下面给你一份 CentOS 上配置和挂载 NFS 的完整示例(服务端 + 客户端),适用于 CentOS 7 / 8 / Stream。
yum install -y nfs-utils rpcbind
systemctl enable --now rpcbind
systemctl enable --now nfs-server
mkdir -p /data/nfs
chmod 777 /data/nfs
vim /etc/exports
示例(允许 192.168.1.0/24 网段访问):
/data/nfs 192.168.1.0/24(rw,sync,no_root_squash,no_all_squash)
常用参数说明:
rw:读写ro:只读sync:同步写入async:异步(更快但不安全)no_root_squash:root 用户不映射为 nobodyroot_squash:root 映射为匿名用户(更安全)exportfs -r
exportfs -v
firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=mountd
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --reload
yum install -y nfs-utils
mkdir -p /mnt/nfs
mount -t nfs 192.168.1.100:/data/nfs /mnt/nfs
测试:
df -h
touch /mnt/nfs/testfile
vim /etc/fstab
添加:
192.168.1.100:/data/nfs /mnt/nfs nfs defaults,_netdev 0 0
_netdev表示网络设备,避免系统启动时网络未就绪导致挂载失败
验证:
mount -a
showmount -e 192.168.1.100
root_squash / no_root_squashsetsebool -P nfs_export_all_rw 1
如果你告诉我 CentOS 版本 / 是否为 Kubernetes / 是否要只读,我可以给你更精确的配置。