测试环境:
服务端:centos 8.3 IP:172.16.14.111
客户端:centos 8.4 IP:172.16.14.92
**
服务端需要的配置
创建需要分享的目录
例如:mkdir /ShareFile
**
1、安装软件
**
yum install -y nfs-utils.x86_64 rpcbind.x86_64
NFS的实现依赖于RPC(远程过程调用)机制,RPC充当NFS服务器和客户端的中介,以完成从远程到本地的映射过程,提供RPC支持的服务为rpcbind,提供nfs共享的服务为nfs-server,CentOS 8中需要安装nfs-util和rpcbind软件包来提供NFS共享服务,前者用于NFS共享发布和访问,后者用于RPC支持
2、把nfs-server和rpcbind服务设置为开机自启,以便每次开机后自动启用
systemctl enable nfs-server.service
systemctl enable rpcbind
3、编辑nfs配置文件,指定挂载的目录,挂载的网段和配置信息
vim /etc/exports
#nfs的主要配置文件
/ShareFile 172.16.14.0/24(rw,sync,no_root_squash)
rw:可读写,sync:同步数据到硬盘和内存,no_root_squash:以root用户
#rw :读写;
#ro :只读;
#sync :同步模式,内存中数据时时写入磁盘;
#async :不同步,把内存中数据定期写入磁盘中;
#no_root_squash :加上这个选项后,root用户就会对共享的目录拥有至高的权限控制,就像是对本机的目录操作一样。不安全,不建议使用;
#root_squash :和上面的选项对应,root用户对共享目录的权限不高,只有普通用户的权限,即限制了root;
#all_squash :不管使用NFS的用户是谁,他的身份都会被限定成为一个指定的普通用户身份
4、启动nfs-server和rpcbind服务
systemctl start nfc-server
systemctl start rpcbind
5、查看是否关闭防火墙和selinux
systemctl status firewalld 查看状态是否是loaded
如果不是运行下面命令
systemctl stop firewalld
systemctl disable firewalld
关闭selinux
setenforce 0
6、查看输出的共享目录
showmount -e 或者 exportfs
/ShareFile 172.16.14.0./24
客户端挂载:
创建本地挂载目录:
例如:mkdir /DataFile
mount 172.16.14.111:/ShareFile /DataFile/
查看绑定状态:mount
172.16.14.111:/ShareFile on /DataFile type nfs4 (rw,relatime,vers=4.2,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=172.16.14.92,local_lock=none,addr=172.16.14.111)