下面为你介绍基于CentOS7的NFS服务端和客户端的配置方法。
NFS服务端配置
- 安装NFS服务相关软件包
yum install -y nfs-utils rpcbind
- 启动并设置开机自启服务
systemctl start rpcbind systemctl start nfs-server systemctl enable rpcbind systemctl enable nfs-server
- 创建共享目录并设置权限
mkdir -p /data/nfs_share
chmod -R 777 /data/nfs_share
chown -R nfsnobody:nfsnobody /data/nfs_share
- 配置共享目录(编辑/etc/exports文件)
vi /etc/exports
在文件中添加如下内容(允许192.168.1.0/24网段访问):
/data/nfs_share 192.168.1.0/24(rw,sync,no_root_squash,no_all_squash)
配置参数说明:
- rw:读写权限
- sync:同步写入磁盘
- no_root_squash:客户端root用户保持权限
- no_all_squash:保持客户端用户权限
- 使配置生效
exportfs -r
- 查看共享情况
exportfs -v
- 配置防火墙(如果启用)
firewall-cmd --add-service=nfs --permanent
firewall-cmd --add-service=rpc-bind --permanent
firewall-cmd --add-service=mountd --permanent
firewall-cmd --reload
NFS客户端配置
- 安装客户端软件
yum install -y nfs-utils
- 启动rpcbind服务
systemctl start rpcbind systemctl enable rpcbind
- 查看服务端共享的目录
showmount -e 192.168.1.100
# 替换为NFS服务端IP
- 创建挂载目录
mkdir -p /mnt/nfs_client
- 临时挂载NFS共享目录
mount -t nfs 192.168.1.100:/data/nfs_share /mnt/nfs_client
- 设置开机自动挂载(编辑/etc/fstab文件)
vi /etc/fstab
添加如下内容:
192.168.1.100:/data/nfs_share /mnt/nfs_client nfs defaults 0 0
- 验证挂载是否成功
df -h
如果能看到NFS共享的挂载信息,则表示配置成功。
通过以上步骤,就可以在CentOS7系统上完成NFS服务端和客户端的配置,实现目录共享功能。