07 NFS搭建

2021-11-08  本文已影响0人  逸章

我们这里把NFS服务器搭建再K8s的一个master节点上

1、在NFS服务器上安装服务端软件

# yum -y install  nfs-utils

编辑/etc/exports

[root@centos7 /]# vi /etc/exports
/backup 192.168.108.0/24(rw,sync,no_root_squash)

若是想让所有主机都可以挂载,可以配置为 /backup *(rw,sync,no_root_squash)

[root@k8s-master03 ~]# mkdir /backup
[root@k8s-master03 ~]# chmod -R 777 /backup/

启动服务并设置为开机自动启动

[root@k8s-master03 ~]# systemctl enable rpcbind.service
[root@k8s-master03 ~]# systemctl enable nfs-server.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@k8s-master03 ~]# systemctl start rpcbind.service
[root@k8s-master03 ~]# systemctl start nfs-server.service

加载配置并确认最终配置情况

[root@k8s-master03 ~]# exportfs -r
[root@k8s-master03 ~]# exportfs
/backup         192.168.108.0/24
[root@k8s-master03 ~]#
完整过程: image.png

2、在NFS客户端上安装软件

2.1 比如在K8s所有work node上安装

# yum -y install nfs-utils

2.2 检查挂载目录

[root@k8s-master03 Chapter05]# showmount -e 192.168.108.88
Export list for 192.168.108.88:
/backup3 192.168.108.0/16
/backup2 192.168.108.0/16
/backup  192.168.108.0/16

2.3 新建挂载点并挂载:

# mkdir /nfs

挂载共享目录:

# mount -t nfs 192.168.108.88:/backup /nfs

开启自动挂载:

[root@k8s-node1 ~]# cat /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
mount -t nfs 192.168.108.88:/backup /nfs
[root@k8s-node1 ~]#

3、测试

image.png image.png image.png
上一篇 下一篇

猜你喜欢

热点阅读