因为作云存储,使用到glusterfs,简单的记录下。java
查看peer的状况,当前的glusterfs集群中,有当前节点和十一、12三个节点组成。node
List-1bash
[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-2tcp
List-2ui
[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地址。spa
List-3code
[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来查看,就会看到效果了。orm
List-4rem
gluster peer detach HOSTNAME gluster peer detach 192.168.33.13
建立卷,以下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上查看也是同样的
删除brick,以下List-9,
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
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