15.NFS服务相关配置

发布时间:2026/7/16 10:59:30
15.NFS服务相关配置 一、NFS基础1.在 RockyLinux101 主机执行 ip addr 查看网卡信息确认 ens192 网卡 IP 为 192.168.0.101/242.在 RockyLinux102 主机执行 ip addr 查看网卡信息确认 ens192 网卡 IP 为 192.168.0.102/243.在 RockyLinux103 主机执行 ip addr 查看网卡信息确认 ens192 网卡 IP 为 192.168.0.103/244.在 RockyLinux101 主机执行 ping 192.168.0.102 -c 3 测试与 RockyLinux102 的网络连通性确认无丢包执行 ping 192.168.0.103 -c 3 测试与 RockyLinux103 的网络连通性确认无丢包5.在 RockyLinux101 主机执行 dnf install -y nfs-utils rpcbind安装 NFS 服务端及依赖的 RPC 服务软件包6.在 RockyLinux101 主机执行 systemctl restart rpcbind.service 启动 RPC 服务执行 systemctl status rpcbind.service 查看运行状态确认服务正常运行执行 systemctl restart nfs-server.service 启动 NFS 服务执行 systemctl status nfs-server.service 查看运行状态确认服务正常运行7.在 RockyLinux101 主机执行 ss -anpt | grep rpcbind 查看 RPC 服务监听状态确认其在 111 端口监听执行 rpcinfo -p 查看 NFS 相关服务的 RPC 注册信息确认 nfs、mountd 等服务正常注册8.在 RockyLinux101 主机执行 tail -5 /etc/passwd 查看系统用户列表执行 useradd student 和 useradd zhangsan 创建两个测试用户再次执行 tail -5 /etc/passwd 确认用户创建成功UID 分别为 1000 和 10019.在 RockyLinux101 主机创建/root_squash、/no_root_squash、/all_squash、/student_all_squash、/html_share 多个 NFS 测试目录执行 chown student:student /student_all_squash 修改目录属主执行 chmod ow 为所有目录添加其他用户写入权限通过 ll -d 命令验证权限修改结果10.在 RockyLinux101 主机执行 vim /etc/exports打开 NFS 服务的共享配置文件准备配置共享目录11.在 RockyLinux101 主机的 /etc/exports 文件中配置五个共享目录的 NFS 规则/root_squash/ 192.168.0.0/24(rw,async,root_squash)/no_root_squash/ 192.168.0.0/24(rw,async,no_root_squash)/all_squash/ 192.168.0.0/24(rw,async,all_squash)/student_all_squash/ 192.168.0.0/24(rw,async,root_squash,anonuid1000,anongid1000)/html_share/ 192.168.0.0/24(rw,async,no_root_squash)12.在 RockyLinux101 主机执行 showmount -e 192.168.0.101 查看当前 NFS 共享列表执行 exportfs -ra 重新加载 NFS 共享配置再次执行 showmount -e 192.168.0.101 验证所有配置的共享目录已成功发布13.在 RockyLinux102 主机执行 dnf install -y nfs-utils rpcbind安装 NFS 客户端工具包及依赖的 RPC 服务14.在 RockyLinux101 主机执行 tail -5 /etc/passwd 和 tail -5 /etc/group确认之前创建的 studentUID/GID 1000和 zhangsanUID/GID 1001用户及组信息15.在 RockyLinux102 主机执行 useradd student 和 useradd lisi 创建两个测试用户执行 tail -5 /etc/passwd 和 tail -5 /etc/group 确认用户创建成功其中 lisi 的 UID/GID 为 1001与服务端 zhangsan 用户的 UID/GID 保持一致16.在 RockyLinux102 主机执行 mkdir /usershare 创建挂载目录执行 mount -t nfs 192.168.0.101:/root_squash /usershare/ 挂载 NFS 服务端的 /root_squash 共享目录执行 cd /usershare/ 进入挂载目录执行 touch root_file.txt 创建测试文件17.在 RockyLinux102 主机执行 umount /usershare 卸载 NFS 共享执行 setfacl -m u:lisi:rwx /usershare/ 为用户 lisi 设置目录的读写执行权限执行 getfacl /usershare/ 验证 ACL 权限配置结果18.在 RockyLinux102 主机执行 mount -t nfs 192.168.0.101:/root_squash /usershare/ 重新挂载共享目录执行 su - lisi 切换到用户 lisi进入 /usershare/ 目录执行 touch lisi_file.txt 创建文件执行 cat /etc/passwd /etc/group | grep lisi 查看用户 lisi 的 UID/GID 信息19.在 RockyLinux101 主机执行 cd /root_squash/ 进入共享目录执行 ll 查看客户端创建的文件属性发现 root_file.txt 的属主被压缩为 nobodylisi_file.txt 的属主为 zhangsan与客户端 lisi 的 UID 1001 对应执行 cat /etc/passwd /etc/group | grep zhangsan 验证服务端用户 zhangsan 的 UID/GID 为 100120.在 RockyLinux102 主机执行 umount /usershare 卸载 NFS 共享执行 mount -t nfs 192.168.0.101:/no_root_squash /usershare/ 挂载 /no_root_squash 共享目录执行 touch root_file.txt 创建文件执行 su - lisi 切换用户并创建 lisi_file.txt执行 cat /etc/passwd /etc/group | grep lisi 查看用户信息21.在 RockyLinux101 主机执行 cd /no_root_squash/ 进入共享目录执行 ll 查看客户端创建的文件属性发现 root_file.txt 的属主保持为 root验证了 no_root_squash 选项的效果lisi_file.txt 的属主为 zhangsan与客户端 lisi 的 UID 1001 对应22.在 RockyLinux102 主机执行 umount /usershare 卸载 NFS 共享执行 mount -t nfs 192.168.0.101:/all_squash /usershare/ 挂载 /all_squash 共享目录执行 touch root_file.txt 创建文件执行 su - lisi 切换用户并创建 lisi_file.txt23.在 RockyLinux101 主机执行 cd /all_squash/ 进入共享目录执行 ll 查看文件属性发现 root_file.txt 和 lisi_file.txt 的属主均被压缩为 nobody验证了 all_squash 选项的效果24.在 RockyLinux102 主机执行 umount /usershare 卸载 NFS 共享执行 mount -t nfs 192.168.0.101:/student_all_squash /usershare/ 挂载 /student_all_squash 共享目录执行 touch root_file.txt 创建文件执行 su - lisi 切换用户并创建 lisi_file.txt25.在 RockyLinux101 主机执行 cd /student_all_squash/ 进入共享目录执行 ll 查看文件属性发现 root_file.txt 的属主被压缩为 studentUID 1000lisi_file.txt 的属主为 zhangsan与客户端 lisi 的 UID 1001 对应验证了 anonuid1000,anongid1000 选项的效果二、NFS共享网页文件1.在 RockyLinux102 主机执行 dnf install -y httpd安装 Apache Web 服务器软件包2.在 RockyLinux102 主机执行 systemctl restart httpd.service启动 Apache 服务3.在 RockyLinux102 主机执行 ss -anpt | grep httpd 确认服务在 80 端口监听执行 cd /var/www/html/ 进入网站根目录执行 echo this is 192.168.0.102 index.html 创建首页文件执行 mkdir ./web102 创建子目录并写入测试文件4.在本地浏览器访问 http://192.168.0.102成功显示网页内容 this is 192.168.0.102验证 Apache 服务正常运行5.在本地浏览器访问 http://192.168.0.102/web102/102.txt成功显示文件内容 this is web102验证网站文件访问正常6.在 RockyLinux103 主机执行 dnf install -y nfs-utils rpcbind httpd安装 NFS 客户端工具包及 Apache Web 服务器软件包7.在 RockyLinux103 主机执行 systemctl start httpd.service启动 Apache 服务8.在 RockyLinux103 主机执行 ss -anpt | grep httpd 确认服务在 80 端口监听执行 cd /var/www/html/ 进入网站根目录执行 echo this is 192.168.0.103 ./index.html 创建首页文件执行 mkdir ./web103 创建子目录并写入测试文件9.在本地浏览器访问 http://192.168.0.103成功显示网页内容 this is 192.168.0.103验证 Apache 服务正常运行10.在本地浏览器访问 http://192.168.0.103/web103/103.txt成功显示文件内容 this is web103验证网站文件访问正常11.在 RockyLinux101 主机执行 cd /html_share/ 进入共享目录执行 scp -r root192.168.0.102:/var/www/html/ /html_share/ 将客户端的网站文件同步到 NFS 共享目录执行 ls 查看同步结果12.在 RockyLinux101 主机执行 cat ./html/index.html 查看文件内容执行 echo hello nfs ./html/index.html 修改首页内容执行 rm -rf ./html/web102/ 删除旧目录并创建新的测试目录和文件13.在 RockyLinux102 主机执行 rm -rf /var/www/html/* 清空网站目录执行 mount -t nfs 192.168.0.101:/html_share/ /var/www/html/ 挂载 NFS 共享目录到网站根目录执行 ls /var/www/html/ 验证挂载结果14.在 RockyLinux103 主机执行 rm -rf /var/www/html/* 清空网站目录执行 mount -t nfs 192.168.0.101:/html_share/ /var/www/html/ 挂载 NFS 共享目录到网站根目录执行 ls /var/www/html/ 验证挂载结果15.在本地浏览器访问 http://192.168.0.102/html/成功显示网页内容 hello nfs验证 NFS 共享的网站文件在 RockyLinux102 上可被正常访问16.在本地浏览器访问 http://192.168.0.103/html/成功显示网页内容 hello nfs验证 NFS 共享的网站文件在 RockyLinux103 上可被正常访问17.在本地浏览器访问 http://192.168.0.102/html/web/web.txt成功显示文件内容 this is web server验证 NFS 共享的子目录文件可被正常访问18.在本地浏览器访问 http://192.168.0.103/html/web/web.txt成功显示文件内容 this is web server验证两台客户端均能访问 NFS 服务端提供的共享网站文件完成 NFS 高可用 Web 共享实验