在 CentOS 上挂载 NFS(Network File System)一般分为服务端配置和客户端挂载两部分。下面以 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)
常用参数说明:
rw:读写ro:只读sync:同步写入no_root_squash:root 用户不映射all_squash:所有用户映射为匿名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
将
192.168.1.100替换为 NFS 服务器 IP
df -h
mount | grep nfs
编辑 /etc/fstab:
vim /etc/fstab
添加一行:
192.168.1.100:/data/nfs /mnt/nfs nfs defaults 0 0
测试配置是否正确:
mount -a
showmount -e IP 是否可见/etc/exports 权限setenforce 0
showmount -e 192.168.1.100
如果你需要 CentOS 6 版本、NFSv4 配置 或 Kubernetes 使用 NFS 的示例,也可以告诉我。