在 CentOS 上挂载 NFS(Network File System)一般分为 服务端共享 和 客户端挂载 两部分。下面以 CentOS 7/8 为例说明。
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)
参数说明:
rw:可读写sync:同步写入no_root_squash:root 用户不映射为匿名exportfs -r
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
showmount -e 192.168.1.100
mkdir -p /mnt/nfs
mount -t nfs 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
测试:
mount -a
soft 或 timeo 参数:mount -t nfs -o soft,timeo=10 192.168.1.100:/data/nfs /mnt/nfs
no_root_squash 是否配置setsebool -P nfs_export_all_rw on
如果你需要 CentOS 6 / Rocky / AlmaLinux 或 NFSv4 特定配置,可以告诉我。