glusterfs --云存储

云存储
分布式存储
分布式文件系统
glusterfs
GlusterFS is a scalable network filesystem. Using common off-the-shelf hardware, you can create large, distributed storage solutions for media streaming, data analysis, and other data- and bandwidth-intensive tasks. GlusterFS is free and open source software.
vm1.cluster.com(模拟客户端)
172.16.2.10
vm2.cluster.com vm3.cluster.com vm4.cluster.com vm5.cluster.com
172.16.2.11 172.16.2.12 172.16.2.13 172.16.2.14
分别模拟分布式存储服务器1,2,3,4
第一步:实验前准备,五台虚拟机(centos7.3平台)
1,配置主机名,并且互相全部主机名绑定
# hostnamectl set-hostname --static vm1.cluster.com
# vim /etc/hosts
172.16.2.10 vm1.cluster.com client
172.16.2.11 vm2.cluster.com storage1
172.16.2.12 vm3.cluster.com storage2
172.16.2.13 vm4.cluster.com storage3
172.16.2.14 vm5.cluster.com storage4
2,ip静态
3,关闭iptables,selinux
4,时间同步
5,配置yum (本地镜像yum源仓库和下面的glusterfs源仓库)
方法一:
我这里把相关软件包共享在笔记目录/arch/glusterfs_soft/
你可以拷贝过去做本地yum源
如果你不想拷过去,那么直接配置下面的yum配置文件(这里是我宿主机的http共享)
# vim /etc/yum.repos.d/glusterfs.repo
[glusterfs]
name=glusterfs
enabled=1
gpgcheck=0
方法二:
去下面的路径找你需要的对应版本,然后配置公网yum源路径就可以了
第二步:
在所有存储服务器上(不包括客户端)安装glusterfs-server包并启动服务
# yum install glusterfs-server
# systemctl start glusterd
# systemctl status glusterd
# systemctl enable glusterd
第三步:
让所有存储集群节点做成trusted pool(也就是建立连接)
只需要在其中一个存储节点上分别probe(建立连接)其它所有节点每人一次就可以了(不用排列组合的两两probe)
下面我就在storage1上操作
# gluster peer probe storage2
# gluster peer probe storage3
# gluster peer probe storage4 --这里使用ip,主机名,主机名别名都可以
然后在所有存储上都可以使用下面命令来验证检查
# gluster peer status
--注意:如果第三步建立连接有问题(一般问题会出现在相互之间的网络连接,iptables,selinux,主机名绑定等);如果想重做这一步,可以使用gluster peer detach xxxxx [force] 来断开连接,重新做第三步
第四步:
在所有存储节点上,建立用于集群的存储目录(可以用单独的分区,也可以使用根分区)
# mkdir -p /data/gv0   --此目录不属性单独的分区,默认属于根分区
第五步:
创建gluster volume取名叫gv0
replicate模式
在其中任一存储节点使用下面的命令创建glusterfs volume(其它存储节点不用重复执行)
# gluster volume create gv0 replica 4 storage1:/data/gv0/ storage2:/data/gv0/ storage3:/data/gv0/ storage4:/data/gv0/
volume create: gv0: failed: The brick storage1:/data/gv0 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
--replica 4后面的数字与你的节点数有关(replica是类似raid1的模式,我们先讨论这种模式)
--报错信息提示:建议使用非根分区来创建volume,但我们这里为了方便,并没有多加硬盘来挂载,默认使用的是根分区,所以多加一个force参数就可以了
# gluster volume create gv0 replica 4 storage1:/data/gv0/ storage2:/data/gv0/ storage3:/data/gv0/ storage4:/data/gv0/ force --加了force参数,成功
volume create: gv0: success: please start the volume to access data
所有存储节点都可以使用下面命令查看gv0的信息
# gluster volume info gv0
Volume Name: gv0
Type: Replicate --模式为replicate模式
Volume ID: 328d3d55-4506-4c45-a38f-f8748bdf1da6
Status: Created --这里状态为created,表示刚创建,还未启动,需要启动才能使用
Snapshot Count: 0
Number of Bricks: 1 x 4 = 4
Transport-type: tcp
Bricks:
Brick1: storage1:/data/gv0
Brick2: storage2:/data/gv0
Brick3: storage3:/data/gv0
Brick4: storage4:/data/gv0
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
第六步:
在其中任一存储节点使用下面的命令启动gv0(其它存储节点不用重复执行)
# gluster volume start gv0
所有存储节点都可以使用下面命令查看gv0的信息
# gluster volume info gv0
Volume Name: gv0
Type: Replicate
Volume ID: 328d3d55-4506-4c45-a38f-f8748bdf1da6
Status: Started --现在看到状态变为started,那么就表示可以被客户端挂载使用了
Snapshot Count: 0
Number of Bricks: 1 x 4 = 4
Transport-type: tcp
Bricks:
Brick1: storage1:/data/gv0
Brick2: storage2:/data/gv0
Brick3: storage3:/data/gv0
Brick4: storage4:/data/gv0
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
第七步:
在客户端上安装gluster客户端软件
# yum install glusterfs glusterfs-fuse
第八步:
客户端挂载测试
--注意:客户端也需要在/etc/hosts文件里绑定存储节点的主机名,才可以挂载(因为我前面做的步骤是用名字的)
# mkdir /test{1,2,3,4} --建立四个测试挂载目录(相当于一个客户端模拟四个客户端)
# mount -t glusterfs storage1:/gv0 /test1
# mount -t glusterfs storage2:/gv0 /test2
# mount -t glusterfs storage3:/gv0 /test3
# mount -t glusterfs storage4:/gv0 /test4
读写测试结果是:类似raid1和lvm的镜像卷,写的东西在所有存储节点上都会产生一份(replica模式)
第九步:
上面测试完后,如果要删除gv0这个volumn,做法如下:
先在客户端umount已经挂载的目录
# rm /test1/* -rf --在umount之前把测试的数据干掉
# umount /test1
# umount /test2
# umount /test3
# umount /test4
在其中任一存储节点使用下面的命令停止gv0(其它存储节点不用重复执行)
# gluster volume stop gv0
Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
volume stop: gv0: success
在其中任一存储节点使用下面的命令删除gv0(其它存储节点不用重复执行)
# gluster volume delete gv0
Deleting volume will erase all information about the volume. Do you want to continue? (y/n) y
volume delete: gv0: success
在所有存储节点上都可以查看,没有gv0的信息了,说明这个volumn被删除了
# gluster volume info
Volume gv0 does not exist
第十步:
再重做成stripe模式(类似raid0和lvm的条带卷)的卷
# gluster volume create gv0 stripe 4 storage1:/data/gv0/ storage2:/data/gv0/ storage3:/data/gv0/ storage4:/data/gv0/ force
volume create: gv0: success: please start the volume to access data
# gluster volume start gv0
第十一步:
客户端再次挂载进行读写测试
# mount -t glusterfs storage1:/gv0 /test1
# mount -t glusterfs storage2:/gv0 /test2
# mount -t glusterfs storage3:/gv0 /test3
# mount -t glusterfs storage4:/gv0 /test4
测试结果比较:
replica模式 类似raid1,客户端挂载看到的大小为所有存储中最小存储的大小,客户端写1G,服务器会占4G,每个存储占1G
stripe模式 类似raid0,客户端挂载看到的大小为所有存储中大小的总和,客户端写1G,服务器会占1G,每个存储占1/4G
==============================================
补充一:
模式Distributed
另一种模式Distributed(默认)的做法,按照上面一样的方法把gv0给删除,再创建启动,创建命令为
# gluster volume create gv0 storage1:/data/gv0/ storage2:/data/gv0/ storage3:/data/gv0/ storage4:/data/gv0/ force --不指定replica或stripe,就默认是Distributed的模式
测试结果:
distributed模式 类似lvm的线性卷,先只占storage1空间,满了才会占storage2空间,再占storage3......以此类推
除了这三种模式外,还有Distributed Striped,Distributed Replicated ,Distributed Striped Replicated,Striped Replicated,Dispersed,Distributed Dispersed等各种模式
参考官方文件路径为:
distributed-stripe模式(下面命令4个存储,但stripe写的是2,也就是2个一个小组进行stripe,写满第一个小组,再写第二个小组,继续stripe)
#gluster volume create gv0 stripe 2 storage1:/data/gv0/ storage2:/data/gv0/ storage3:/data/gv0/ storage4:/data/gv0/ force
补充二:
在线裁减(还要看是哪一种模式,比如:stripe模式就不允许在线裁减):
# gluster volume remove-brick gv0 storage4:/data/gv0 force
Removing brick(s) can result in data loss. Do you want to Continue? (y/n) y
volume remove-brick commit force: success
在线扩容:
# gluster volume add-brick gv0 storage4:/data/gv0 force
volume add-brick: success
posted @ 2018-06-19 22:18  Sky-wings  阅读(277)  评论(0编辑  收藏  举报