目标:nfs服务器配置nfs服务,客户端将nfs共享的目录挂载到网站服务的根目录下。
环境准备:两台linux虚拟机(192.168.1.11,192.168.1.12)
192.168.1.11 服务器端配置
[root@nfs ~]# yum -y install nfs-utils
[root@nfs ~]# mkdir /web_share
[root@nfs ~]# vim /etc/exports
/web_share 192.168.1.0/24(rw,no_root_squash)
[root@nfs ~]# echo nihao > /web_share/index.html
[root@nfs ~]# systemctl restart rpcbind
[root@nfs ~]# systemctl enable rpcbind
[root@nfs ~]# systemctl restart nfs
[root@nfs ~]# systemctl enable nfs
NFS使用的是随机端口,每次启动NFS都需要将自己的随机端口注册到rpcbind服务,这样客户端访问NFS时先到rpcbind查询端口信息,得到端口信息后再访问NFS服务。
192.168.1.12 客户端配置
[root@web1 ~]# yum -y install nfs-utils
[root@web1 ~]# yum -y install httpd
[root@web1 ~]# echo "192.168.2.11:/web_share/ /var/www/html/ nfs defaults 0 0" >> /etc/fstab
[root@web1 ~]# mount -a
[root@web1 ~]# systemctl restart httpd
[root@web1 ~]# curl 192.168.1.12
nihao