Loading... ## 简介 > 作用: 解决数据一致性问题,实现多主机目录共享。 > NFS服务程序的配置文件为 `/etc/exports`,需要严格按照 `共享目录的路径 允许访问的NFS客户端(共享权限参数)`格式书写,定义要共享的目录与相应的权限,具体书写方式如下图所示。 | 配置语法 | nfs服务端共享目录 | nfs客户端地址 | nfs客户端挂载目录 | 参数 | | ---------- | ----------------- | --------------- | ----------------- | -------------------- | | `语法含义` | `/nfs` | `100.100.157.*` | `/nfs_client` | `rw,sync,all_squash` | | 节点 | ip | | ---------- | -------------- | | nfs-server | 100.100.157.10 | | nfs-client | 100.100.157.11 | | nfs-client | 100.100.157.12 | ### nfs服务端安装配置 ``` ###安装nfs yum install -y nfs-utils ###配置共享目录以及nfs客户端 [root@k8s-master01 ~]# cat /etc/exports /nfs 100.100.157.11/24(rw,sync,all_squash) /nfs 100.100.157.12/24(rw,sync,all_squash) ###创建共享目录 mkdir /nfs ###启动nfs systemctl enable nfs --now ###验证是否生效 [root@k8s-master01 ~]# cat /var/lib/nfs/etab /nfs 100.100.157.11/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,secure,root_squash,all_squash) /nfs 100.100.157.12/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,secure,root_squash,all_squash) ###如新增配置可使用热更新 [root@k8s-master01 ~]# exportfs -r ``` ### nfs客户端配置 ``` ###安装nfs,客户端无需启动 yum install -y nfs-utils ###验证客户端与服务端的联通性 [root@k8s-node02 ~]# showmount -e 100.100.157.10 Export list for 100.100.157.10: /nfs 100.100.157.12/24,100.100.157.11/24 ``` ### 验证挂载 ``` ###客户端执行挂载命令 mount -t nfs 100.100.157.10:/nfs /nfs_client/ ###验证 [root@k8s-node02 ~]# df -h |grep nfs 100.100.157.10:/nfs 36G 3.7G 32G 11% /nfs_client ``` `验证文件同步`  最后修改:2025 年 05 月 15 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 4 如果觉得我的文章对你有用,请随意赞赏