安装NFS服务
# 安装nfs
[root@k8s-master01 nfs]# dnf install nfs-utils
Repository extras is listed more than once in the configuration
Last metadata expiration check: 3:24:27 ago on Wed 19 May 2021 10:33:02 AM CST.
Package nfs-utils-1:2.3.3-41.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
# 启动nfs服务
[root@k8s-master01 nfs]# systemctl enable --now nfs-server
Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service → /usr/lib/systemd/system/nfs-server.service.
# 查看可用版本
[root@k8s-master01 nfs]# cat /proc/fs/nfsd/versions
-2 +3 +4 +4.1 +4.2
创建文件系统(根据实际使用配置)
# 创建全局NFS根目录
[root@k8s-master01 /]# mkdir -p /data/nfs
# 将分享目录(share)绑定至NFS根目录(share)中
[root@k8s-master01 /]# mkdir -p /data/nfs/share
[root@k8s-master01 share]# sudo mount --bind /home/share /data/nfs/share
# 挂载持久化(按需配置)
[root@k8s-master01 share]# vim /etc/fstab
# 末尾添加
/home/share /data/nfs/share none bind 0 0
导出文件系统
说明: 配置导出文件夹的权限
[root@k8s-master01 share]# vim /etc/exports
# 添加
/data/nfs/ 192.168.100.0/24(rw,sync,no_subtree_check,crossmnt,fsid=0)
# fsid=0 定义了 NFS 根目录/data/nfs。
# 来自192.168.0.0/24网络的所有客户端被允许访问 NFS 卷。
# crossmnt选项是必要的,用来分享被导出目录的子目录。
# 导出分享
[root@k8s-master01 share]# exportfs -ra
挂载/取消挂载命令
# 挂载命令
[root@k8s-master02 ~]# mount -t nfs 192.168.100.12:/data/nfs/share /data/nfs/share
# 取消挂载命令
[root@k8s-master02 ~]# umount /data/nfs/share