NFS 即network file system
可用于向k8s集群提供持久存储
最小化安装centos后 把网卡设置好了后
1.关闭防火墙
[root@NFS ~]# systemctl stop firewalld
[root@NFS ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@NFS ~]# firewall-cmd --state
not running
2.关闭 selinux
[root@NFS ~]# setenforce
[root@NFS ~]# sed -i 's/^ *SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
重启后生效
[root@NFS ~]# reboot
[root@NFS ~]# sestatus
SELinux status: disabled
3.yum安装 配置 nfs服务端
yum update一下再安装
yum -y install nfs-utils
配置 任意ip可以以root的权限对/k8s文件夹进行读写
[root@NFS ~]# cat /etc/exports
/k8s *(rw,sync,no_root_squash)
#创建一个k8s目录
[root@NFS ~]# mkdir /k8s
#给权限
[root@NFS /]# chmod 777 /k8s
设置开机自启 并启动
[root@NFS /]# systemctl enable rpcbind
[root@NFS /]# systemctl enable nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@NFS /]# systemctl start rpcbind
[root@NFS /]# systemctl start nfs-server
加载配置并查看
[root@NFS /]# exportfs -r
[root@NFS /]# exportfs
/k8s <world>
4.安装配置 nfs客户端, 在每个k8s节点上做.
yum安装
yum -y install nfs-utils
创建要挂载nfs的文件夹
mkdir /nfs
查看nfs 我的nfs服务端安装在192.168.1.250 上
[root@m1 ~]# showmount -e 192.168.1.250
Export list for 192.168.1.250:
/k8s *
挂载nfs 中的k8s目录到 /nfs
[root@m1 ~]# mount -t nfs 192.168.1.250:/k8s /nfs
自动挂载
[root@m1 ~]# 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.1.250:/k8s /nfs
给权限防止因为权限没有执行 除了root,其他用户的只有读和执行的权限
chmod /etc/rc.local
测试
[root@m1 nfs]# vi hello
[root@m1 nfs]# ll
total
-rw-r--r--. root root Nov : hello
至此 nfs实践结束