GlusterFS原理及如何配置使用

一、GlusterFS概述

1.1简介

Glusterfs是一个开源的分布式文件系统,是Scale存储的核心,能够处理千数量级的客户端.在传统的解决 方案中Glusterfs能够灵活的结合物理的,虚拟的和云资源去体现高可用和企业级的性能存储.
Glusterfs通过TCP/IP或InfiniBand RDMA网络链接将客户端的存储资块源聚集在一起,使用单一的全局命名空间来管理数据,磁盘和内存资源.
Glusterfs基于堆叠的用户空间设计,可以为不同的工作负载提供高优的性能.

1.2特点

●扩展性和高性能
GlusterFS利用双重特性来提供几TB至数PB的高扩展存储解决方案。Scale-Out架构允许通过简单地增加资源来提高存储容量和性能,磁盘、计算和I/O资源都可以独立增加,支持10GbE和InfiniBand等高速网络互联。Gluster弹性哈希(Elastic Hash)解除了GlusterFS对元数据服务器的需求,消除了单点故障和性能瓶颈,真正实现了并行化数据访问。
●高可用性
GlusterFS可以对文件进行自动复制,如镜像或多次复制,从而确保数据总是可以访问,甚至是在硬件故障的情况下也能正常访问。自我修复功能能够把数据恢复到正确的状态,而且修复是以增量的方式在后台执行,几乎不会产生性能负载。GlusterFS没有设计自己的私有数据文件格式,而是采用操作系统中主流标准的磁盘文件系统(如EXT3、ZFS)来存储文件,因此数据可以使用各种标准工具进行复制和访问。

●全局统一命名空间
全局统一命名空间将磁盘和内存资源聚集成一个单一的虚拟存储池,对上层用户和应用屏蔽了底层的物理硬件。存储资源可以根据需要在虚拟存储池中进行弹性扩展,比如扩容或收缩。当存储虚拟机映像时,存储的虚拟映像文件没有数量限制,成千虚拟机均通过单一挂载点进行数据共享。虚拟机I/O可在命名空间内的所有服务器上自动进行负载均衡,消除了SAN环境中经常发生的访问热点和性能瓶颈问题。

●弹性卷管理

数据储存在逻辑卷中,逻辑卷可以从虚拟化的物理存储池进行独立逻辑划分而得到。存储服务器可以在线进行增加和移除,不会导致应用中断。逻辑卷可以在所有配置服务器中增长和缩减,可以在不同服务器迁移进行容量均衡,或者增加和移除系统,这些操作都可在线进行。文件系统配置更改也可以实时在线进行并应用,从而可以适应工作负载条件变化或在线性能调优。

●基于标准协议

Gluster存储服务支持NFS, CIFS, HTTP, FTP以及Gluster原生协议,完全与POSIX标准兼容。现有应用程序不需要作任何修改或使用专用API,就可以对Gluster中的数据进行访问。这在公有云环境中部署Gluster时非常有用,Gluster对云服务提供商专用API进行抽象,然后提供标准POSIX接口。

1.3GlusterFS相关术语

●Brick:GFS中的存储单元,通过是一个受信存储池中的服务器的一个导出目录。可以通过主机名和目录名来标识,如’SERVER:EXPORT’
●Volume:一组bricks的逻辑集合(卷)
●FUSE:Filesystem Userspace是一个可加载的内核模块,其支持非特权用户创建自己的文件系统而不需要修改内核代码。通过在用户空间运行文件系统的代码通过FUSE代码与内核进行桥接。
●VFS:虚拟文件系统
●Glusterd:Gluster management daemon,要在trusted storage pool中所有的服务器上运行。
Node:一个拥有若干brick的设备
Client: 挂载了GFS卷的设备
RDMA:远程直接内存访问,支持不通过双方的OS进行直接内存访问。
RRDNS:round robin DNS是一种通过DNS轮转返回不同的设备以进行负载均衡的方法
Self-heal:用于后台运行检测复本卷中文件和目录的不一致性并解决这些不一致。
Split-brain:脑裂
Volfile:glusterfs进程的配置文件,通常位于/var/lib/glusterd/vols/volname

