NFS共享存储服务
■ NFS (Network File System)网络文件系统
● 依赖于RPC (远端过程调用)
● 需安装nfs-utils、rpcbind软件包
● 系统服务: nfs、 rpcbind
● 共享配置文件: /etc/exports
使用NFS发布共享资源
■ 安装nfs-utils、rpcbind软件包
[root@localhost ~]# yum -y install nfs-utils rpcbind
[root@localhost ~]# systemqtl enable nfs
[root@localhost ~]# systemctl enable rpcbind
■ 设置共享目录
[root@localhost ~]# mkdir -p /opt/wwwroot
[root@localhost ~]# vi /etc/exports
/opt/wwwroot 192.168.7.0/24(rw,sync,no_ root_ squash) /var/ftp/pub 192.168.4.11(ro) 192.168.4.110(rw)
(ro)权限是只读,不允许更改(rw是读写权限,sync是服务器和客户机间开启同步, no_root_squash表示可以是root身份访问服务器)
■ 启动NFS服务程序
■ 查看本机发布的NFS共享目录
[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# netstat -anpt | grep rpc
tcp 0 00.0.0.0:20048 0.0.0.0:* LISTEN 10508/rpc.mountd
tcp 0 00.0.0.0:52732 0.0.0.0:* LISTEN 10495/rpc.statd
tcp6 00 ::20048 ::* LISTEN 10508/rpc.mountd
tcp6 00 ::47669 ::* LISTEN 10495/rpc.statd
[root@localhost ~]# showmount -e
/opt/wwwroot 192.168.7.0/24
/var/ftp/pub 192.168. 4.110,192.168.4.11
在客户机中访问NFS共享资源
■ 安装rpcbind软件包, 并启动rpcbind服务
[root@localhost ~]# yum -y install rpcbind nfs-utils
[root@localhost ~]# systemctl enable rpcbind
[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# showmount -e 192.168.7 .250
Export list for 192. 168.7.250:
/opt/wwwroot 192. 168.7.0/24
/var/ftp/pub 192.168.4.110,192.168.4.11
■ 手动挂载NFS共享目录
[root@localhost ~]# mount 192.168.7.250:/opt/wwwroot /var/www/html
[root@localhost ~]# tail -1 /etc/mtab
192.168.7.250:/opt/wwwroot /var/www/html nfs4
rw,relatime,vers=4.0,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,
timeo=600,retrans=2,sec=sys, clientaddr=192.168.7.21,local lock=none,
addr=192.168.7.250 0 0
[root@localhost ~]# vi /var/www/html/index.html
Real Web Server Document
■ fstab自动挂载设置
[root@localhost ~]# vi /etc/fstab
.... //省略部分信息
192.168.7.250:/opt/wwwroot /var/www/html nfs defaults,_netdev 0 0
■ 强制卸载NFS
[root@localhost ~]# umount /mnt
umount: /mnt: device is busy
[root@localhost ~]# umount -If /mnt
[root@localhost ~]#