- 使用NFS发布共享资源 关闭selinux
- 安装nfs-utils、rpcbind软件包(centos7默认安装,调整为自启状态)
[root@localhost ~]# yum -y install nfs-utils rpcbind
[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# systemctl enable rpcbind
- 设置共享目录,默认配置文件为/etc/exports,文件内容默认为空(无共享)。
[root@localhost ~]# mkdir -p /opt/wwwroot 共享目录
[root@localhost ~]# vim /etc/exports
[root@localhost ~]# cat /etc/exports
/opt/wwwroot 192.168.7.0/24(rw,sync,no_root_squash) 共享给7网段写*代表所有
#如需将同一个目录共享给不同客户机,且分配不同权限,只要以空格分隔指定多个“客户机(权限选项)”即可
- 启动nfs服务程序
[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# netstat -anpt | grep rpcbind
- 查看本机发布的nfs共享目录
[root@localhost ~]# showmount -e
Export list for localhost.localdomain:
/opt/wwwroot 192.168.7.0/24
- 在客户机中访问nfs共享资源
1)安装nfs-utils、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 查看此ip共享的目录
Export list for 192.168.7.250:
/opt/wwwroot 192.168.7.0/24
- 手动挂载nfs共享目录
[root@localhost ~]# mount 192.168.7.250:/opt/wwwroot /var/www/html/ [root@localhost ~]# tail -1 /etc/mtab //确认挂载结果
[root@localhost ~]# vim /var/www/html/index.html //在客户机创建测试文件
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
index.html //访问客户机/var/www/html文件夹相当于访问服务器/opt/wwwroot,。例如:上述创建的index就可以在服务器/opt/wwwroot/下。
- fstab自动挂载设置,在客户机修改/etc/fstab,加入挂载目录的挂载设置。
[root@localhost ~]# vim /etc/fstab //添加,这样开机后自动挂载nfs共享资源。