1.4模块化堆栈式架构

●模块化、堆栈式的架构
●通过对模块的组合,实现复杂的功能
GlusterFS采用模块化、堆栈式的架构,可通过灵活的配置支持高度定制化的应用环境,比如大文件存储、海量小文件存储、云存储、多传输协议应用等。每个功能以模块形式实现,然后以积木方式进行简单的组合,即可实现复杂的功能。比如,Replicate模块可实现RAID1,Stripe模块可实现RAID0,通过两者的组合可实现RAID10和RAID01,同时获得高性能和高可靠性。如下图所示
在这里插入图片描述

二、GlusterFS工作原理

2.1弹性hash算法

●通过hash算法得到一个32位的整数
●划分为N个连续的子空间,每个空间对应一个Brick
●弹性hash算法的优点
保证数据平均分布在每一个Brick中
解决了对元数据服务器的依赖,进而解决了单点故障以及访问瓶颈

2.2GlusterFS工作流程

1、客户端或应用程序通过GlusterFS的挂载点访问数据,对于用户来说,集群系统的存在对用户是完全透明的,用户感觉不到是操作本地系统还是远端的集群系统。
2、用户的这个操作被递交给 本地linux系统的VFS来处理。
3、VFS将数据递交给FUSE内核文件系统, fuse文件系统则是将数据通过/dev/fuse设备文件递交给了GlusterFS client端,所以, 我们可以将 fuse文件系统理解为一个代理。
4、GlusterFS client 收到数据后,client根据配置文件的配置对数据进行处理
5、通过网络将数据传递至远端的GlusterFS Server,并且将数据写入到服务器存储设备上
在这里插入图片描述

三、GlusterFS的卷类型

3.1分布式卷

●没有对文件进行分块处理
●通过扩展文件属性保存hash值
●支持的底层文件系统有ext4、zfs、xfs等

●特点
文件分布在不同的服务器,不具备冗余性
可以灵活的扩展卷的大小
单点故障会造成数据丢失
依赖底层的数据保护
●创建分布式卷
创建一个名为dis-vol的分布式卷,文件将根据hash分布在node1:/data/sdb node2:/data/sdb中

gluster volume create dis-vol node1:/data/sdb node2:/data/sdb force

3.2条带卷

●根据偏移量将文件分成N块(N个条带节点),轮询的存储在每个Brick Server节点
●存储大文件时,性能尤为突出
●不具备冗余性,类似Raid0
●特点
数据被分割成更小块分布到块服务器中的不同条带区
分布减少了负载且更小的文件加速了存取的速度
没有数据冗余
●创建条带卷
创建了一个名为stripe-vol的条带卷,文件将被分块轮询的存储在node1:/data/sdc node2:/data/sdc中

