一、服务器
1.安装NFS服务
[root@localhost ~]# yum install -y nfs-utils
2.启动NFS服务
# 查看rpc服务状态
[root@localhost ~]# systemctl status rpcbind
启动rpc服务
[root@localhost ~]# systemctl enable --now rpcbind
nfs开机自启
[root@localhost ~]# systemctl enable --now nfs-server
启动nfs服务
[root@localhost ~]# systemctl start nfs-server
3.配置防火墙放行规则
[root@localhost ~]# firewall-cmd --add-service=nfs
success
[root@localhost ~]# firewall-cmd --add-service=mountd
success
[root@localhost ~]# firewall-cmd --add-service=rpc-bind
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --list-services
cockpit dhcpv6-client dns http https mountd nfs rpc-bind ssh
4.配置导出文件
[root@localhost ~]# mkdir /nfs
[root@localhost ~]# chmod 777 /nfs
[root@localhost ~]# touch /nfs/testfile
[root@localhost ~]# ll /nfs
total 0
-rw-r--r--. 1 root root 0 Jul 10 13:10 testfile
[root@localhost ~]# cat /etc/exports
/nfs *(rw)
[root@localhost ~]# systemctl restart nfs-server
5.本地测试
[root@localhost ~]# showmount -e 192.168.166.129
Export list for 192.168.166.129:
/nfs *
二、客户端
1.安装NFS服务
[root@localhost ~]# yum install -y nfs-utils
2.启动NFS服务
# 查看rpc服务状态
[root@localhost ~]# systemctl status rpcbind
启动rpc服务
[root@localhost ~]# systemctl enable --now rpcbind
nfs开机自启
[root@localhost ~]# systemctl enable --now nfs-server
启动nfs服务
[root@localhost ~]# systemctl start nfs-server
3.配置防火墙放行规则
[root@localhost ~]# firewall-cmd --add-service=nfs
success
[root@localhost ~]# firewall-cmd --add-service=mountd
success
[root@localhost ~]# firewall-cmd --add-service=rpc-bind
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --list-services
cockpit dhcpv6-client dns http https mountd nfs rpc-bind ssh
4.客户端查看导出文件
[root@localhost ~]# showmount -e 192.168.166.129
Export list for 192.168.166.129:
/nfs *
[root@localhost ~]# mkdir /haha
[root@localhost ~]# mount 192.168.166.129:/nfs /haha/
# 查看挂载
[root@localhost ~]# df -h /haha
Filesystem Size Used Avail Use% Mounted on
192.168.166.129:/nfs 17G 4.3G 13G 25% /haha
[root@localhost ~]# mkdir /haha/test
[root@localhost ~]# ll /haha/
total 0
-rw-r--r--. 1 nobody nobody 0 Jul 10 12:56 test
-rw-r--r--. 1 root root 0 Jul 10 13:10 testfile
5.开机自动挂载
[root@localhost ~]# cat /etc/fstab
192.168.166.129:/nfs /haha nfs defaults 0 0 # 添加本行
# 主机重启,查看文件挂载情况
[root@localhost ~]# df -h /haha/
Filesystem Size Used Avail Use% Mounted on
192.168.166.129:/nfs 17G 4.3G 13G 25% /haha