# 安装 glusterfs 组件
yum install -y glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma glusterfs-geo-replication glusterfs-devel
## 创建 glusterfs 目录
mkdir /data/glusterd
## 修改 glusterd 目录
$ sed -i 's/var\/lib/export/g' /etc/glusterfs/glusterd.vol
# 启动 glusterfs,设置开机启动,
查看状态
systemctl start glusterd.service
systemctl enable glusterd.service
systemctl status glusterd.service
配置 glusterfs
[root@node1 glusterd]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.20.171 master1 etcd1
192.168.20.172 master2 etcd2
192.168.20.173 master3 etcd3
192.168.20.174 node1
192.168.20.175 node2
192.168.20.176 node3
192.168.20.177 node4
192.168.20.178 node5
# 添加节点到 集群, 执行操作的本机不需要probe 本机执行
[root@node1 ~]#
gluster peer probe node2
gluster peer probe node3
gluster peer probe node4
gluster peer probe node5
查看集群状态
[root@node1 glusterd]# gluster peer status
Number of Peers: Hostname: node2
Uuid: 58fe4710--4f18-8ae7-92d0130efbb7
State: Peer in Cluster (Connected) Hostname: node3
Uuid: af0985bd-2f85--9ac6-5712cd35b148
State: Peer in Cluster (Connected) Hostname: node4
Uuid: 917cb471--48b5-95ad-454395f3f1f4
State: Peer in Cluster (Connected) Hostname: node5
Uuid: a73078df-13a5-4b2c-b3bb-9a63f25f77fa
State: Peer in Cluster (Connected)
创建存储目录
mkdir /export/gfs_data
配置 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个节点 组成一个 组。
创建分布式卷
gluster volume create senyintvolume stripe replica transport tcp node1:/export/gfs_data/ node2:/export/gfs_data/ node3:/export/gfs_data/ node4:/export/gfs_data/ node5:/export/gfs_data/ node1:/data/gfs_data/ node2:/data/gfs_data/ node3:/data/gfs_data/ force
查看卷
[root@node1 glusterd]# gluster volume info Volume Name: senyintvolume
Type: Distributed-Striped-Replicate
Volume ID: d11a39c5-65c8-415a-ac28-a698554a2b77
Status: Created
Snapshot Count:
Number of Bricks: x x =
Transport-type: tcp
Bricks:
Brick1: node1:/export/gfs_data
Brick2: node2:/export/gfs_data
Brick3: node3:/export/gfs_data
Brick4: node4:/export/gfs_data
Brick5: node5:/export/gfs_data
Brick6: node1:/data/gfs_data
Brick7: node2:/data/gfs_data
Brick8: node3:/data/gfs_data
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off
启动 分布卷
gluster volume start senyintvolume
再次查看
[root@node1 glusterd]# gluster volume info Volume Name: senyintvolume
Type: Distributed-Striped-Replicate
Volume ID: d11a39c5-65c8-415a-ac28-a698554a2b77
Status: Started
Snapshot Count:
Number of Bricks: x x =
Transport-type: tcp
Bricks:
Brick1: node1:/export/gfs_data
Brick2: node2:/export/gfs_data
Brick3: node3:/export/gfs_data
Brick4: node4:/export/gfs_data
Brick5: node5:/export/gfs_data
Brick6: node1:/data/gfs_data
Brick7: node2:/data/gfs_data
Brick8: node3:/data/gfs_data
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off
Glusterfs调优
# 设置 cache 大小, 默认32MB
$ gluster volume set senyintvolume performance.cache-size 4GB # 设置 io 线程, 太大会导致进程崩溃
$ gluster volume set senyintvolume performance.io-thread-count # 设置 网络检测时间, 默认42s
$ gluster volume set senyintvolume network.ping-timeout # 设置 写缓冲区的大小, 默认1M
$ gluster volume set senyintvolume performance.write-behind-window-size 1024MB # 开启 指定 volume 的配额,不使用
# gluster volume quota k8s-volume enable
# 限制 指定 volume 的配额,不使用
# gluster volume quota k8s-volume limit-usage / 1TB
挂载使用
master1: yum install glusterfs-client
mount -t glusterfs node1:/senyintvolume /data//
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