在 Linux 下挂载 NFS(Network File System)一般分为服务器端共享和客户端挂载两部分。下面给你一个常见、实用的操作示例。
# CentOS / RHEL
yum install nfs-utils
# Ubuntu / Debian
apt install nfs-kernel-server
mkdir -p /data/nfs
chmod 777 /data/nfs
编辑 /etc/exports:
vi /etc/exports
示例(允许 192.168.1.0/24 网段访问):
/data/nfs 192.168.1.0/24(rw,sync,no_root_squash)
常用参数说明:
rw:可读写ro:只读sync:同步写入async:异步(性能高但不安全)no_root_squash:客户端 root 保持权限all_squash:所有用户映射为匿名# CentOS 7+
systemctl enable --now nfs-server
# Ubuntu
systemctl enable --now nfs-kernel-server
exportfs -r
# CentOS / RHEL
yum install nfs-utils
# Ubuntu / Debian
apt install nfs-common
mkdir -p /mnt/nfs
mount -t nfs 192.168.1.100:/data/nfs /mnt/nfs
如果是 NFSv4:
mount -t nfs4 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
或(推荐 NFSv4):
192.168.1.100:/data/nfs /mnt/nfs nfs4 defaults,_netdev 0 0
_netdev表示网络就绪后再挂载
ping 192.168.1.100
# 服务器端
systemctl stop firewalld
# 或放行 nfs 服务
firewall-cmd --add-service=nfs --permanent
firewall-cmd --reload
showmount -e 192.168.1.100
/etc/exportsroot_squash / no_root_squash如果你有 具体系统版本(CentOS 7 / Ubuntu 22.04 等) 或 报错信息,我可以给你更精确的命令。