GlusterFS群集部署-非常详细

部署GlusterFS集群

资源列表

操作系统配置主机名IP挂载磁盘挂载目录
CentOS 7.91C2Gnode1192.168.93.101/dev/sdb(3G)
/dev/sdc(4G)
/dev/sdd(5G)
/dev/sde(6G)
/b3
/c4
/d5
/e6
CentOS 7.91C2Gnode2192.168.93.102/dev/sdb(3G)
/dev/sdc(4G)
/dev/sdd(5G)
/dev/sde(6G)
/b3
/c4
/d5
/e6
CentOS 7.91C2Gnode3192.168.93.103/dev/sdb(3G)
/dev/sdc(4G)
/dev/sdd(5G)
/b3
/c4
/d5
CentOS 7.91C2Gnode4192.168.93.104/dev/sdb(3G)
/dev/sdc(4G)
/dev/sdd(5G)
/b3
/c4
/d5
CentOS 7.91C1Gclient192.168.93.105

GlusterFS卷信息

卷名称卷类型空间大小/GBBrick
dis-volume分布式卷12node1(/e6)、node2(/e6)
rep-volume复制卷10node3(/d5)、node4(/d5)
dis-rep分布式复制卷16node1(/c4)、node2(/c4)、node3(/c4)、node4(/c4)

基础环境

  • 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
  • 关闭内核安全机制
setenforce 0
sed -i "s/^SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config
  • 修改主机名
hostnamectl set-hostname node1
hostnamectl set-hostname node2
hostnamectl set-hostname node3
hostnamectl set-hostname node4
hostnamectl set-hostname client

配置hosts文件

cat >> /etc/hosts << EOF
192.168.93.101 node1
192.168.93.102 node2
192.168.93.103 node3
192.168.93.104 node4
192.168.93.105 client
EOF

