目的
今天写的这篇,主要是为了解决在k8s中搭建mysql,并且基于NFS-PV的方式,基于这种方式搭建有状态存储相对可靠,并且易于维护。
什么是NFS
网上类似的文章很多,可以简单的理解为一种网络存储,分为server和client两部分,server提供真实的存储,client将这部分网络存储挂载到本地,作为共享使用。
搭建NFS-Sever
教程全部基于Centos7.4其他版本请自行尝试
#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
#设置Hosts
hostnamectl set-hostname nfs-cluster-node1
yum -y install nfs-utils rpcbind
#创建挂载目录,尽量选择一块盘单独使用,如果将根目录作为服务提供出去会存在安全问题
mkdir -p /nfs/data
chmod 666 /nfs/data
#配置挂载目录
cat > /etc/exports <<EOF
/nfs/data *(rw,no_root_squash,no_all_squash,sync)
EOF
#重新挂载 exports文件
exportfs -r
service rpcbind start
service nfs start
#查看是否挂载成功
showmount -e localhost
#成功输出如下
#Export list for localhost:
#/nfs/data *
搭建NFS-Client
# 安装nfs组件
yum -y install nfs-utils rpcbind
# 创建想要挂载的目录
mkdir -p /pv/mysql/
# 挂载nfs-server ip为nfs-server
mount -t nfs 192