企业级NFS网络文件共享服务
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了企业级NFS网络文件共享服务相关的知识,希望对你有一定的参考价值。
虚拟实验:
操作系统:CentOS release 6.8 (Final)
虚拟机:VMware
任务:NFS网络文件共享服务
默认是没有安装NFS软件包,NFS主要功能是通过网络让不同的主机系统之间可以共享文件或目录。NFS网络文件系统很像Windows系统的网络共享、安全功能、网络驱动映射,而互联网中小型网站集群架构后端常用NFS进行数据共享。
NFS服务器IP: 192.168.222.130
NFS客户端IP1: 192.168.222.138
NFS客户端IP2:192.168.222.139
N个客户端
NFS服务器端设置:
[[email protected] ~]# yum install nfs-utils rpcbind –y
[[email protected] ~]# rpm -qa nfs-utils rpcbind
nfs-utils-1.2.3-70.el6_8.2.x86_64
rpcbind-0.2.0-12.el6.x86_64
[[email protected] ~]# /etc/init.d/rpcbind status
rpcbind is stopped
[[email protected] ~]# /etc/init.d/rpcbind start #启动rpc服务
Starting rpcbind: [ OK ]
[[email protected] ~]# lsof -i:111
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rpcbind 1839 rpc 6u IPv4 13719 0t0 UDP *:sunrpc
rpcbind 1839 rpc 8u IPv4 13722 0t0 TCP *:sunrpc (LISTEN)
rpcbind 1839 rpc 9u IPv6 13724 0t0 UDP *:sunrpc
rpcbind 1839 rpc 11u IPv6 13727 0t0 TCP *:sunrpc (LISTEN)
[[email protected] ~]# netstat -lntup|grep rpcbind #查看NFS服务向RPC服务注册的端口
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1839/rpcbind
tcp 0 0 :::111 :::* LISTEN 1839/rpcbind
udp 0 0 0.0.0.0:742 0.0.0.0:* 1839/rpcbind
udp 0 0 0.0.0.0:111 0.0.0.0:* 1839/rpcbind
udp 0 0 :::742 :::* 1839/rpcbind
udp 0 0 :::111 :::* 1839/rpcbind
[[email protected] ~]# rpcinfo -p localhost
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
[[email protected] ~]# chkconfig --list rpcbind
rpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off
NFS服务的相关操作:
[[email protected] ~]# /etc/init.d/nfs status
rpc.svcgssd 已停
rpc.mountd is stopped
nfsd is stopped
[[email protected] ~]# /etc/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
正在启动 RPC idmapd: [确定]
[[email protected] ~]# rpcinfo -p localhost
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
100005 1 udp 38130 mountd
100005 1 tcp 54803 mountd
100005 2 udp 54566 mountd
100005 2 tcp 37618 mountd
100005 3 udp 56646 mountd
100005 3 tcp 43214 mountd
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100227 2 tcp 2049 nfs_acl
100227 3 tcp 2049 nfs_acl
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100227 2 udp 2049 nfs_acl
100227 3 udp 2049 nfs_acl
100021 1 udp 43937 nlockmgr
100021 3 udp 43937 nlockmgr
100021 4 udp 43937 nlockmgr
100021 1 tcp 46011 nlockmgr
100021 3 tcp 46011 nlockmgr
100021 4 tcp 46011 nlockmgr
配置NFS服务器端开机自动启动: chkconfig和/etc/rc.local的配置二选一即可。
[[email protected] ~]# chkconfig rpcbind on
[[email protected] ~]# chkconfig nfs on
[[email protected] ~]# chkconfig --list rpcbind
rpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[[email protected] ~]# chkconfig --list nfs
nfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off
配置NFS服务器端:配置文件路径
创建需要共享的目录并授权:
-bash: l: command not found
[[email protected] ~]# mkdir /data
[[email protected] ~]# ll /data
total 0
[[email protected] ~]# chown -R nfsnobody.nfsnobody /data
[[email protected] ~]# ls -ld /data
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Dec 28 23:54 /data
配置NFS服务配置文件:
[[email protected] ~]# vi /etc/exports
/data 192.168.222.0/24(rw,sync)
[[email protected] ~]# exportfs –rv #查看挂载信息
exporting 192.168.222.0/24:/data
[[email protected] ~]# showmount -e localhost #查看本地服务器挂载情况
Export list for localhost:
/data 192.168.222.0/24
[[email protected] /]# mount -t nfs 192.168.222.130:/data /mnt
[[email protected] /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 27G 3.0G 23G 12% /
tmpfs 495M 0 495M 0% /dev/shm
/dev/sda1 93M 51M 38M 58% /boot
192.168.222.130:/data 27G 3.0G 23G 12% /mnt
NFS Client端执行的操作:
安装客户端软件rpcbind
[[email protected] ~]# yum install rpcbind –y
[[email protected] ~]# rpm -qa rpcbind
rpcbind-0.2.0-12.el6.x86_64
[[email protected] ~]# showmount
-bash: showmount: command not found
[[email protected] ~]# yum install nfs-utils –y
启动RPC服务
[[email protected] ~]# /etc/init.d/rpcbind start
正在启动 rpcbind: [确定]
[[email protected] ~]# showmount -e 192.168.222.130
Export list for 192.168.222.130:
/data 192.168.222.0/24
[[email protected] ~]# mount -t nfs 192.168.222.130:/data /mnt
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 27G 939M 25G 4% /
tmpfs 495M 0 495M 0% /dev/shm
/dev/sda1 93M 51M 38M 58% /boot
192.168.222.130:/data 27G 3.0G 23G 12% /mnt
[[email protected] ~]# mount
/dev/sda3 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.222.130:/data on /mnt type nfs (rw,vers=4,addr=192.168.222.130,clientaddr=192.168.222.138)
[[email protected] ~]# ls /mnt/
[[email protected] ~]# mkdir /mnt/source
[[email protected] ~]# ls -l /mnt
总用量 4
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 12月 29 2016 source
将rpcbind服务和挂载加入开机自启动,如下:
[[email protected] ~]# echo "/etc/inti.d/rpcbind start" >>/etc/rc.local
[[email protected] ~]# echo "/bin/mount -t nfs 192.168.222.130:/data /mnt" >>/etc/rc.local
[[email protected] ~]# tail -2 /etc/rc.local
/etc/inti.d/rpcbind start
/bin/mount -t nfs 192.168.222.130:/data /mnt
注意:关于防火墙和文件权限的相关设置在这里省略。
本文出自 “sky9890” 博客,请务必保留此出处http://sky9896.blog.51cto.com/2330653/1886956
以上是关于企业级NFS网络文件共享服务的主要内容,如果未能解决你的问题,请参考以下文章