温馨提示×

centos mount怎样挂NFS

小樊
39
2026-09-06 05:06:34
栏目: 智能运维

在 CentOS 上挂载 NFS(Network File System)一般分为 服务端共享客户端挂载 两部分。下面以 CentOS 7/8 为例说明。


一、NFS 服务端(提供共享目录)

1. 安装 NFS 服务

yum install -y nfs-utils rpcbind

2. 启动服务

systemctl start rpcbind
systemctl start nfs-server
systemctl enable rpcbind
systemctl enable nfs-server

3. 创建共享目录

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

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

vim /etc/exports

示例(允许 192.168.1.0/24 网段访问):

/data/nfs 192.168.1.0/24(rw,sync,no_root_squash)

常用参数说明:

  • rw:读写
  • ro:只读
  • sync:同步写入
  • no_root_squash:root 用户不映射
  • all_squash:所有用户映射为匿名

5. 使配置生效

exportfs -r

二、NFS 客户端(挂载 NFS)

1. 安装客户端工具

yum install -y nfs-utils

2. 创建挂载点

mkdir -p /mnt/nfs

3. 挂载 NFS

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

192.168.1.100 是 NFS 服务端 IP

4. 查看是否挂载成功

df -h
mount | grep nfs

三、开机自动挂载

编辑 /etc/fstab

vim /etc/fstab

添加一行:

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

测试:

mount -a

四、常见问题排查

1. 挂载时报 No route to host

  • 防火墙未放行
  • NFS 服务未启动

服务端放行端口(CentOS 7):

firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=mountd
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --reload

2. 权限拒绝

  • 检查 /etc/exports
  • 客户端用户 ID 是否匹配
  • 是否使用了 root_squash

如果你能提供 CentOS 版本具体报错信息,我可以给你更精确的命令。

0