CentOS7下分布式系统GlusterFS安装配置

一、主机规划

操作系统版本为:CentOS 7.2.1511

1node1:172.17.0.1 gfs1
2node2:172.17.0.2 gfs2
3node3:172.17.0.3 gfs3
4node4:172.17.0.4 gfs
5client:172.17.0.5 

二、安装

1.在node1-4上安装glusterfs-server

1yum install -y centos-release-gluster38
2yum install -y glusterfs glusterfs-server glusterfs-fuse

设置开机自启动并启动

1systemctl enable glusterd.service
2systemctl start glusterd.service

2.在gfs1-gfs4节点上配置整个GlusterFS集群,把各个节点加入到集群

修改hosts文件

1vim /etc/hosts
2127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
3::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
4172.17.0.1  gfs1
5172.17.0.2  gfs2
6172.17.0.3  gfs3
7172.17.0.4  gfs4

把节点加入到集群中

1[root@gfs1 ~]# gluster peer probe gfs1
2[root@gfs1 ~]# gluster peer probe gfs2
3[root@gfs1 ~]# gluster peer probe gfs3
4[root@gfs1 ~]# gluster peer probe gfs4

3.查看节点状态

1[root@gfs1 ~]#gluster peer status

4.在gfs{1-4}上创建数据存储目录

1mkdir -p  /usr/local/share/models

5.在gfs1上创建GlusterFS磁盘

注意: 加上replica 4就是4个节点中,每个节点都要把数据存储一次,就是一个数据存储4份,每个节点一份 如果不加replica 4,就是4个节点的磁盘空间整合成一个硬盘,

1[root@gfs1 ~]#gluster volume create models replica 4 gfs1:/usr/local/share/models gfs2:/usr/local/share/models gfs3:/usr/local/share/models gfs4:/usr/local/share/models force

6.启动

1[root@gfs1 ~]# gluster volume start models

客户端

1.部署GlusterFS客户端并mount GlusterFS文件系统

1[root@client ~]# yum install -y centos-release-gluster38
2[root@client ~]# yum install -y glusterfs glusterfs-fuse
3[root@client ~]# mkdir -p /mnt/models
4[root@client ~]# mount -t glusterfs -o ro gfs1:models /mnt/models/

2.查看效果

1[root@client ~]# df -h

3.观察分布式文件系统的效果

 1umount /mnt/models
 2mount -t glusterfs -o rw gfs1:models /mnt/models/
 3[root@client ~]# cd /mnt/models/
 4[root@client mnt]# for i in `seq -w 10`; do mkdir $i ; done
 5[root@client models]# for i in `seq -w 10`; do mkdir $i ; done
 6[root@client models]# ll
 7total 40
 8drwxr-xr-x 2 root root 4096 Feb 14 21:56 01
 9drwxr-xr-x 2 root root 4096 Feb 14 21:59 02
10drwxr-xr-x 2 root root 4096 Feb 14 21:56 03
11drwxr-xr-x 2 root root 4096 Feb 14 21:56 04
12drwxr-xr-x 2 root root 4096 Feb 14 21:56 05
13drwxr-xr-x 2 root root 4096 Feb 14 21:56 06
14drwxr-xr-x 2 root root 4096 Feb 14 21:59 07
15drwxr-xr-x 2 root root 4096 Feb 14 21:56 08
16drwxr-xr-x 2 root root 4096 Feb 14 21:56 09
17drwxr-xr-x 2 root root 4096 Feb 14 21:59 10

分别在4台Server上查看新建的文件夹同步情况

 1[root@gfs1 ~]# ls /usr/local/share/models/ -l
 2total 0
 3drwxr-xr-x 2 root root 6 Feb 14 21:56 01
 4drwxr-xr-x 2 root root 6 Feb 14 21:59 02
 5drwxr-xr-x 2 root root 6 Feb 14 21:56 03
 6drwxr-xr-x 2 root root 6 Feb 14 21:56 04
 7drwxr-xr-x 2 root root 6 Feb 14 21:56 05
 8drwxr-xr-x 2 root root 6 Feb 14 21:56 06
 9drwxr-xr-x 2 root root 6 Feb 14 21:59 07
10drwxr-xr-x 2 root root 6 Feb 14 21:56 08
11drwxr-xr-x 2 root root 6 Feb 14 21:56 09
12drwxr-xr-x 2 root root 6 Feb 14 21:59 10

可以看到4台服务器都同步过来了。 当单台Server出现故障,比如服务器断开连接的情况,创建一个文件需要比较长的时间。 但是当Server重新连上之后,文件可以及时的同步过来。