在 CentOS 上挂载 NFS(Network File System)一般分为服务端共享和客户端挂载两部分。下面以常见场景为例说明。
yum install -y nfs-utils rpcbind
systemctl enable rpcbind
systemctl start rpcbind
systemctl enable nfs-server
systemctl start 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)
参数说明:
rw:可读写sync:同步写入no_root_squash:客户端 root 不被映射为匿名用户(测试环境常用)exportfs -r
exportfs -v
yum install -y nfs-utils
mkdir -p /mnt/nfs
mount -t nfs 192.168.1.100:/data/nfs /mnt/nfs
如果 NFS 版本有兼容问题,可指定版本:
mount -t nfs -o vers=3 192.168.1.100:/data/nfs /mnt/nfs
df -h
mount | grep nfs
vi /etc/fstab
添加一行:
192.168.1.100:/data/nfs /mnt/nfs nfs defaults 0 0
或指定版本:
192.168.1.100:/data/nfs /mnt/nfs nfs vers=3,defaults 0 0
保存后测试:
mount -a
systemctl stop firewalld
# 或放行 nfs 服务
firewall-cmd --add-service=nfs --permanent
firewall-cmd --reload
/etc/exports 网段root_squashshowmount -e 192.168.1.100
如果你有 CentOS 版本(6/7/8/Stream) 或 具体报错信息,我可以给出更精确的命令。