温馨提示×

centos mount如何挂nfs

小樊
31
2026-10-23 15:06:20
栏目: 智能运维

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


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

1. 安装 NFS 服务

yum install -y nfs-utils rpcbind

2. 启动服务

systemctl enable --now rpcbind
systemctl enable --now 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

6. 防火墙放行(如有)

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

二、NFS 客户端挂载(CentOS)

1. 安装客户端工具

yum install -y nfs-utils

2. 查看服务端共享

showmount -e 192.168.1.100

3. 创建挂载点

mkdir -p /mnt/nfs

4. 手动挂载

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

5. 验证挂载

df -h
mount | grep nfs

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

vi /etc/fstab

添加一行:

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

测试:

mount -a

四、常见问题

1. 挂载卡住

  • 检查网络
  • 检查防火墙
  • 使用 soft 或 timeo 参数:
mount -t nfs -o soft,timeo=10 192.168.1.100:/data/nfs /mnt/nfs

2. 权限问题

  • 服务端目录权限
  • no_root_squash 是否配置
  • SELinux:
setsebool -P nfs_export_all_rw on

如果你需要 CentOS 6 / Rocky / AlmaLinux 或 NFSv4 特定配置,可以告诉我。

0 踩