NFS 挂载教程

Posted by Forgus on 2026-03-19

环境信息

项目
NFS 服务器 192.168.2.20
导出目录 /volume3/wiki
挂载点 /mnt/nfs
权限 读写

挂载步骤

1. 安装 NFS 客户端(可选)

1
2
3
4
5
# Ubuntu/Debian
sudo apt install nfs-common

# CentOS/RHEL
sudo yum install nfs-utils

2. 创建挂载点

1
sudo mkdir -p /mnt/nfs

3. 挂载 NFS

1
2
3
4
5
# 临时挂载
sudo mount -t nfs 192.168.2.20:/volume3/wiki /mnt/nfs

# 带选项挂载(可选)
sudo mount -t nfs -o rw,soft,timeo=30 192.168.2.20:/volume3/wiki /mnt/nfs

常用选项说明:

选项 说明
ro / rw 只读 / 读写
soft 软挂载(超时返回错误)
hard 硬挂载(一直重试)
timeo=N 超时秒数
bg / fg 后台 / 前台重试

4. 配置开机自动挂载

编辑 /etc/fstab,添加一行:

1
192.168.2.20:/volume3/wiki   /mnt/nfs   nfs   defaults   0   0

格式说明:

1
<file system>  <mount point>  <type>  <options>  <dump>  <pass>
  • <dump>: 0 表示不备份
  • <pass>: 0 表示不检查磁盘顺序

修改后重载 systemd:

1
sudo systemctl daemon-reload

验证命令

1
2
3
4
5
6
7
8
# 查看挂载状态
mount | grep nfs

# 查看磁盘使用
df -h /mnt/nfs

# 测试写入
touch /mnt/nfs/test && rm /mnt/nfs/test

卸载 NFS

1
sudo umount /mnt/nfs

如遇忙碌:

1
sudo umount -l /mnt/nfs  # 强制卸载