NFS安装
yum -y install nfs-utils
创建共享目录
mkdir /share
chmod 777 /share
修改配置文件传输规则
vim /etc/exports
/share 172.31.0.0/16(rw,rsnc,no_root_squash)
开启NFS和RPC服务
systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable nfs
检查挂载
showmount -e localhost
# localhost 为nfs服务端的主机IP
客户端挂载
mkdir /share
mount -t nfs 172.31.1.1:/share /share
NFS卸载挂载目录
# 普通卸载
umount /share
# 强制卸载
umount -lf /share
客户端开机自动挂载
vim /etc/fstab
# 写入以下内容
172.31.1.1:/share /share nfs defaults 0 0
NFS配置参数说明
| 共享参数 | 作用 |
|---|
| rw* | 读写权限 |
| ro | 只读权限 |
| root_squash | 当NFS客户端以root管理员访问时,映射为NFS服务器的匿名用户(不常用) |
| no_root_squash | 当NFS客户端以root管理员访问时,映射为NFS服务器的root管理员(常用) |
| all_squash | 无论NFS客户端使用什么账户访问,均映射NFS服务器的匿名用户(常用) |
| no_all_squash | 无论NFS客户端使用什么账户访问,都不进行压缩 |
| sync* | 同时将数据写入到内存与磁盘中,保证不丢失数据 |
| async | 优先将数据保存到内存中,然后再写入硬盘;这样效率更高,但可能会丢失数据 |
| anonuid* | 配置all_squash使用,指定NFS的用户UID,必须存在系统 |
| anongid* | 配置all_squash使用,指定NFS的用户GID,必须存在系统 |