NFS配置指南
NFS(Network File System)是一种网络文件系统协议,允许客户端像访问本地文件一样访问远程共享资源。以下是配置 NFS 的详细步骤。
1.服务端配置
安装必要软件
在服务端安装 *nfs-utils* 和 *rpcbind*:
yum install -y nfs-utils rpcbind创建共享目录
创建并设置共享目录的权限:
mkdir /data/share
chmod 777 /data/share编辑配置文件
修改 */etc/exports* 文件,添加共享目录配置:
vim /etc/exports
/data/share 192.168.1.0/24(rw,sync,no_root_squash)rw:读写权限
sync:同步写入
no_root_squash:允许客户端以 root 权限访问
保存并退出。
启动服务
启动并设置服务开机自启:
systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable nfs发布共享目录
刷新并查看共享目录:
exportfs -rv
showmount -e localhost2.客户端配置
安装必要软件
在客户端安装 nfs-utils:
yum install -y nfs-utils查看共享目录
检查服务端的共享目录:
showmount -e 192.168.1.100挂载共享目录
将远程目录挂载到本地:
mkdir /mnt/nfs_share
mount 192.168.1.100:/data/share /mnt/nfs_share验证挂载
使用以下命令确认挂载成功:
df -h | grep nfs_share3.自动挂载(可选)
编辑 */etc/fstab* 文件,添加以下内容以实现开机自动挂载:
192.168.1.100:/data/share /mnt/nfs_share nfs defaults,_netdev 0 04.注意事项
使用 umount 命令卸载挂载的目录:
umount /mnt/nfs_share如果需要更高的稳定性,可以使用 TCP 协议挂载:
mount -o proto=tcp,nolock 192.168.1.100:/data/share /mnt/nfs_share通过以上步骤,您可以成功配置 NFS 服务,实现网络文件共享。
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 FengLee