在 Linux 上挂载 NFS(Network File System)一般分为 服务端配置 和 客户端挂载 两部分。下面按常见流程说明(以 CentOS / Rocky / Alma / RHEL / Ubuntu 为例)。
# CentOS / RHEL / Rocky
yum install -y nfs-utils
# Ubuntu / Debian
apt install -y nfs-kernel-server
mkdir -p /data/nfs
chmod 755 /data/nfs
编辑 /etc/exports:
vim /etc/exports
示例配置:
/data/nfs *(rw,sync,no_root_squash)
常见参数说明:
rw:读写ro:只读sync:同步写入async:异步(性能高但不安全)no_root_squash:允许 root 权限root_squash:root 映射为 nobody(更安全)指定客户端示例:
/data/nfs 192.168.1.0/24(rw,sync)
# CentOS / RHEL
systemctl enable --now nfs-server
# Ubuntu
systemctl enable --now nfs-kernel-server
exportfs -r
# NFS 依赖 rpc
firewall-cmd --add-service=nfs --permanent
firewall-cmd --add-service=mountd --permanent
firewall-cmd --add-service=rpc-bind --permanent
firewall-cmd --reload
# CentOS / RHEL
yum install -y nfs-utils
# Ubuntu / Debian
apt install -y nfs-common
mkdir -p /mnt/nfs
mount -t nfs 192.168.1.10:/data/nfs /mnt/nfs
如果 NFS 版本有问题,可指定版本:
mount -t nfs -o vers=3 192.168.1.10:/data/nfs /mnt/nfs
mount -t nfs -o vers=4 192.168.1.10:/data/nfs /mnt/nfs
df -h | grep nfs
或:
mount | grep nfs
编辑 /etc/fstab:
192.168.1.10:/data/nfs /mnt/nfs nfs defaults 0 0
或指定版本:
192.168.1.10:/data/nfs /mnt/nfs nfs vers=4,defaults 0 0
测试:
mount -a
showmount -e 192.168.1.10
/etc/exportssetenforce 0
# 服务端
echo "/data/nfs *(rw,sync)" >> /etc/exports
systemctl start nfs-server
# 客户端
mount -t nfs 192.168.1.10:/data/nfs /mnt/nfs
如果你能告诉我:
我可以给你更精确的配置示例。