主页 > 电脑硬件  > 

k8s学习-数据管理之nfs手动搭建


需要先准备好3台虚拟机 系统CentOS7

IP 192.168.200.128 master IP 192.168.200.129 node1 IP 192.168.200.130 node2

问题描述

在学习数据管理的时候创建完pv和pvc以后,创建了pod使用pvc,但是pod创建不成功。 查看pod描述

kubectl describe pod mypod1

描述有错误信息:

Normal Scheduled 22m default-scheduler Successfully assigned default/mypod1 to k8s-node2 Warning FailedMount 22m kubelet, k8s-node2 MountVolume.SetUp failed for volume "mypv1" : mount failed: exit status 32 Mounting command: systemd-run Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/pods/2637337e-f53f-4b97-883b-1c7cdbb7e497/volumes/kubernetes.io~nfs/mypv1 --scope -- mount -t nfs 192.168.200.128:/nfsdata/pv1 /var/lib/kubelet/pods/2637337e-f53f-4b97-883b-1c7cdbb7e497/volumes/kubernetes.io~nfs/mypv1 Output: Running scope as unit run-28836.scope. mount: 文件系统类型错误、选项错误、192.168.200.128:/nfsdata/pv1 上有坏超级块、 缺少代码页或助手程序,或其他错误 (对某些文件系统(如 nfs、cifs) 您可能需要 一款 /sbin/mount.<类型> 助手程序) 有些情况下在 syslog 中可以找到一些有用信息- 请尝试 dmesg | tail 这样的命令看看。

是因为在安装完master节点的nfs以后我并没有在node1和node2上安装nfs。所以完整安装一遍nfs以后就可以正常测试nfs了。

1.0 命令安装nfs yum -y install nfs-utils rpcbind

会提示找不到镜像,所以就手动安装了一遍。

1.1 手动安装nfs

先下载nfs所需要的文件。 百度网盘下载安装包:

链接:https://pan.baidu.com/s/1ORc1cXa042tP5DDRJgbuXw?pwd=1234 提取码:1234

下载上述nfs离线包,把包上传到centos7服务器,使用下列命令按顺序执行命令。

# 1.创建文件夹 mkdir -p /root/nfs # 2.上传到当前目录 # 3. 安装: rpm -ivh *.rpm --force --nodeps

执行安装命令。

[root@k8s-node2 nfs]# rpm -ivh *.rpm --force --nodeps 警告:tcp_wrappers-7.6-48.mga7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 80 420f66: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:libverto-0.2.5-4.el7 ################################# [ 6%] 2:libtirpc-0.2.4-0.16.el7 ################################# [ 12%] 3:rpcbind-0.2.0-49.el7 ################################# [ 18%] 4:libref_array-0.1.5-32.el7 ################################# [ 24%] 5:libevent-2.0.21-4.el7 ################################# [ 29%] 6:libcollection-0.7.0-32.el7 ################################# [ 35%] 7:libbasicobjects-0.1.1-32.el7 ################################# [ 41%] 8:libverto-libevent-0.2.5-4.el7 ################################# [ 47%] 9:tcp_wrappers-7.6-48.mga7 ################################# [ 53%] 10:quota-nls-1:4.01-19.el7 ################################# [ 59%] 11:quota-1:4.01-19.el7 ################################# [ 65%] 12:libpath_utils-0.2.1-32.el7 ################################# [ 71%] 13:libini_config-1.3.1-32.el7 ################################# [ 76%] 14:gssproxy-0.7.0-30.el7_9 ################################# [ 82%] 15:libnfsidmap-0.25-19.el7 ################################# [ 88%] 16:keyutils-1.5.8-3.el7 ################################# [ 94%] 17:nfs-utils-1:1.3.0-0.68.el7.2 ################################# [100%] 1.2 启动nfs

服务端:

开机启动

systemctl enable rpcbind.service systemctl enable nfs-server.service

启动nfs

systemctl start rpcbind.service systemctl start nfs-server.service service nfs start

检查启动项

chkconfig nfs on

客户端: systemctl enable rpcbind.service systemctl start rpcbind.service 注意:客户端不需要启动nfs服务

1.3配置NFS服务端

1.创建共享目录

mkdir -p /nfsdata mkdir -p /nfsdata/pv1

2.修改exports文件

# 1.编辑配置文件 vi /etc/exports # 修改配置文件,增加下面这一行数据,指定的ip地址为客户端的地址,ip可设置为*表示所有服务器可访问 /nfsdata *(rw,all_squash) /nfsdata/pv1 *(rw,all_squash) # 2.加载配置文件 exportfs -arv

3.目录授权

chmod o+w /nfsdata chmod o+w /nfsdata/pv1

4.重启服务

systemctl restart rpcbind.service systemctl restart nfs-server.service 1.4 客户端挂载

在其中一个node节点上执行showmount ,查看master可挂载的目录

[root@k8s-node1 ~]# showmount -e 192.168.200.128 Export list for 192.168.200.128: /nfsdata/pv1 * /nfsdata *

执行挂载

[root@k8s-node1 ~]# mkdir /root/mcw/ [root@k8s-node1 ~]# mount -t nfs 192.168.200.128:/nfsdata/ /root/mcw/ [root@k8s-node1 ~]# df -h|tail -1 192.168.200.128:/nfsdata 27G 3.7G 24G 14% /root/mcw [root@k8s-node1 ~]# df -h 192.168.200.128:/nfsdata 27G 3.7G 24G 14% /root/mcw

创建文件,查看挂载结果

[root@k8s-node1 ~]# touch /root/mcw/test.txt [root@k8s-node1 ~]# ls /root/mcw/ mypv1 pv1 test.txt [root@k8s-node1 ~]# df -h|grep mcw 192.168.200.128:/nfsdata 27G 3.7G 24G 14% /root/mcw

挂载/nfsdata/pv1

[root@k8s-node1 ~]# mount -t nfs 192.168.200.128:/nfsdata/pv1 /root/mcw/ mount.nfs: /root/mcw is busy or already mounted [root@k8s-node1 ~]# umount /root/mcw [root@k8s-node1 ~]# mount -t nfs 192.168.200.128:/nfsdata/pv1 /root/mcw/

设置开机自动挂载

mount -t nfs 192.168.200.128:/nfsdata/pv1 /root/mcw/

切换到master

[root@k8s-master ~]# ls /nfsdata/pv1/ [root@k8s-master ~]# ls /nfsdata mypv1 pv1 test.txt [root@k8s-master ~]# ls /nfsdata/pv1/ test.txt

可以看到在node节点创建的文件,到此就按照成功了。

标签:

k8s学习-数据管理之nfs手动搭建由讯客互联电脑硬件栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“k8s学习-数据管理之nfs手动搭建