🧩 openEuler 22.03 LTS SP3 NFS 服务配置
一、实验目标
| 项目 | 内容 |
|---|---|
| 服务端 | Server3 |
| 客户端 | Server1、Server2 |
| 系统版本 | openEuler 22.03 LTS SP3 |
| 功能目标 | 通过 NFS 实现目录共享与访问控制 |
二、服务端(Server3)配置
1️⃣ 安装与启用 NFS 服务
dnf install -y nfs-utils
systemctl enable --now nfs-server
2️⃣ 创建共享目录并设置权限
mkdir -p /data /backup
chmod 777 /data /backup
3️⃣ 编辑 NFS 导出配置文件
vim /etc/exports
示例内容:
/data 192.168.10.101(rw,sync,no_root_squash,no_subtree_check) 192.168.10.102(ro,sync,no_root_squash,no_subtree_check)
/backup 192.168.10.0/24(rw,sync,no_root_squash,no_subtree_check)
| `rw` / `ro` | 指定共享目录的访问权限(读写 / 只读) |
| `sync` / `async` | 同步或异步写入(推荐 sync,数据更安全) |
| `no_root_squash` | 保留客户端 root 权限,便于管理(注意安全) |
| `root_squash` | 禁止客户端 root 拥有服务器 root 权限(默认更安全) |
| `no_subtree_check` | 不检查子目录层级,性能更好、避免警告(推荐) |
| `subtree_check` | 检查共享子目录的权限(安全但性能略低) |
| `insecure` | 允许非特权端口访问(一般不推荐) |
4️⃣ 重新加载配置并验证
exportfs -r
exportfs -v
5️⃣ 开放防火墙端口
firewall-cmd --permanent --zone=public --add-service=nfs
firewall-cmd --permanent --zone=public --add-service=mountd
firewall-cmd --permanent --zone=public --add-service=rpc-bind
firewall-cmd --reload
6️⃣ 查看服务状态
systemctl status nfs-server
三、客户端(Server1、Server2)配置
1️⃣ 安装并启用 NFS 客户端
dnf install -y nfs-utils
systemctl enable --now nfs-client.target
2️⃣ 创建挂载点并手动挂载
Server1:
mkdir -p /mnt/nfs /mnt/backup
mount -t nfs 192.168.10.103:/data /mnt/nfs
mount -t nfs 192.168.10.103:/backup /mnt/backup
Server2:
mkdir -p /mnt/nfs /mnt/backup
mount -t nfs 192.168.10.103:/data /mnt/nfs
mount -t nfs 192.168.10.103:/backup /mnt/backup
3️⃣ 设置开机自动挂载
编辑 /etc/fstab:
192.168.10.103:/data /mnt/nfs nfs defaults 0 0
192.168.10.103:/backup /mnt/backup nfs defaults 0 0
执行:
mount -a
df -h | grep nfs
四、测试验证
✅ Server1(可读写)
cd /mnt/nfs
touch test_rw.txt
ls /mnt/backup
✅ Server2(只读)
cd /mnt/nfs
touch test_ro.txt # 应提示权限被拒绝
ls /mnt/backup
✅ Server3(服务端验证)
ls /data /backup
确认文件同步显示。
4251





