一、服务端
1、安装NFS
[root@localhost ~]# yum -y install rpcbind nfs-utils
2、创建共享目录
[root@localhost ~]# mkdir /NFS
3、编辑访问策略
此处设定允许对外提供NFS服务的目录信息及允许访问的外部IP信息,其中*号代表IP
[root@localhost ~]# vim /etc/exports
/NFS *(rw,sync,no_root_squash,no_subtree_check)
[root@localhost ~]# chmod 777 /NFS
说明:
rw:挂接此目录的客户端对该共享目录具有读写权限
sync:资料同步写入内存和硬盘
no_root_squash:客户机用root访问该共享文件夹时,不映射root用户。(root_squash:客户机用root用户访问该共享文件夹时,将root用户映射成匿名用户)
no_subtree_check:不检查父目录的权限
4、重启服务、关闭防火墙
[root@localhost ~]# systemctl restart rpcbind
[root@localhost ~]# systemctl restart nfs
[root@localhost ~]# systemctl enable rpcbind
[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# showmount -e localhost
Export list for localhost:
/NFS *[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
二、客户端
1、安装客户端并启动服务
test@test-PC:~$ sudo apt install nfs-common -y
test@test-PC:~$ sudo systemctl restart rpcbind
test@test-PC:~$ sudo systemctl enable rpcbind
2、创建挂载点并挂载
test@test-PC:~$ mkdir /home/test/nfs-mount/
test@test-PC:~$ sudo mount -t nfs 10.20.61.13:/NFS /home/test/nfs-mount/
test@test-PC:~$ df -Th
3、设置自动挂载
test@test-PC:~$ vim /etc/fstab
10.20.61.13:/NFS /home/test/nfs-mount nfs defaults 0 0
4、测试
test@test-PC:~$ df -Th
test@test-PC:~$ sudo umount /home/test/nfs-mount
test@test-PC:~$ sudo mount -a