温馨提示×

centos mount如何挂载nfs

小樊
41
2026-09-09 02:00:38
栏目: 智能运维

在 CentOS 上挂载 NFS(Network File System)一般分为服务端共享和客户端挂载两部分。下面以常见场景为例说明。


一、NFS 服务端(共享目录的机器)

1. 安装 NFS 服务

yum install -y nfs-utils rpcbind

2. 启动服务

systemctl enable rpcbind
systemctl start rpcbind

systemctl enable nfs-server
systemctl start nfs-server

3. 创建共享目录

mkdir -p /data/nfs
chmod 777 /data/nfs

4. 配置共享(/etc/exports)

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 不被映射为匿名用户(测试环境常用)

5. 使配置生效

exportfs -r
exportfs -v

二、NFS 客户端(CentOS 挂载端)

1. 安装客户端工具

yum install -y nfs-utils

2. 创建挂载点

mkdir -p /mnt/nfs

3. 手动挂载 NFS

mount -t nfs 192.168.1.100:/data/nfs /mnt/nfs

如果 NFS 版本有兼容问题,可指定版本:

mount -t nfs -o vers=3 192.168.1.100:/data/nfs /mnt/nfs

4. 验证挂载

df -h
mount | grep nfs

三、开机自动挂载(/etc/fstab)

vi /etc/fstab

添加一行:

192.168.1.100:/data/nfs  /mnt/nfs  nfs  defaults  0 0

或指定版本:

192.168.1.100:/data/nfs  /mnt/nfs  nfs  vers=3,defaults  0 0

保存后测试:

mount -a

四、常见问题排查

1. 挂载卡住或无响应

  • 检查防火墙
systemctl stop firewalld
# 或放行 nfs 服务
firewall-cmd --add-service=nfs --permanent
firewall-cmd --reload

2. 权限拒绝

  • 检查 /etc/exports 网段
  • 检查目录权限
  • 是否使用了 root_squash

3. 查看 NFS 共享

showmount -e 192.168.1.100

如果你有 CentOS 版本(6/7/8/Stream) 或 具体报错信息,我可以给出更精确的命令。

0 踩