概述:GlusterFS(Google File System)是一个开源的分布式文件系统,Gluster借助TCP/IP网络将存储资源分散存储在网络的不同节点,在通过汇聚为客户端提供统一的资源访问,在存储方面具有很强大的横向扩展能力,通过扩展不同的节点可以支持PB级别的存储容量;Bit、Byte、KB、MB、GB、TB、PB、EB、ZB、YB、DB、NB扩展性与高性能:通过Scale-out架构可以增加存储节点的方式来提高容量和性能(磁盘、计算、I/O资源都可以独立增加),Gluster弹性哈希(Elastic Hash)解决了Gluster服务对元数据服务器的依赖,Gluster采用弹性哈希算法来确定数据在chunk节点中的分布情况,无须元数据服务器,实现了存储的横向扩展,改善了元数据服务器节点的压力以及单点故障;高可用性:GlusterFS通过配置不同类型的卷,可以对数据进行自动复制(类似于RAID1),即使某节点故障,也不影响数据的访问;通用性:GlusterFS没有设置独立的私有数据文件系统,而是采用以往的ext4、ext3等,数据可以通过传统的磁盘访问方式被客户端所访问;弹性卷管理:GlusterFS通过将数据存储在逻辑卷上,逻辑卷从逻辑存储池进行独立逻辑划分,逻辑存储池可以在线进行增加和删除,不会导致业务中断,逻辑卷的数量可以根据实际需求进行自行增加和缩减;Brick(存储块):存储池中节点对外提供存储服务的目录;Volume(逻辑卷):一个逻辑卷时一组Brick的集合,卷是数据存储的逻辑设备,类似LVM中的逻辑卷,大部分GlusterFS管理操作都是在逻辑卷上进行的;FUSE(用户空间文件系统):是一个内核模块,用户自行创建挂载的的文件系统;VFS(接口):内核空间对用户空间提供的访问磁盘的接口;Glusterd(后台管理进程):在存储集群中的每个节点上都要运行;1. 首先是在客户端,用户通过glusterfs的mount point 来读写数据, 对于用户来说, 集群系统的存在对用户是完全透明的, 用户感觉不到是操作本地系统还是远端的集群系统。 2. 用户的这个操作被递交给 本地linux系统的VFS来处理。 3. VFS 将数据递交给FUSE 内核文件系统:在启动 glusterfs 客户端以前, 需要想系统注册一个实际的文件系统FUSE,如上图所示,该文件系统与ext3在同一个层次上面,ext3 是对实际的磁盘进行处理,而 fuse 文件系统则是将数据通过/dev/fuse 这个设备文件递交给了glusterfs client端。所以我们可以将 fuse 文件系统理解为一个代理。 4. 数据被 fuse 递交给 Glusterfs client 后,client 对数据进行一些指定的处理(所谓的指定,是按照client 配置文件据来进行的一系列处理, 我们在启动glusterfs client 时 需 要 指 定 这 个 文 件 , 其 默 认 位 置 :/etc/glusterfs/client.vol)。 5. 在glusterfs client的处理末端,通过网络将数据递交给 Glusterfs Server,并且将数据写入到服务器所控制的存储设备上。分布式卷、条带卷、复制卷、分布式条带卷、分布式复制卷、条带复制卷、分布式条带复制卷;分布式卷是GlusterFS的默认卷,在创建卷时,默认选项是创建分布式卷。在该模式下,并没有对文件进行分块处理,文件直接存储在某个Server节点上。由于使用本地文件系统,所以存取效率并没有提高,反而会因为网络通信的原因而有所降低,另外支持超大型文件也会有一定的难度,因为分布式卷不会对文件进行分块处理,一个文件要么在Server1上,要么在Serve2上,不能分块同时存放在Sever1和Server2上;[root@gfs ~]# gluster volume create dis-volume server1:/dir1 server2:/dir2Creation of dis -volume has been successfulPlease start the volume to access dataStripe模式相当于RAIDO,在该模式下,根据偏移量将文件分成N块,轮询地存储在每个Brick Server节点。节点把每个数据块都作为普通文件存入本地文件系统中,通过扩展属性记录总块数(Stripe-count) 和每块的序号(Stripe-index),在配置时指定的条带数必须等于卷中Brick所包含的存储服务器数,在存储大文件时,性能尤为突出,但是不具备冗余性;[root@gfs ~]# gluster volume create stripe-volume stripe 2 transport tcp server1:/dir1 server2:/dir2create of Stripe -volume has been successfulplease start the volume to access data也称为AFR(AutGilePepliatio)相当于RAD1,即同一文件保存一份或多份副本。每个节点上保存相同的内容和目录结构。复制模式因为要保存副本,所以磁盘利用率较低,复制卷时,复制数必须等于卷中Brick所包含的存储服务器数,复制卷具备冗余性,即使一个节点损坏,也不影响数据的正常使用;[root@gfs ~]# gluster volume create rep-volume replica 2 transport tcp server1:/dir1 server2:/dir2create of rep -volume has been successfulplease start the volume to access data4.分布式条带卷 分布式条带卷兼顾分布式卷和条带卷的功能,可以理解成为大型的条带卷,主要用于大文件访问处理,创建一个分布式条带,卷最少需要4台服务器;[root@gfs ~]# gluster volume create dis-stripe stripe 2 transport tcp server1:/dir1 server2:/dir2 server3:/dir3 server4:/dir4create of dis-stripe has been successfulplease start the volume to access data上述命令创建了一个名为dis-stripe的分布式条带卷,配置分布式条带卷时,卷中Brick所包含的存储服务器必须是条带数的倍数(大于等于2倍),如上述命令,Brick的数量为4,条带数为2;分布式复制卷兼顾分布式卷和复制卷的功能,可以理解成为大型的复制卷,主要用于冗余的场景下,创建一个分布式复制卷,最少需要4块brick;[root@gfs ~]# gluster volume create dis-rep replica 2 transport tcp server1:/dir1 server2:/dir2 server3:/dir3 server4:/dir4create of dis-rep has been successfulplease start the volume to access data条带复制卷兼顾了条带卷和复制卷两者的优点,相当于RADI 10,用于存储效率高,备份冗余的场景下,创建条带复制卷,最少需要四个brick;[root@gfs ~]# gluster volume create test-volume stripe 2 replica 2 transport tcp server1:/dir1 server2:/dir2 server3:/dir3 server4:/dir4create of test-volume has been successfulplease start the volume to access data分布式条带复制卷将分布条带数据在复制卷集群。为了获得最佳效果,可以选择使用分布在高并发的条带复制卷环境下并行访问非常大的文件和性能是至关重要的; | | | | | | | glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma | | | | glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma | | | | glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma | | | | | Ø配置主机之间的解析(在此所有主机配置相同,在此只列举data1节点的配置);Ø在所有data节点上安装GlusterFS(在此所有主机配置相同,在此只列举data1节点的配置);Ø在data1节点上进行创建集群,其他节点会同步配置;Ø在data1节点创建数据存储的卷(复制卷),其他节点会同步配置;Ø在client客户端节点上安装gluster客户端工具并测试挂载;Ø配置主机之间的解析(在此所有主机配置相同,在此只列举data1节点的配置);[root@data1 ~]# cat <>/etc/hosts192.168.100.101 data1.linuxfan.cn192.168.100.102 data2.linuxfan.cn192.168.100.103 data3.linuxfan.cn192.168.100.104 client.linuxafn.cn[root@data1 ~]# ping data1.linuxfan.cn -c 2 ##ping命令进行测试PING data1.linuxfan.cn (192.168.100.101) 56(84) bytes of data.64 bytes from data1.linuxfan.cn (192.168.100.101): icmp_seq=1 ttl=64 time=0.062 ms64 bytes from data1.linuxfan.cn (192.168.100.101): icmp_seq=2 ttl=64 time=0.040 msØ在所有data节点上安装GlusterFS(在此所有主机配置相同,在此只列举data1节点的配置);[root@data1 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo[root@data1 ~]# yum -y install centos-release-gluster ##安装gluster包的yum源[root@data1 ~]# yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma[root@data1 ~]# systemctl start glusterd[root@data1 ~]# systemctl enable glusterdCreated symlink from /etc/systemd/system/multi-user.target.wants/glusterd.service to /usr/lib/systemd/system/glusterd.service.[root@data1 ~]# netstat -utpln |grep glutcp 0 0 0.0.0.0:24007 0.0.0.0:* LISTEN 1313/glusterd [root@data1 ~]# netstat -utpln |grep rpctcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1311/rpcbind udp 0 0 0.0.0.0:111 0.0.0.0:* 1311/rpcbind udp 0 0 0.0.0.0:634 0.0.0.0:* 1311/rpcbindØ在data1节点上进行创建集群,其他节点会同步;[root@data1 ~]# gluster peer probe data1.linuxfan.cn ##添加本机节点peer probe: success. Probe on localhost not needed[root@data1 ~]# gluster peer probe data2.linuxfan.cn ##添加data2节点[root@data1 ~]# gluster peer probe data3.linuxfan.cn ##添加data3节点[root@data1 ~]# gluster peer status ##查看gluster集群状态Hostname: data2.linuxfan.cnUuid: a452f7f4-7604-4d44-8b6a-f5178a41e308State: Peer in Cluster (Connected)Hostname: data3.linuxfan.cnUuid: b08f1b68-3f2c-4076-8121-1ab17d1517e1State: Peer in Cluster (Connected)[root@data1 ~]# mkdir /data[root@data1 ~]# gluster volume infoØ在data1节点创建数据存储的卷(复制卷),其他节点会同步配置;[root@data1 ~]# gluster volume create rep-volume replica 3 transport tcp data1.linuxfan.cn:/data data2.linuxfan.cn:/data data3.linuxfan.cn:/data force ##创建复制卷,名称如上volume create: rep-volume: success: please start the volume to access data[root@data1 ~]# gluster volume infoVolume ID: ac59612b-e6ce-46ce-85a7-74262fb722b2Number of Bricks: 1 x 3 = 3Brick1: data1.linuxfan.cn:/dataBrick2: data2.linuxfan.cn:/dataBrick3: data3.linuxfan.cn:/datatransport.address-family: inetperformance.client-io-threads: off[root@data1 ~]# gluster volume start rep-volume ##启动该卷volume start: rep-volume: successØ在client客户端节点上安装gluster客户端工具并测试挂载;[root@client ~]# yum install -y glusterfs glusterfs-fuse[root@client ~]# mount -t glusterfs data1.linuxfan.cn:rep-volume /mnt/[root@client ~]# ls /mnt/[root@client ~]# df -hT |tail -1data1.linuxfan.cn:rep-volume fuse.glusterfs 19G 2.0G 17G 11% /mnt[root@client ~]# touch /mnt/{1..10}.file[root@client ~]# dd if=/dev/zero of=/mnt/1.txt bs=1G count=1[root@client ~]# ls /mnt/10.file 1.file 1.txt 2.file 3.file 4.file 5.file 6.file 7.file 8.file 9.file[root@client ~]# du -sh /mnt/1.txt Gluster peer status ##查看所有的节点信息Gluster peer probe name ##添加节点Gluster peer detach name ##删除节点Gluster volume create xxx ##创建卷Gluster volume info ##查看卷信息gluster volume quota VOLNAME enable/disable
gluster volume quota VOLNAME limit-usage /img limit-value
gluster volume quota img limit-usage /quota 10GB 设置img 卷下的quota 子目录的限额为10GB。这个目录是以系统挂载目录为根目录”/”,所以/quota 即客户端挂载目录下的子目录quotagluster volume quota VOLNAME list
gluster volume quota VOLNAME list 可以使用如上两个命令进行系统卷的配额查看,第一个命令查看目的卷的所有配额设置,第二个命令则是执行目录进行查看。可以显示配额大小及当前使用容量,若无使用容量(最小0KB)则说明设置的目录可能是错误的(不存在)。gluster volume geo-replication MASTER SLAVE start/status/stop //地域复制是系统提供的灾备功能,能够将系统的全部数据进行异步的增量备份到另外的磁盘中。gluster volume geo-replication img 192.168.10.8:/data1/brick1 start 如上,开始执行将img 卷的所有内容备份到10.8 下的/data1/brick1 中的task,需要注意的是,这个备份目标不能是系统中的Brick。平衡布局是很有必要的,因为布局结构是静态的,当新的bricks 加入现有卷,新创建的文件会分布到旧的bricks 中,所以需要平衡布局结构,使新加入的bricks 生效。布局平衡只是使新布局生效,并不会在新的布局移动老的数据,如果你想在新布局生效后,重新平衡卷中的数据,还需要对卷中的数据进行平衡。当你扩展或者缩小卷之后,需要重新在服务器直接重新平衡一下数据,重新平衡的操作被分修改扩展或者缩小后的布局,以确保文件可以存储到新增加的节点中。* Fix Layout and Migrate Data# gluster volume rebalance VOLNAME fix-layout start# gluster volume rebalance VOLNAME migrate-data start # gluster volume rebalance VOLNAME start# gluster volume rebalance VOLNAME status //你可以在在平衡过程中查看平衡信息# gluster volume rebalance VOLNAME stop //你也可以暂停平衡,再次启动平衡的时候会从上次暂停的地方继续开始平衡。 Profile Command 提供接口查看一个卷中的每一个brick 的IO 信息#gluster volume profile VOLNAME start //启动profiling,之后则可以进行IO 信息查看#gluster volume profile VOLNAME info //查看IO 信息,可以查看到每一个Brick 的IO 信息#gluster volume profile VOLNAME stop //查看结束之后关闭profiling 功能 Top command 允许你查看bricks 的性能例如:read, write, fileopen calls, file read calls, file,write calls,directory open calls, and directory real calls# gluster volume top VOLNAME open [brick BRICK-NAME] [list-cnt cnt] //查看打开的fd# gluster volume top VOLNAME read [brick BRICK-NAME] [list-cnt cnt] //查看调用次数最多的读调用# gluster volume top VOLNAME write [brick BRICK-NAME] [list-cnt cnt] //查看调用次数最多的写调用# gluster volume top VOLNAME opendir [brick BRICK-NAME] [list-cnt cnt] //查看次数最多的目录调用# gluster volume top VOLNAME readdir [brick BRICK-NAME] [list-cnt cnt] //查看次数最多的目录调用# gluster volume top VOLNAME read-perf [bs blk-size count count] [brickBRICK-NAME] [list-cnt cnt] //查看每个Brick 的读性能# gluster volume top VOLNAME write-perf [bs blk-size count count] [brickBRICK-NAME] [list-cnt cnt] //查看每个Br
|