安装 Gluster FS
1 | 先安装 gluster 源 |
配置 Gluster FS
1 | 配置 hosts |
配置 Gluster FS Volume
GlusterFS中的volume的模式有很多中,包括以下几种:
- 分布卷(默认模式):即DHT, 也叫 分布卷: 将文件已hash算法随机分布到 一台服务器节点中存储。
- 复制模式:即AFR, 创建volume 时带 replica x 数量: 将文件复制到 replica x 个节点中。
- 条带模式:即Striped, 创建volume 时带 stripe x 数量: 将文件切割成数据块,分别存储到 stripe x 个节点中 ( 类似raid 0 )。
- 分布式条带模式:最少需要4台服务器才能创建。 创建volume 时 stripe 2 server = 4 个节点: 是DHT 与 Striped 的组合型。
- 分布式复制模式:最少需要4台服务器才能创建。 创建volume 时 replica 2 server = 4 个节点:是DHT 与 AFR 的组合型。
- 条带复制卷模式:最少需要4台服务器才能创建。 创建volume 时 stripe 2 replica 2 server = 4 个节点: 是 Striped 与 AFR 的组合型。
- 三种模式混合: 至少需要8台 服务器才能创建。 stripe 2 replica 2 , 每4个节点 组成一个 组。
这几种模式的示例图参考:CentOS7安装GlusterFS。
因为我们只有四台主机,在此我们使用默认的分布式复制模式。
1 | 创建分布卷 |
调优 Gluster FS
1 | 开启 指定 volume 的配额 |
在 Kubernetes 使用 Gluster FS
安装 Gluster FS 客户端
1 | 在所有 k8s node 中安装 glusterfs 客户端 |
创建 endpoints
1 | curl -O https://raw.githubusercontent.com/batizhao/dockerfile/master/k8s/glusterfs/glusterfs-endpoints.yaml |
创建 PersistentVolume
1 | curl -O https://raw.githubusercontent.com/batizhao/dockerfile/master/k8s/glusterfs/glusterfs-pv.yaml |
创建 PersistentVolumeClaim
1 | curl -O https://raw.githubusercontent.com/batizhao/dockerfile/master/k8s/glusterfs/glusterfs-pvc.yaml |
创建测试 nginx 挂载 volume
1 | curl -O https://raw.githubusercontent.com/batizhao/dockerfile/master/k8s/glusterfs/nginx-deployment.yaml |
安装 Heketi
GlusterFS 是个开源的分布式文件系统,而 Heketi 在其上提供了 REST 形式的 API,二者协同为 Kubernetes 提供了存储卷的自动供给能力。
- Heketi 服务器:172.31.21.208
- Gluster 服务器:
- 172.31.21.208
- 172.31.21.209
- 172.31.21.210
- 172.31.21.211
1 | 安装 |
制作完成后会在当前目录下生成 heketi_key、heketi_key.pub。接下来,修改 /etc/heketi/heketi.json 中的 keyfile 指向生成的 key。
1 | 将公钥 heketi_key.pub 拷贝到所有 glusterfs 节点上 /etc/heketi/keketi_key.pub |
1 | cat /etc/heketi/heketi.json |