搭建Gluster集群(Debian 8)

环境信息

三台虚拟机节点(192.168.100.171<debian171>, 192.168.100.172<debian172>, 192.168.100.173<debian173>)

Debian jessie 8.5 

Gluster 3.5.2

安装Gluster集群

#apt安装

sudo apt-get -y install glusterfs-server

#格式化并挂载bricks(跳过)

mkfs.xfs -i size=512 /dev/sdb1
mkdir -p /data/brick1
echo '/dev/sdb1 /data/brick1 xfs defaults 1 2' >> /etc/fstab
mount -a && mount

由于当前节点环境只有sda,该步骤跳过,如需要可自行尝试

#配置trusted pool

debian171:

surfin@debian171:/var/lib$ sudo gluster peer probe debian172
peer probe: success. 
surfin@debian171:/var/lib$ sudo gluster peer probe debian173
peer probe: success. 

debian172:

surfin@debian172:~$ sudo gluster peer probe debian171
peer probe: success. 
surfin@debian172:~$ sudo gluster peer probe debian173
peer probe: success. Host debian173 port 24007 already in peer list

debian173:

surfin@debian173:~$ sudo gluster peer probe debian171
peer probe: success. Host debian171 port 24007 already in peer list
surfin@debian173:~$ sudo gluster peer probe debian172
peer probe: success. Host debian172 port 24007 already in peer list

#设置GlusterFS volume

sudo mkdir -p /var/lib/gluster/data/brick1/gv0
surfin@debian171:/var/lib$ sudo gluster volume create gv0 replica 3 debian171:/var/lib/gluster/data/brick1/gv0 debian172:/var/lib/gluster/data/brick1/gv0 debian173:/var/lib/gluster/data/brick1/gv0
volume create: gv0: failed: The brick debian171:/var/lib/gluster/data/brick1/gv0 is is being created in the root partition. It is recommended that you don't use the system's root partition for storage backend. Or use 'force' at the end of the command if you want to override this behavior.

在这里提示不能创建volume在根目录上,需要在命令结尾添加force指令

surfin@debian171:/var/lib$ sudo gluster volume create gv0 replica 3 debian171:/var/lib/gluster/data/brick1/gv0 debian172:/var/lib/gluster/data/brick1/gv0 debian173:/var/lib/gluster/data/brick1/gv0 force
volume create: gv0: success: please start the volume to access data

启动Gluster并查看volume信息

surfin@debian171:/var/lib$ sudo gluster volume start gv0
volume start: gv0: success
surfin@debian171:/var/lib$ sudo gluster volume info
 
Volume Name: gv0
Type: Replicate
Volume ID: 60cd8336-b94f-4f99-98ab-1106f85ffca4
Status: Started
Number of Bricks: 1 x 3 = 3
Transport-type: tcp
Bricks:
Brick1: debian171:/var/lib/gluster/data/brick1/gv0
Brick2: debian172:/var/lib/gluster/data/brick1/gv0
Brick3: debian173:/var/lib/gluster/data/brick1/gv0

#测试Gluster

client 服务器需要安装glusterfs-client,这里我们直接用debian173做client测试

surfin@debian173:/mnt$ sudo mkdir -p /mnt/gv0-cli
surfin@debian173:/mnt$ cd /mnt/gv0-cli
surfin@debian173:/mnt/gv0-cli$ sudo cp /home/surfin/package/* .
surfin@debian173:/mnt/gv0-cli$ ll
total 210102
-rw-r--r-- 1 root root 181389058 Jul  6 16:41 jdk-8u92-linux-x64.tar.gz
-rw-r--r-- 1 root root  11492794 Jul  6 16:41 Mycat-server-1.5.1-RELEASE-20160622153300-linux.tar.gz
-rw-r--r-- 1 root root  22261552 Jul  6 16:41 zookeeper-3.4.8.tar.gz

查看debian172上的gv0目录

surfin@debian172:/var/lib/gluster/data/brick1/gv0$ ll
total 210116
-rw-r--r-- 2 root root 181389058 Jul  6 16:41 jdk-8u92-linux-x64.tar.gz
-rw-r--r-- 2 root root  11492794 Jul  6 16:41 Mycat-server-1.5.1-RELEASE-20160622153300-linux.tar.gz
-rw-r--r-- 2 root root  22261552 Jul  6 16:41 zookeeper-3.4.8.tar.gz

删除debian173上的文件

surfin@debian173:/mnt/gv0-cli$ sudo rm -rf *
surfin@debian173:/mnt/gv0-cli$ ll
total 0
surfin@debian172:/var/lib/gluster/data/brick1/gv0$ ll
total 0

debian172上的文件删除了,ok!

#client添加自动挂载

sudo vi /etc/fstab

 在文件最后添加下面内容,注意中间分隔不能为tab键,否则无法挂载

debian171:/gv0  /mnt/gv0-cli    glusterfs   defaults,_netdev 0 0

#结合keepalived

参见“搭建keepalived+haproxy+mariadb高可用负载均衡数据库集群”

修改/etc/hosts,添加vip的hostname

192.168.100.170	debian170.surfin.org	debian170

修改/etc/fstab,将debian171改为debian170

debian170:/gv0  /mnt/gv0-cli    glusterfs   defaults,_netdev 0 0

Well done!

参考资料:

http://gluster.readthedocs.io/en/latest/Quick-Start-Guide/Quickstart/

http://www.gluster.org/community/documentation/index.php/Gluster_3.1:_Automatically_Mounting_Volumes

转载于:https://my.oschina.net/norxiva/blog/707205

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值