一、安装GlusterFS软件

  • 以上基础操作包括磁盘划分、磁盘挂载根据资源列表做好准备之后即可进行如下操作了

  • 采用YUM源安装所需软件(所有node节点操作

# 以node1为例进行演示
## 安装官方GFS源(YUM)
yum -y install centos-release-gluster
## 安装所需软件
yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma

## 软件作用
glusterfs:GFS核心软件,包含了用于搭建分布式文件系统的主要组件和工具
glusterfs-server:GFS服务端软件包,用于在服务器上部署和管理GFS集群
glusterfs-fuse:基于FUSE的模块,用于在客户端挂载GFS卷,使得客户端可以访问和管理GFS群集中的文件
glusterfs-rdma:一个支持RDMA协议的模块,可以通过RDMA技术提高数据传输的效率和性能。RDMA是一种高性能网络传输技术,可以在不经过CPU的情况下直接在内存之间传输数据,减少了数据传输延迟和CPU的负担

二、启动GlusterFS

  • 在所有node节点执行以下操作
systemctl start glusterd
systemctl enable glusterd

三、添加节点

  • 只在node1上执行以下操作,添加node1~node4节点
[root@node1 ~]# gluster peer probe node1
# node1也可以不执行
peer probe: Probe on localhost not needed
[root@node1 ~]# gluster peer probe node2
peer probe: success
[root@node1 ~]# gluster peer probe node3
peer probe: success
[root@node1 ~]# gluster peer probe node4
peer probe: success

四、查看群集状态

  • 通过以下命令在每个节点上查看群集状态,正常情况下每个节点的输出结果均为“State:Peer in Cluster(cinnected)”。如果显示Disconnected,请检查hosts文件配置
[root@node1 ~]# gluster peer status
Number of Peers: 3

Hostname: node2
Uuid: 07c5d279-8aa5-4c44-a9dd-ff20e48263d0
State: Peer in Cluster (Connected)

Hostname: node3
Uuid: 9381ecdf-29ac-486f-88ce-ad70cc04dabc
State: Peer in Cluster (Connected)

Hostname: node4
Uuid: 28f83bb0-06b3-41d2-92f9-bbb39f3f69ed
State: Peer in Cluster (Connected)

五、创建卷

  • 在部署gluster分布式文件系统时,要根据生产环境的需求,创建合适公司业务的卷

5.1、创建分部试卷

[root@node1 ~]# gluster volume create dis-volume node1:/e6 node2:/e6 force
## force参数表示在创建卷时强制执行,即如果有任何冲突或错误,也会继续创建卷
volume create: dis-volume: success: please start the volume to access data

# 查询卷信息
[root@node1 ~]# gluster volume info dis-volume
 
Volume Name: dis-volume
Type: Distribute
Volume ID: 77e44b01-5a19-40b3-9616-c3187baafaec
Status: Created
Snapshot Count: 0
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: node1:/e6
Brick2: node2:/e6
Options Reconfigured:
storage.fips-mode-rchecksum: on
transport.address-family: inet
nfs.disable: on

# 开启卷
[root@node1 ~]# gluster volume start dis-volume
volume start: dis-volume: success


#### 上述命令中,没有指定类型,默认创建的是分布式卷

5.2、创建复制卷

[root@node1 ~]# gluster volume create rep-volume replica 2 node3:/d5 node4:/d5 force
## force参数表示在创建卷时强制执行,即如果有任何冲突或错误,也会继续创建卷
volume create: rep-volume: success: please start the volume to access data

# 查询卷信息
[root@node1 ~]# gluster volume info rep-volume
 
Volume Name: rep-volume
Type: Replicate
Volume ID: bdfb7901-82f3-49a0-9a45-62cf010cb6d8
Status: Created
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: node3:/d5
Brick2: node4:/d5
Options Reconfigured:
cluster.granular-entry-heal: on
storage.fips-mode-rchecksum: on
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off

# 开启卷
[root@node1 ~]# gluster volume start rep-volume
volume start: rep-volume: success

#### 上述命令中,指定类型为replica,数值为2,而且后面跟了2个Brick Server,所以创建的是复制卷

5.3、创建分布式复制卷

[root@node1 ~]# gluster volume create dis-rep replica 2 node1:/c4 node2:/c4 node3:/c4 node4:/c4 force
## force参数表示在创建卷时强制执行,即如果有任何冲突或错误,也会继续创建卷
volume create: dis-rep: success: please start the volume to access data

# 查询卷信息
[root@node1 ~]# gluster volume info dis-rep
 
Volume Name: dis-rep
Type: Distributed-Replicate
Volume ID: 943599b5-bd22-4bb7-93cf-72d3541eb48a
Status: Created
Snapshot Count: 0
Number of Bricks: 2 x 2 = 4
Transport-type: tcp
Bricks:
Brick1: node1:/c4
Brick2: node2:/c4
Brick3: node3:/c4
Brick4: node4:/c4
Options Reconfigured:
cluster.granular-entry-heal: on
storage.fips-mode-rchecksum: on
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off

# 开启卷
[root@node1 ~]# gluster volume start dis-rep
volume start: dis-rep: success

#### 上述命令中,指定类型为replica,数值为2,而且后面跟了4个Brick Server,是2的两倍,所以创建的是分布式复制卷

六、部署Gluster客户端

  • 部署分布式文件系统后,需要对挂载的服务器安装客户端软件,并创建挂载目录,将分布式文件系统挂载到刚刚创建目录即可。最后将挂载命令添加自启fstab文件中,当服务器重启时,不需要手动挂载

6.1、安装客户端软件

# 下面两个软件Bash源自带
[root@client ~]# yum -y install glusterfs glusterfs-fuse

6.2、创建挂载目录

[root@client ~]# mkdir -p /test/{dis,rep,dis_and_rep}

6.3、挂载Gluster文件系统

  • 确保写入hosts文件,因为是进行主机名的挂载
# 挂载分布式卷
[root@client ~]# mount -t glusterfs node1:dis-volume /test/dis/
# 挂载复制卷
[root@client ~]# mount -t glusterfs node1:rep-volume /test/rep/
# 挂载分布式复制卷
[root@client ~]# mount -t glusterfs node1:dis-rep /test/dis_and_rep/


# 查看挂在情况
[root@client ~]# df -hT | grep glusterfs
node1:dis-volume        fuse.glusterfs   12G  188M   12G    2% /test/dis
node1:rep-volume        fuse.glusterfs  5.0G   84M  5.0G    2% /test/rep
node1:dis-rep           fuse.glusterfs  8.0G  147M  7.9G    2% /test/dis_and_rep

6.4、修改fstab配置文件

[root@client ~]# cat >> /etc/fstab << EOF
node1:dis-volume /test/dis/ glusterfs defaults,_netdev 0 0 
node1:rep-volume /test/rep/ glusterfs defaults,_netdev 0 0
node1:dis-rep /test/dis_and_rep glusterfs defaults,netdev 0 0 
EOF

# 执行mount -a检测fstab文件是否正确,如果没有任何回显代表fstab文件写入没有错误
[root@client ~]# mount -a

七、测试Gluster文件系统

  • 在分布式系统一切准备就绪后,就可以用来存储相关的业务数据了,但在使用之前,需要做一些基本的文件系统性能测试。比如下面所提到的,写入测试,破坏性测试等

7.1、卷中写入文件

# client节点操作
[root@client ~]# dd if=/dev/zero of=./demo1.log bs=43M count=1
[root@client ~]# dd if=/dev/zero of=./demo2.log bs=43M count=1
[root@client ~]# dd if=/dev/zero of=./demo3.log bs=43M count=1
[root@client ~]# dd if=/dev/zero of=./demo4.log bs=43M count=1
[root@client ~]# dd if=/dev/zero of=./demo5.log bs=43M count=1

# 复制数据到存储目录中
[root@client ~]# cp demo* /test/dis/
[root@client ~]# cp demo* /test/rep/
[root@client ~]# cp demo* /test/dis_and_rep/

7.2、查看文件分布

7.2.1、下面查看分布式文件分布
[root@node1 ~]# ll -h /e6
总用量 172M
## 没有分片,原始大小43M
-rw-r--r-- 2 root root 43M 516 10:14 demo1.log
-rw-r--r-- 2 root root 43M 516 10:14 demo2.log
-rw-r--r-- 2 root root 43M 516 10:14 demo3.log
-rw-r--r-- 2 root root 43M 516 10:14 demo4.log

[root@node2 ~]# ll -h /e6
## 没有分片,原始大小43M
总用量 43M
-rw-r--r-- 2 root root 43M 516 10:17 demo5.log

7.2.2、下面查看复制卷文件分布
[root@node3 ~]# ll -h /d5
总用量 215M
## 没有分片,原始大小43M
-rw-r--r-- 2 root root 43M 516 10:14 demo1.log
-rw-r--r-- 2 root root 43M 516 10:14 demo2.log
-rw-r--r-- 2 root root 43M 516 10:14 demo3.log
-rw-r--r-- 2 root root 43M 516 10:14 demo4.log
-rw-r--r-- 2 root root 43M 516 10:17 demo5.log

[root@node4 ~]# ll -h /d5
总用量 215M
## 没有分片,原始大小43M
-rw-r--r-- 2 root root 43M 516 10:14 demo1.log
-rw-r--r-- 2 root root 43M 516 10:14 demo2.log
-rw-r--r-- 2 root root 43M 516 10:14 demo3.log
-rw-r--r-- 2 root root 43M 516 10:14 demo4.log
-rw-r--r-- 2 root root 43M 516 10:17 demo5.log

7.2.3、下面查看分布式复制卷文件分布
[root@node1 ~]# ll -h /c4
总用量 172M
## 没有分片,原始大小43M
-rw-r--r-- 2 root root 43M 516 10:14 demo1.log
-rw-r--r-- 2 root root 43M 516 10:14 demo2.log
-rw-r--r-- 2 root root 43M 516 10:14 demo3.log
-rw-r--r-- 2 root root 43M 516 10:14 demo4.log

[root@node2 ~]# ll -h /c4
总用量 172M
## 没有分片,原始大小43M
-rw-r--r-- 2 root root 43M 516 10:14 demo1.log
-rw-r--r-- 2 root root 43M 516 10:14 demo2.log
-rw-r--r-- 2 root root 43M 516 10:14 demo3.log
-rw-r--r-- 2 root root 43M 516 10:14 demo4.log

[root@node3 ~]# ll -h /c4
总用量 43M
## 没有分片,原始大小43M
-rw-r--r-- 2 root root 43M 516 10:17 demo5.log

[root@node4 ~]# ll -h /c4
总用量 43M
## 没有分片,原始大小43M
-rw-r--r-- 2 root root 43M 516 10:17 demo5.log

7.3、破坏性测试

  • 挂起node2节点
7.3.1、测试分布式卷数据是否可以访问
# 访问数据没有回显表示访问成功
[root@client ~]# head -1 /test/dis/demo1.log
[root@client ~]# head -1 /test/dis/demo2.log
[root@client ~]# head -1 /test/dis/demo3.log
[root@client ~]# head -1 /test/dis/demo4.log
[root@client ~]# head -1 /test/dis/demo5.log
head: 无法打开"/test/dis/demo5.log" 读取数据: 没有那个文件或目录

## 分布在node2节点上的demo5.log无法访问,分布式卷不具备冗余性
7.3.2、测试分布式复制卷数据是否可以访问
# 访问数据没有回显表示访问成功
[root@client ~]# head -1 /test/dis_and_rep/demo1.log
[root@client ~]# head -1 /test/dis_and_rep/demo2.log
[root@client ~]# head -1 /test/dis_and_rep/demo3.log
[root@client ~]# head -1 /test/dis_and_rep/demo4.log
[root@client ~]# head -1 /test/dis_and_rep/demo5.log

## node2节点挂起后,数据不丢失
  • 继续挂起node4节点,在客户端上测试文件是否可以正常使用
7.3.3、测试复制卷数据是否可以访问
[root@client ~]# head -1 /test/rep/demo1.log
[root@client ~]# head -1 /test/rep/demo2.log
[root@client ~]# head -1 /test/rep/demo3.log
[root@client ~]# head -1 /test/rep/demo4.log
[root@client ~]# head -1 /test/rep/demo5.log

## node4节点节点挂起后,数据不会丢失

八、其他的GFS维护命令

  • 在完成以上所有节点操作后,需要根据生产环境需要,后续可能对其分布式文件系统各项参数的调整和配置,比如如下所提到的查看GlusterFS的命令,停止、删除卷及文件系统访问控制等等

8.1、查看GlusterFS的命令

# 查看卷的列表
[root@node1 ~]# gluster volume list
dis-rep
dis-volume
rep-volume


[root@node1 ~]# gluster volume info
 
Volume Name: dis-rep
Type: Distributed-Replicate
Volume ID: 943599b5-bd22-4bb7-93cf-72d3541eb48a
Status: Started
Snapshot Count: 0
Number of Bricks: 2 x 2 = 4
Transport-type: tcp
Bricks:
Brick1: node1:/c4
Brick2: node2:/c4
Brick3: node3:/c4
Brick4: node4:/c4
Options Reconfigured:
cluster.granular-entry-heal: on
storage.fips-mode-rchecksum: on
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off
## 部分内容省略


[root@node1 ~]# gluster volume status
Status of volume: dis-rep
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick node1:/c4                             49153     0          Y       8804 
Brick node3:/c4                             49153     0          Y       8665 
Self-heal Daemon on localhost               N/A       N/A        Y       8738 
Self-heal Daemon on node3                   N/A       N/A        Y       8619 
 
Task Status of Volume dis-rep
------------------------------------------------------------------------------
There are no active volume tasks
 
Status of volume: dis-volume
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick node1:/e6                             49152     0          Y       8668 
 
Task Status of Volume dis-volume
------------------------------------------------------------------------------
There are no active volume tasks
 
Status of volume: rep-volume
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick node3:/d5                             49152     0          Y       8602 
Self-heal Daemon on localhost               N/A       N/A        Y       8738 
Self-heal Daemon on node3                   N/A       N/A        Y       8619 
 
Task Status of Volume rep-volume
------------------------------------------------------------------------------
There are no active volume tasks

8.2、停止/删除卷

# 停止一个卷
[root@node1 ~]# gluster volume stop dis-volume
Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
volume stop: dis-volume: success

# 删除一个卷
[root@node1 ~]# gluster volume delete dis-volume
Deleting volume will erase all information about the volume. Do you want to continue? (y/n) y
volume delete: dis-volume: failed: Some of the peers are down

8.3、设置卷的访问控制

  • 下面设置只允许192.168.93.0/和192.168.10.0网段的客户端访问dis-rep卷
[root@node1 ~]# gluster volume set dis-rep auth.allow 192.168.93.*,192.168.10.*
volume set: success

  • 27
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值