在 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
vi /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
showmount -e 192.168.1.100
mount -t nfs 192.168.1.100:/data/nfs /mnt/nfs
df -h
touch /mnt/nfs/testfile
vi /etc/fstab
添加:
192.168.1.100:/data/nfs /mnt/nfs nfs defaults,_netdev 0 0
_netdev表示网络就绪后再挂载,避免开机失败
/etc/exportsroot_squash 设置systemctl status nfs-server
showmount -e localhost
如果你需要 CentOS 6 / Rocky / Alma / 特定版本,或 NFSv4 配置、Kerberos 安全挂载,可以继续问我。