2018年3月29日 11:02:33 关于docker分享之分布式存储 glusterfs
经典语录:
实际实验搭建:
前提 是要保证 一个 /data目录不和根分区在同一个磁盘! 1、centos7安装glusterfs
参考链接:https://wiki.centos.org/SpecialInterestGroup/Storage/gluster-Quickstart
#To Use the RPMs from Storage SIG, you need to install the centos-release-gluster RPM as it will provide the required YUM repository files. This RPM is available from CentOS Extras.
[root@docker1 ~]# ping docker2 #确保hostname可以通讯
PING dubbo2 (192.168.0.78) 56(84) bytes of data.
64 bytes from dubbo2 (192.168.0.78): icmp_seq=1 ttl=64 time=0.200 ms
64 bytes from dubbo2 (192.168.0.78): icmp_seq=2 ttl=64 time=0.167 ms
64 bytes from dubbo2 (192.168.0.78): icmp_seq=3 ttl=64 time=0.191 ms
^C
--- dubbo2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.167/0.186/0.200/0.013 ms
[root@docker1 ~]# gluster peer probe docker2
peer probe: success. #建立集群成功!
#验证检查 docker2和docker1建立集群成功!
[root@docker1 ~]# gluster peer status
Number of Peers: 1
Hostname: docker2
Uuid: e675b971-b503-4342-82ff-182858656282
State: Peer in Cluster (Connected)
[root@docker2 ~]# gluster peer status
Number of Peers: 1
Hostname: docker1
Uuid: 283ff245-7adf-4359-98c7-873cfcaa4a13
State: Peer in Cluster (Connected) 3、建立 GlusterFS volume
On both docker1 and docker2:
[root@docker1 ~]# mkdir -p /data/brick1/gv0
[root@docker2 ~]# mkdir -p /data/brick1/gv0 From any single server:
[root@docker1 ~]# gluster volume create gv0 replica 2 docker1:/data/brick1/gv0
Replica 2 volumes are prone to split-brain. Use Arbiter or Replica 3 to avoid this. See: http://docs.gluster.org/en/latest/Administrator%20Guide/Split%20brain%20and%20ways%20to%20deal%20with%20it/.
Do you still want to continue? #上述提示是2台集群有脑裂的风险,建议3台建群,有自动选举决策能力
(y/n) y
volume create: gv0: success: please start the volume to access data
[root@docker1 ~]# gluster volume start gv0
volume start: gv0: success
#查看一下
[root@docker1 ~]# gluster volume info
Volume Name: gv0
Type: Replicate
Volume ID: 47a40786-eb5e-4845-b324-6feb4557d428
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: docker1:/data/brick1/gv0
Brick2: docker2:/data/brick1/gv0
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off 4、客户端使用
存储服务器主要提供基本的数据存储功能,客户端弥补了没有元数据服务器的问题,承担了更多的功能,包括数据卷管理、I/O 调度、文件定位、数据缓存等功能,利用 FUSE(File system in User Space)模块(所以客户端使用需要安装glusterfs-fuse)将 GlusterFS 挂载到本地文件系统之上,实现 POSIX 兼容的方式来访问系统数据。
###For example to create a distributed volume with four storage servers using TCP.
gluster volume create test-volume server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4 Creation of test-volume has been successful Please start the volume to access data
别人的小结:基于 Hash 算法将文件分布到所有 brick server,只是扩大了磁盘空间,不具备容错能力。由于distribute volume 使用本地文件系统,因此存取效率并没有提高,相反会因为网络通信的原因使用效率有所降低,另外本地存储设备的容量有限制,因此支持超大型文件会有一定难度。
###For example, to create a replicated volume with two storage servers:
gluster volume create test-volume replica 2 transport tcp server1:/exp1 server2:/exp2
Creation of test-volume has been successful
Please start the volume to access data
别人的小结:文件同步复制到多个 brick 上,文件级 RAID1,具有容错能力,写性能下降,读性能提升。Replicated 模式,也称作 AFR(Auto File Replication),相当于 RAID1,即同一文件在多个镜像存储节点上保存多份,每个 replicated 子节点有着相同的目录结构和文件,replica volume 也是在容器存储中较为推崇的一种。
这个用法需要注意的地方就是 中间指定卷类型如果为n个副本,则后面必须接对应n个 节点地址;
假如你前面指定4个副本,后面接的2个pv地址,那么就是raid0+1了,即后面所谓的复合卷 distribute stripe volume.
假如你前面指定2个副本,后面接的4个节点地址,即下面所谓的基础卷 Distributed Replicated Glusterfs Volume.
###For example, four node distributed (replicated) volume with a two-way mirror:
gluster volume create test-volume replica 2 transport tcp server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4
Creation of test-volume has been successful Please start the volume to access data
别人的小结:Brick server 数量是条带数的倍数,兼具 distribute 和 stripe 卷的特点。分布式的条带卷,volume 中 brick 所包含的存储服务器数必须是 stripe 的倍数(>=2倍),兼顾分布式和条带式的功能。每个文件分布在四台共享服务器上,通常用于大文件访问处理,最少需要 4 台服务器才能创建分布条带卷。
###For example, to create a striped volume across two storage servers:
gluster volume create test-volume stripe 2 transport tcp server1:/exp1 server2:/exp2
Creation of test-volume has been successful
Please start the volume to access data
别人的小结:类似 RAID0,文件分成数据块以 Round Robin 方式分布到 brick server 上,并发粒度是数据块,支持超大文件,大文件的读写性能高。
GlusterFS 客户端常用命令: (创建信任集群后,在任意一个节点执行下面命令,集群全部配置生效,这句话或许说的不够准确呢!)
命令 功能
gluster peer probe 添加节点
gluster peer detach 移除节点
gluster volume create 创建卷
gluster volume start 启动卷
gluster volume stop 停止卷
gluster volume delete 删除卷
其实上面说了这么多,也就是打个基础和铺垫,对于今天的标题来说,这才是重点!!!
基于docker的持久化,如果要使用到glusterfs必须安装别人写的第三方插件,(我觉得主要是docker懒,没有出系统化的持久化方案,或许未来更新迭代应该也不会有了,因为有k8s了,哈哈哈!)
摘抄如下:接下来,我们再来看GlusterFS如何作为Docker的存储。Docker Volume是一种可以将容器以及容器生产的数据分享开来的数据格式,我们可以使用宿主机的本地存储作为Volume的提供方,也可以使用Volume Plugin接入许多第三方的存储。 GitHub就有一个Docker GlusterFS Volume Plugin,方便我们将GlusterFS挂载到容器中。
原文:https://www.ibm.com/developerworks/cn/opensource/os-cn-glusterfs-docker-volume/index.html (也就是上面的中文拓展网址)
基于k8s编排工具的持久化,k8s是原生就支持glusterfs的存储驱动的,当然k8s还支持别的很多种存储驱动,今天就讲讲它算了。
安装好k8s后,直接部署下面几个文件即可!