先决条件
NFS Server IP: 192.168.33.148
NFS Clients IPs: From the 192.168.1.0/24 range
本次主要在server 端搭建服务。
搭建 NFS 服务器
sudo dnf install nfs-utils
sudo systemctl enable --now nfs-server
## 默认情况下,在 CentOS 8 上启用 NFS 版本 3 和 4.x,禁用版本 2。NFSv2 现在已经很老了,没有理由启用它。要验证它,请运行以下cat 命令:
sudo cat /proc/fs/nfsd/versions
#output
#-2 +3 +4 +4.1 +4.2
NFS 服务器配置选项在 /etc/nfsmount.conf 和 /etc/nfs.conf 文件中设置。默认设置足以满足我们的教程。
创建输出目录
sudo mkdir -p /mnt/demo
#选择你要授权的用户
sudo chown nobody:nogroup /mnt/demo
sudo chmod 777 /mnt/demo
授予客户端机器访问 NFS 服务器的权限
sudo nano /etc/exports
#添加如下内容
/mnt/demo clientIP(rw,sync,no_subtree_check)
#或者添加整个网段的内容
/mnt/demo 192.168.1.0/24(rw,sync,no_subtree_check)
#验证配置
sudo exportfs -a
最后就是nfs 客户端挂载nfs共享的目录了,这里不在这儿介绍,可以参考下面的文章。
备注:
rw:读写操作。客户端机器拥有对存储卷的读写权限。
sync:更改将被写入磁盘和内存中。
no_subtree_check:防止子树检查,即禁用客户端挂载允许的子目录所需的安全验证。
具体请参考以前的文章:
centos7安装nfs服务器
how-to-install-and-configure-an-nfs-server-on-centos-8
安装及配置 NFS 服务器