Glusterfs的peer/volume/brick

时间:2022-06-25
本文章向大家介绍Glusterfs的peer/volume/brick,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

由于做云存储,使用到glusterfs,简单的记录下。

1、Peer

    查看peer的情况,当前的glusterfs集群中,有当前节点和11、12三个节点组成。

List-1

[root@master1 /]# gluster peer status
Number of Peers: 2

Hostname: 192.168.33.11
Uuid: 8c22b08f-7232-4ac9-b5d8-8262db2d4ee7
State: Peer in Cluster (Connected)

Hostname: 192.168.33.12
Uuid: 7906f9a9-c58b-4c6e-93af-f4d9960b6220
State: Peer in Cluster (Connected)

    也可以用peer list来查看,如下List-2

List-2

[root@master1 /]# gluster pool list
UUID					Hostname     	State
8c22b08f-7232-4ac9-b5d8-8262db2d4ee7	192.168.33.11	Connected 
7906f9a9-c58b-4c6e-93af-f4d9960b6220	192.168.33.12	Connected 
a2d23b65-381e-45ea-a488-e9fee45e5928	localhost    	Connected

    加入工作节点,如下List-3,将13这个工作节点加入进来,可以使用hostname,也可以使用IP地址。

List-3

[root@master1 /]# gluster peer probe -h
-h is an invalid address

Usage:
peer probe { <HOSTNAME> | <IP-address> }
[root@master1 /]# gluster peer probe 192.168.33.13

    取消工作节点,如下List-4所示,使用detach命令来取消,执行之后,再使用peer status来查看,就会看到效果了。

List-4

gluster peer detach HOSTNAME
gluster peer detach 192.168.33.13

2、卷Volume

    创建卷,如下List-5所示,10/11/12上的/data_gluster目录必须存在,不然会报错目录不存在,如果有警告之类的信息,可以加上force。要注意的是不加replica则,集群中只会保留一份,不会复制到其它节点上。

List-5

gluster volume create hive_db_volume replica 3 192.168.33.10:/data_gluster/hive_db_volume 
    192.168.33.11:/data_gluster/hive_db_volume 192.168.33.12:/data_gluster/hive_db_volume
#加上force
gluster volume create hive_db_volume replica 3 192.168.33.10:/data_gluster/hive_db_volume 
    192.168.33.11:/data_gluster/hive_db_volume 192.168.33.12:/data_gluster/hive_db_volume force

    启用数据卷,用volume start启动卷,如下List-6,因为我已经启动那个卷了,所以提示卷已经启动。

List-6

[root@master1 /]# gluster volume start hive_db_volume
volume start: hive_db_volume: failed: Volume hive_db_volume already started
#查看卷的信息
[root@master1 /]# gluster volume info hive_db_volume
 
Volume Name: hive_db_volume
Type: Replicate
Volume ID: b34d2970-27b9-421a-8680-c242b38946e5
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 3 = 3
Transport-type: tcp
Bricks:
Brick1: 192.168.33.10:/data_gluster/hive_db_volume
Brick2: 192.168.33.11:/data_gluster/hive_db_volume
Brick3: 192.168.33.12:/data_gluster/hive_db_volume
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off

    之后要先挂载才能使用,不能直接操作/data_gluster/hive_db_volume,如下List-7,挂载之后,在10这台机器的/mnt/gluster/hive_db下,我们就可以存储数据了,注意是我们手动写数据是到/mnt/gluster/hive_db,glusterfs会自动同步到/data_gluster/hive_db_volume下,不能直接操作/data_gluster/hive_db_volume这个目录,更不要手动删除/data_gluster/hive_db_volume里面的数据。

List-7

