★ 安装
yum install nfs-utils rpcbind
apt install nfs-kernel-server rpcbind
systemctl enable nfs-server
★ 配置文件
[/etc/exports.d/example.exports]
参数 | 作用 |
---|---|
ro | 只读 |
rw | 读写 |
root_squash | 当NFS客户端以root管理员访问时,映射为NFS服务器的匿名用户 |
no_root_squash | 当NFS客户端以root管理员访问时,映射为NFS服务器的root管理员 |
all_squash | 无论NFS客户端使用什么账户访问,均映射为NFS服务器的匿名用户 |
sync | 同时将数据写入到内存与硬盘中,保证不丢失数据 |
async | 优先将数据保存到内存,然后再写入硬盘;这样效率更高,但可能会丢失数据 |
# 格式
# 共享目录 可访问地址(选项:默认ro,sync)
# <DIRECTORY> <IP|HOSTNAME>(rw) [<*|?.lanyue.me>(ro)] [server[0-20].lanyue.me]
# 例子
/mnt/data1 192.168.66.6(rw)
/mnt/data2 *.xyh.moe(rw)
/mnt/data3 host[01-20].xyh.moe(rw,sync)
# 发布共享
exportfs -r
★ 服务&防火墙
systemctl enable nfs --now
firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=mountd
firewall-cmd --permanent --add-service=rpc-bind
★ 挂载
# 显示可用网络共享
showmount -e ipaddress
# 手动挂载网络文件
mount [-t nfs] <IPADDR>:<DIRECTORY> <DIRECTORY>