gluster volume create stripe-vol stripe 2 transport tcp node1:/data/sdc node2:/data/sdc
(transport不指明时默认是RDMA

3.3复制卷

●同一个文件保存一份或多份副本
●因为要保存副本,所以磁盘利用率较低
●若多个节点上的存储空间不一致,将按照木桶效应取最低节点的容量作为该卷的总容量
●特点
卷中所有的服务器均保存一个完整的副本
卷的副本数量可由客户创建的时候决定
至少有两个块服务器或更多服务器
具备冗余性
●创建复制卷
创建名为rep-vol的复制卷,文件将同时存储两个副本,分别在node3:/data/sdb node4:/data/sdb两个Brick中

gluster volume create rep-vol replica 2 node3:/data/sdb node4:/data/sdb force

3.4分布式条带卷

●兼顾分布式卷和条带卷的功能
●主要用于大文件访问处理
●最少需要4台服务器
●创建分布式条带卷
创建了名为dis-stripe的分布式条带卷,配置分布式的条带卷时,卷中Brick所包含的存储服务器数必须是条带数的倍数(>=2倍)

 gluster volume create dis-stripe stripe 2 node1:/data/sdd node2:/data/sdd node3:/data/sdd node4:/data/sdd force

3.5分布式复制卷

●兼顾分布式卷和复制卷的功能
●用于需要冗余的情况

●创建分布式复制卷
创建名为dis-rep的分布式条带卷,配置分布式复制卷时,卷中Brick所包含的存储服务器数必须是条带数的倍数(>=2倍)

  gluster volume create dis-rep replica 2 node1:/data/sde node2:/data/sde node3:/data/sde node4:/data/sde force

四、部署GlusterFS卷

4.1实验环境

在这里插入图片描述

安装软件:

服务端:glusterfs;glusterfs-server;glusterfs-fuse;glusterfs-rdma
客户端:glusterfs;glusterfs-fuse
glusterfs:命令软件包
glusterfs-server:glusterfs服务软件
glusterfs-fuse:内核模块软件
glusterfs-rdma:通讯协议RDMA软件包

4.2以下过程为构建存储池子

1.每个节点添加4块磁盘,每块都是20G,格式化后进行挂载
采用如下的脚本进行格式化并挂载到系统中

#!/bin/bash
for i in {
    
    b,c,d,e}
do

    echo "n
           p



           w" | fdisk /dev/sd$i
         mkdir -p /data/sd$i
         mkfs.xfs /dev/sd${
    
    i}1
         cat>>/etc/fstab<<EOF
          /dev/sd${
    
    i}1 /data/sd$i xfs defaults 0 0
EOF

done
mount -a

2.为四台节点修改主机名,添加主机名解析到本地hosts文件中

[root@localhost ~]# hostnamectl set-hostname node1
[root@localhost ~]# su
[root@node1 ~]# vim /etc/hosts
14.0.0.10 node1
14.0.0.20 node2
14.0.0.30 node3
14.0.0.40 node4

3.安装glusterfs相应软件并启动服务

[root@localhost data]# yum -y install centos-release-gluster 
#Gluster的安装包在centos-release-gluster源里面,CentOS7.5默认带的是GlusterFS 3.11版本,默认版本比较低,如果要安装更高的版本需要安装centos-release-gluster源
[root@localhost ~]# yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma
[root@localhost ~]# systemctl start glusterd
[root@localhost ~]# systemctl enable glusterd                                  
 [root@localhost ~]# systemctl status glusterd

4.时间同步

[root@localhost ~]# ntpdate ntp1.aliyun.com
13 Sep 21:56:31 ntpdate[10857]: adjust time server 120.25.115.20 offset 0.000978 sec

5.构建存储池子(在任意节点即可)

[root@node1 ~]# gluster peer probe node2
peer probe: success.
[root@node1 ~]# gluster peer probe node3
peer probe: success.
[root@node1 ~]# gluster peer probe node4
peer probe: success.
#查看所有节点
[root@node1 ~]# gluster peer status
Number of Peers: 3
Hostname: node2
Uuid: 472754cd-a486-435b-9dc6-30cc2e3f8165
State: Peer in Cluster (Connected)
Hostname: node3
Uuid: 95f22b8a-6ac6-417d-bb60-4fb5c0a612a2
State: Peer in Cluster (Connected)
Hostname: node4
Uuid: 13d749b8-715d-4abd-94ca-5d38852271e0
State: Peer in Cluster (Connected)

4.3根据规划创建如下卷

在这里插入图片描述
注意!!!从glusterfs 6.0版本 开始,已经弃用stripe模式

[root@node1 ~]# gluster --version   #查看安装的glusterfs版本
glusterfs 7.7
Repository revision: git://git.gluster.org/glusterfs.git
Copyright (c) 2006-2016 Red Hat, Inc. <https://www.gluster.org/>
GlusterFS comes with ABSOLUTELY NO WARRANTY.
It is licensed to you under your choice of the GNU Lesser
General Public License, version 3 or any later version (LGPLv3
or later), or the GNU General Public License, version 2 (GPLv2),
in all cases as published by the Free Software Foundation.
[root@node1 ~]# gluster volume create stripe-vol stripe 2 node1:/data/sdc node2:/data/sdc force
stripe option not supported   #从glusterfs 6.0版本 开始,已经弃用stripe模式

所以本实验将演示如何构建分布式卷、复制卷和分布式复制卷;生产环境中分布式复制卷用的最多。

客户端配置:

1.添加4个服务器节点的主机名解析
[root@client ~]# vim /etc/hosts
14.0.0.10 node1
14.0.0.20 node2
14.0.0.30 node3
14.0.0.40 node4
2.安装glusterfs软件
[root@client ~]# yum -y install glusterfs glusterfs-fuse
3.创建540M的文件
[root@client ~]# dd if=/dev/zero of=/opt/test1.txt bs=1M count=40
[root@client ~]# dd if=/dev/zero of=/opt/test2.txt bs=1M count=40
[root@client ~]# dd if=/dev/zero of=/opt/test3.txt bs=1M count=40
[root@client ~]# dd if=/dev/zero of=/opt/test4.txt bs=1M count=40
[root@client ~]# dd if=/dev/zero of=/opt/test5.txt bs=1M count=40

4.3.1创建分布式卷

[root@node1 ~]# gluster volume create dis-vol node1:/data/sdb node2:/data/sdb force
volume create: dis-vol: success: please start the volume to access data
[root@node1 ~]# gluster volume info dis-vol           #查看dis-vol卷信息
...省略内容
Status: Created

[root@node1 ~]# gluster volume start dis-vol          #启用dis-vol卷
volume start: dis-vol: success
[root@node1 ~]# gluster volume info dis-vol
...省略内容
Status: Started

#客户端挂载分布式卷到/test/dis目录下,并将5个测试文件拷贝进去

[root@client ~]# mkdir -p /test/dis
[root@client ~]# mount.glusterfs node1:dis-vol /test/dis/
[root@client ~]# cp /opt/test* /test/dis/
[root@client ~]# df -Th
文件系统                类型            容量  已用  可用 已用% 挂载点
...省略内容
node1:dis-vol           fuse.glusterfs   40G  475M   40G    2% /test/dis

#回到node1和node2节点中查看5个文件分布情况
node1下/data/sdb/被分布到了3个文件

[root@node1 ~]# ll -h /data/sdb/
总用量 120M
-rw-r--r--. 2 root root 40M 913 22:48 test1.txt
-rw-r--r--. 2 root root 40M 913 22:48 test3.txt
-rw-r--r--. 2 root root 40M 913 22:48 test4.txt
node2下/data/sdb/被分布到了2个文件
[root@node2 ~]#  ll -h /data/sdb/
总用量 80M
-rw-r--r--. 2 root root 40M 913 22:48 test2.txt
-rw-r--r--. 2 root root 40M 913 22:48 test5.txt

4.3.2创建复制卷

[root@node1 ~]# gluster volume create rep-vol replica 2 node3:/data/sdb node4:/data/sdb force
[root@node1 ~]# gluster volume start rep-vol        
[root@node1 ~]# gluster volume status rep-vol      #查看rep-vol卷状态
Status of volume: rep-vol
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick node3:/data/sdb                       49152     0          Y       68129
Brick node4:/data/sdb                       49152     0          Y       11283
...省略内容

#客户端挂载分布式卷到/test/rep-vol目录下,并将5个测试文件拷贝进去

[root@client test]# mkdir /test/rep-vol
[root@client test]# mount.glusterfs node1:rep-vol/ /test/rep-vol/
[root@client test]# df -Th
文件系统                类型            容量  已用  可用 已用% 挂载点
...省略内容
node1:rep-vol           fuse.glusterfs   20G  238M   20G    2% /test/rep-vol   #复制卷容量是总和一半
[root@client ~]# cp /opt/test* /test/rep-vol/

#回到node3和node4节点中查看5个文件分布情况

node3下/data/sdb/被分布到了5个文件

[root@node3 sdb]# ll -h /data/sdb
总用量 200M
-rw-r--r--. 2 root root 40M 913 23:22 test1.txt
-rw-r--r--. 2 root root 40M 913 23:22 test2.txt
-rw-r--r--. 2 root root 40M 913 23:22 test3.txt
-rw-r--r--. 2 root root 40M 913 23:22 test4.txt
-rw-r--r--. 2 root root 40M 913 23:22 test5.txt

node4下/data/sdb/也被分布到了5个文件
[root@node4 ~]# ll -h /data/sdb
总用量 200M
-rw-r--r--. 2 root root 40M 913 23:22 test1.txt
-rw-r--r--. 2 root root 40M 913 23:22 test2.txt
-rw-r--r--. 2 root root 40M 913 23:22 test3.txt
-rw-r--r--. 2 root root 40M 913 23:22 test4.txt
-rw-r--r--. 2 root root 40M 913 23:22 test5.txt

4.3.3创建分布式复制卷

[root@node1 ~]# gluster volume create dis-rep replica 2 node1:/data/sde node2:/data/sde node3:/data/sde node4:/data/sde force
volume create: dis-rep: success: please start the volume to access data
[root@node1 ~]# gluster volume start dis-rep
volume start: dis-rep: success

#客户端挂载分布式卷到/test/dis-rep目录下,并将5个测试文件拷贝进去

[root@client ~]# mkdir /test/dis-rep
[root@client ~]# mount.glusterfs node1:dis-rep /test/dis-rep
[root@client ~]# df -Th
文件系统                类型            容量  已用  可用 已用% 挂载点
...省略内容
node1:dis-rep           fuse.glusterfs   40G  475M   40G    2% /test/dis-rep
[root@client ~]# cp /opt/test* /test/dis-rep

#回到node1、node2、node3和node4节点中查看5个文件分布情况

#node1和node2节点中互为备份的存了三个文件
[root@node1 ~]# ll -h /data/sde/
总用量 120M
-rw-r--r--. 2 root root 40M 913 23:29 test1.txt
-rw-r--r--. 2 root root 40M 913 23:29 test3.txt
-rw-r--r--. 2 root root 40M 913 23:29 test4.txt

[root@node2 ~]# ll -h /data/sde/
总用量 120M
-rw-r--r--. 2 root root 40M 913 23:29 test1.txt
-rw-r--r--. 2 root root 40M 913 23:29 test3.txt
-rw-r--r--. 2 root root 40M 913 23:29 test4.txt
#node3和node4节点中互为备份的存了剩下的两个文件
[root@node3 sdb]# ll -h /data/sde/
总用量 80M
-rw-r--r--. 2 root root 40M 913 23:29 test2.txt
-rw-r--r--. 2 root root 40M 913 23:29 test5.txt

[root@node4 ~]# ll -h /data/sde/
总用量 80M
-rw-r--r--. 2 root root 40M 913 23:29 test2.txt
-rw-r--r--. 2 root root 40M 913 23:29 test5.txt

4.4破坏测试

将node2宕机掉模拟故障,查看客户端中挂载点中依然存在的文件:

[root@client test]# ll -h dis
总用量 120M
-rw-r--r-- 1 root root 40M 913 22:48 test1.txt
-rw-r--r-- 1 root root 40M 913 22:48 test3.txt
-rw-r--r-- 1 root root 40M 913 22:48 test4.txt
[root@client test]# ll -h dis-rep
总用量 200M
-rw-r--r-- 1 root root 40M 913 23:37 test1.txt
-rw-r--r-- 1 root root 40M 913 23:37 test2.txt
-rw-r--r-- 1 root root 40M 913 23:37 test3.txt
-rw-r--r-- 1 root root 40M 913 23:37 test4.txt
-rw-r--r-- 1 root root 40M 913 23:37 test5.txt
[root@client test]# ll -h rep-vol
总用量 200M
-rw-r--r-- 1 root root 40M 913 23:22 test1.txt
-rw-r--r-- 1 root root 40M 913 23:22 test2.txt
-rw-r--r-- 1 root root 40M 913 23:22 test3.txt
-rw-r--r-- 1 root root 40M 913 23:22 test4.txt
-rw-r--r-- 1 root root 40M 913 23:22 test5.txt

总结:复制卷、分布式复制卷的数据完整,条带卷数据全部丢失,分布式卷丢失一部分

4.5访问控制

#仅拒绝某个用户
[root@node1 ~]# gluster volume set dis-rep auth.reject 14.0.0.50
volume set: success
#仅允许某个用户
[root@node1 ~]# gluster volume set dis-rep auth.allow 14.0.0.50
volume set: success

猜你喜欢

转载自blog.csdn.net/chengu04/article/details/108573173