#在/mnt下创建目录用于挂载
mkdir -p /mnt/gluster/hive_db
#如下命令进行挂载,hive_db_volume是我们之前创建的卷
mount -t glusterfs 192.168.33.10:/hive_db_volume /mnt/gluster/hive_db

    在10这台机器的/mnt/gluster/hive_db下操作文件,看其它机器上的情况,如下List-8,创建文件hello,写入"hello world",之后进入/data_gluster/hive_db_volume——因为List-5我们指定了路径是/data_gluster/hive_db_volume,看到的就是我们刚才创建的那个文件。我们去看11和12上的/data_gluster/hive_db_volume。

    我们只能在10这台机器的/mnt/gluster/hive_db下操作才有效,在11/12的这个目录下操作,没有作用,因为List-7中挂载到10这台上了。

List-8

[root@master1 hive_db]# pwd
/mnt/gluster/hive_db
[root@master1 hive_db]# more hello 
hello world
#之后进入/data_gluster/hive_db_volume查看,如下
[root@master1 hive_db_volume]# pwd
/data_gluster/hive_db_volume
[root@master1 hive_db_volume]# more hello 
hello world

#在11上查看
[root@node1 hive_db_volume]# pwd
/data_gluster/hive_db_volume
[root@node1 hive_db_volume]# more hello 
hello world

#在12上查看也是一样的

3、Brick

    删除brick,如下List-9,

  1. 使用volume remove-brick 卷名称
  2. replica  2参数,开始我们创建卷时复制数是3,现在变为2。 
  3. 最后的那个192.168.33.12:/data_gluster/hive_db_volume参数,表示192.168.33.12:/data_gluster/hive_db_volume将不存储卷hive_db_volume的数据

List-9

[root@master1 /]# gluster volume remove-brick hive_db_volume replica 2 192.168.33.12:/data_gluster/hive_db_volume  force
Remove-brick force will not migrate files from the removed bricks, so they will no longer be available on the volume.
Do you want to continue? (y/n) y
volume remove-brick commit force: success

    List-9的操作之后,再查看该volume的详情,如下List-10,发现对比List-6,少了一个brick,这样大致应该了解brick是什么了,大体可以理解为卷的数据存储在这三个brick中,glusterfs自动帮我们保持各个brick的同步,我们也可以删除brick,这样存储数据的brick个数就减少了。

List-10

[root@master1 hive_db_volume]# gluster volume info hive_db_volume
 
Volume Name: hive_db_volume
Type: Replicate
Volume ID: b34d2970-27b9-421a-8680-c242b38946e5
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: 192.168.33.10:/data_gluster/hive_db_volume
Brick2: 192.168.33.11:/data_gluster/hive_db_volume
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off

    增加brick,之前删除brick之后,还可以增加上去,如下List-11所示,使用add-brick增加卷,之后再查看卷信息,发现对比List-10,brick多了个,即多了192.168.33.12:/data_gluster/hive_db_volume这个brick。

List-11

[root@master1 /]# gluster volume add-brick hive_db_volume replica 3 192.168.33.12:/data_gluster/hive_db_volume force
volume add-brick: success
[root@master1 /]# gluster volume info hive_db_volume
 
Volume Name: hive_db_volume
Type: Replicate
Volume ID: b34d2970-27b9-421a-8680-c242b38946e5
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 3 = 3
Transport-type: tcp
Bricks:
Brick1: 192.168.33.10:/data_gluster/hive_db_volume
Brick2: 192.168.33.11:/data_gluster/hive_db_volume
Brick3: 192.168.33.12:/data_gluster/hive_db_volume
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off

    还可以替换brick,用replace-brick命令,如下List-12

  1. 卷hive_db_volume是已经存在的
  2. 192.168.33.12:/data_gluster/hive_db_volume这个brick被替换为192.168.33.12:/data_gluster/hive_db_volume2,这个例子中是同一台机器上的不同目录,也可以替换为另一台机器

List-12

gluster volume replace-brick hive_db_volume 192.168.33.12:/data_gluster/hive_db_volume 192.168.33.12:/data_gluster/hive_db_volume2 commit force

    卷启动之后才可以使用,我们可以停止卷,使用stop,如下List-13,停止之后不能使用了。

List-13

[root@master1 hive_db_volume]# gluster volume stop hive_b_volume

    删除卷,使用delete命令删除卷

List-14

[root@master1 hive_db_volume]# gluster volume delete hive_b_volume