首页 > 代码库 > 企业级NFS网络文件共享服务
企业级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服务器端设置:
[root@localhost ~]# yum install nfs-utils rpcbind –y
[root@localhost ~]# rpm -qa nfs-utils rpcbind
nfs-utils-1.2.3-70.el6_8.2.x86_64
rpcbind-0.2.0-12.el6.x86_64
[root@localhost ~]# /etc/init.d/rpcbind status
rpcbind is stopped
[root@localhost ~]# /etc/init.d/rpcbind start #启动rpc服务
Starting rpcbind: [ OK ]
[root@localhost ~]# 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)
[root@localhost ~]# 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
[root@localhost ~]# 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
[root@localhost ~]# chkconfig --list rpcbind
rpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off
NFS服务的相关操作:
[root@localhost ~]# /etc/init.d/nfs status
rpc.svcgssd 已停
rpc.mountd is stopped
nfsd is stopped
[root@localhost ~]# /etc/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
正在启动 RPC idmapd: [确定]
[root@localhost ~]# 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的配置二选一即可。
[root@localhost ~]# chkconfig rpcbind on
[root@localhost ~]# chkconfig nfs on
[root@localhost ~]# chkconfig --list rpcbind
rpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost ~]# chkconfig --list nfs
nfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off
配置NFS服务器端:配置文件路径
创建需要共享的目录并授权:
-bash: l: command not found
[root@localhost ~]# mkdir /data
[root@localhost ~]# ll /data
total 0
[root@localhost ~]# chown -R nfsnobody.nfsnobody /data
[root@localhost ~]# ls -ld /data
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Dec 28 23:54 /data
配置NFS服务配置文件:
[root@localhost ~]# vi /etc/exports
/data 192.168.222.0/24(rw,sync)
[root@localhost ~]# exportfs –rv #查看挂载信息
exporting 192.168.222.0/24:/data
[root@localhost ~]# showmount -e localhost #查看本地服务器挂载情况
Export list for localhost:
/data 192.168.222.0/24
[root@localhost /]# mount -t nfs 192.168.222.130:/data /mnt
[root@localhost /]# 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
[root@localhost ~]# yum install rpcbind –y
[root@localhost ~]# rpm -qa rpcbind
rpcbind-0.2.0-12.el6.x86_64
[root@localhost ~]# showmount
-bash: showmount: command not found
[root@localhost ~]# yum install nfs-utils –y
启动RPC服务
[root@localhost ~]# /etc/init.d/rpcbind start
正在启动 rpcbind: [确定]
[root@localhost ~]# showmount -e 192.168.222.130
Export list for 192.168.222.130:
/data 192.168.222.0/24
[root@localhost ~]# mount -t nfs 192.168.222.130:/data /mnt
[root@localhost ~]# 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
[root@localhost ~]# 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)
[root@localhost ~]# ls /mnt/
[root@localhost ~]# mkdir /mnt/source
[root@localhost ~]# ls -l /mnt
总用量 4
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 12月 29 2016 source
将rpcbind服务和挂载加入开机自启动,如下:
[root@localhost ~]# echo "/etc/inti.d/rpcbind start" >>/etc/rc.local
[root@localhost ~]# echo "/bin/mount -t nfs 192.168.222.130:/data /mnt" >>/etc/rc.local
[root@localhost ~]# 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网络文件共享服务