参考文档:

https://cloud.tencent.com/developer/article/1602926

https://www.cnblogs.com/biehongli/p/13214542.html

https://www.cnblogs.com/breezey/p/8849466.html

GlusterFS 几种volume 模式说明:

一、 默认模式,既DHT, 也叫 分布卷: 将文件已hash算法随机分布到 一台服务器节点中存储。

gluster volume create test-volume server1:/exp1 server2:/exp2

二、 复制模式,既AFR, 创建volume 时带 replica x 数量: 将文件复制到 replica x 个节点中。

gluster volume create test-volume replica 2 transport tcp server1:/exp1 server2:/exp2

三、 条带模式,既Striped, 创建volume 时带 stripe x 数量: 将文件切割成数据块,分别存储到 stripe x 个节点中 ( 类似raid 0 )。

gluster volume create test-volume stripe 2 transport tcp server1:/exp1 server2:/exp2

四、 分布式条带模式(组合型),最少需要4台服务器才能创建。 创建volume 时 stripe 2 server = 4 个节点: 是DHT 与 Striped 的组合型。

gluster volume create test-volume stripe 2 transport tcp server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4

五、 分布式复制模式(组合型), 最少需要4台服务器才能创建。 创建volume 时 replica 2 server = 4 个节点:是DHT 与 AFR 的组合型。

gluster volume create test-volume replica 2 transport tcp server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4

六、 条带复制卷模式(组合型), 最少需要4台服务器才能创建。 创建volume 时 stripe 2 replica 2 server = 4 个节点: 是 Striped 与 AFR 的组合型。

gluster volume create test-volume stripe 2 replica 2 transport tcp server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4

七、 三种模式混合, 至少需要8台 服务器才能创建。 stripe 2 replica 2 , 每4个节点 组成一个 组。

gluster volume create test-volume stripe 2 replica 2 transport tcp server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4 server5:/exp5 server6:/exp6 server7:/exp7 server8:/exp8

安装规划:三台服务器

1IP              主机名
2172.16.2.135    k8s-master
3172.16.2.136    k8s-node1
4172.16.2.137    k8s-node2

这只是用户测试。生产过程中, 建议使用分布式复制模式

  1. 安装

(1)、配置hosts(三台服务器都要操作)

1[root@k8s-master ~]# vi /etc/hosts
2# 添加如下内容:
3172.16.2.135 k8s-master
4172.16.2.136 k8s-node1
5172.16.2.137 k8s-node2

(2)、YUM安装(三台服务器都要操作)

1[root@k8s-master ~]# yum install centos-release-gluster -y
2[root@k8s-master ~]# yum install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma -y

(3)、启动并配置开机自启动(三台服务器都要操作)

1[root@k8s-master ~]# systemctl start glusterd.service && systemctl enable glusterd.service

(4)、如果防火墙是开启的需要配置防火墙(三台服务器都要操作)

1[root@k8s-master ~]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 24007 -j  ACCEPT
2[root@k8s-master ~]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 24008 -j ACCEPT
3[root@k8s-master ~]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 2222 -j ACCEPT
4[root@k8s-master ~]# iptables -I INPUT -p tcp -m state --state NEW -m multiport --dports 49152:49251 -j ACCEPT

(5)、将节点加入集群(master节点操作)

添加存储资源池,即将节点都组装起来,在master主节点进行操作,可以查看gluster的资源池(如果gluster没有提示,可以先退出xshell,再重新登录即可),如下所示:

1[root@k8s-master ~]# gluster pool list
2UUID                                    Hostname        State
3cab52f64-7cec-484a-a227-92b158e81143    localhost       Connected

资源池默认只能识别出自己本身,这里需要将另外两个节点加入到资源池中,根据hostname加入到资源池,需要做host解析的,如下所示:

1[root@k8s-master ~]# gluster peer probe k8s-node1
2peer probe: success
3[root@k8s-master ~]# gluster peer probe k8s-node2
4peer probe: success

此时,再次查看资源池,发现已经有了三个节点了,如下所示:

1[root@k8s-master ~]# gluster pool list 
2UUID                                    Hostname        State
357eb6f0b-0b44-4dcc-a9e0-2d9b35877c14    k8s-node1       Connected 
413b7b5cc-9909-458b-b493-4671421c9260    k8s-node2       Connected 
5cab52f64-7cec-484a-a227-92b158e81143    localhost       Connected

查看集群状态

 1[root@k8s-master ~]# gluster peer status
 2Number of Peers: 2
 3
 4Hostname: k8s-node1
 5Uuid: 57eb6f0b-0b44-4dcc-a9e0-2d9b35877c14
 6State: Peer in Cluster (Connected)
 7
 8Hostname: k8s-node2
 9Uuid: 13b7b5cc-9909-458b-b493-4671421c9260
10State: Peer in Cluster (Connected)

2、测试

(1)、创建volume

创建数据目录,所有节点都要操作

1[root@k8s-master ~]# mkdir -p /data/gluster-data

新建卷(3个副本的复制模式),任意一个节点操作即可

1[root@k8s-master ~]# gluster volume create glusterfs_volume replica 3 k8s-master:/data/gluster-data k8s-node1:/data/gluster-data k8s-node2:/data/gluster-data force
2volume create: glusterfs_volume: success: please start the volume to access data

(2)、查看所有volume

 1[root@k8s-master ~]# gluster volume info
 2 
 3Volume Name: glusterfs_volume
 4Type: Replicate
 5Volume ID: ee84cc19-9ce1-4825-9947-f114dafbe644
 6Status: Created
 7Snapshot Count: 0
 8Number of Bricks: 1 x 3 = 3
 9Transport-type: tcp
10Bricks:
11Brick1: k8s-master:/data/gluster-data
12Brick2: k8s-node1:/data/gluster-data
13Brick3: k8s-node2:/data/gluster-data
14Options Reconfigured:
15cluster.granular-entry-heal: on
16storage.fips-mode-rchecksum: on
17transport.address-family: inet
18nfs.disable: on
19performance.client-io-threads: off

(3)、启动volume

 1##### 启动
 2[root@k8s-master ~]# gluster volume start glusterfs_volume
 3volume start: glusterfs_volume: success
 4
 5##### 查看volume状态
 6[root@k8s-master ~]# gluster volume info glusterfs_volume
 7 
 8Volume Name: glusterfs_volume
 9Type: Replicate
10Volume ID: ee84cc19-9ce1-4825-9947-f114dafbe644
11Status: Started
12Snapshot Count: 0
13Number of Bricks: 1 x 3 = 3
14Transport-type: tcp
15Bricks:
16Brick1: k8s-master:/data/gluster-data
17Brick2: k8s-node1:/data/gluster-data
18Brick3: k8s-node2:/data/gluster-data
19Options Reconfigured:
20cluster.granular-entry-heal: on
21storage.fips-mode-rchecksum: on
22transport.address-family: inet
23nfs.disable: on
24performance.client-io-threads: off

(4)、安装client

1[root@k8s-master ~]# yum install -y glusterfs glusterfs-fuse

(5)、挂载

1[root@k8s-master ~]# mount -t glusterfs k8s-master:glusterfs_volume /mnt

3、调优(可选,未测试)

 1# 开启 指定 volume 的配额
 2$ gluster volume quota k8s-volume enable
 3# 限制 指定 volume 的配额
 4$ gluster volume quota k8s-volume limit-usage / 1TB
 5# 设置 cache 大小, 默认32MB
 6$ gluster volume set k8s-volume performance.cache-size 4GB
 7# 设置 io 线程, 太大会导致进程崩溃
 8$ gluster volume set k8s-volume performance.io-thread-count 16
 9# 设置 网络检测时间, 默认42s
10$ gluster volume set k8s-volume network.ping-timeout 10
11# 设置 写缓冲区的大小, 默认1M
12$ gluster volume set k8s-volume performance.write-behind-window-size 1024MB

4、heketi 的安装和配置

简介

Heketi提供了一个RESTful管理界面,可以用来管理GlusterFS卷的生命周期。

通过Heketi,就可以像使用OpenStack Manila,Kubernetes和OpenShift一样申请可以动态配置GlusterFS卷。

Heketi会动态在集群内选择bricks构建所需的volumes,这样以确保数据的副本会分散到集群不同的故障域内。

同时Heketi还支持任意数量的ClusterFS集群,以保证接入的云服务器不局限于单个GlusterFS集群。

heketi项目地址:https://github.com/heketi/heketi

下载地址:

wget https://github.com/heketi/heketi/releases/download/v10.3.0/heketi-v10.3.0.linux.amd64.tar.gz

wget https://github.com/heketi/heketi/releases/download/v10.3.0/heketi-client-v10.3.0.linux.amd64.tar.gz