GlusterFS分布式的介绍及其实操

GlusterFS简介

  • 开源的分布式文件系统
  • 由存储服务器、客户端以及NFS/Samba存- 储网关组成
  • 无元数据服务器

GlusterFS 特点:
♢ 扩展性和高性能;
♢ 高可用性;
♢ 全局统一命名空间;
♢ 弹性卷管理;
♢ 基于标准协议

在这里插入图片描述
2.模块化堆栈架构:**
♢ 模块化,堆栈式结构;
♢通过对模块的组合,实现复杂的功能;
在这里插入图片描述

  • CentOS6.0以下使用的是EXT4文件系统,CentOS7.0使用的是xfs格式

  • RDMA协议的优势是去中心化,没有唯一的管理master,每台服务器协同管理

3.GFS的工作流程:

在这里插入图片描述
(1)客户端或应用程序通过GlusterFS的挂载点访问数据
(2)VFS将文件递交给FUSE内核文件系统,fuse文件系统则是将数据通过/dev/fuse设备文件递交给了GlusterFS client端
(3)GlusterFS client 收到数据后,client根据配置文件的配置对数据进行处理
(4) 通过网络将数据传递至远端的GlusterFS server,并且将数据写入到服务器存储设备上

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

弹性HASH算法会将文件分配到各个节点存储中,用户访问文件时,通过计算文件的HASH值,得到对应的brick存储空间,组合起来获得完整的文件

GlusterFS的卷类型

  • 分布式卷
  • 条带卷
  • 复制卷
  • 分布式条带卷
  • 分布式复制卷
  • 条带复制卷
  • 分布式条带复制卷

1.分布式卷

  • 没有对文件进行分块处理
  • 通过扩展文件属性保存HASH值
  • 支持的底层文件系统有EXT3、EXT4、ZFS、xFS等
    在这里插入图片描述

分布式卷的特点

  • 文件分布在不同的服务器,不具备冗余性
  • 更容易和廉价地扩展卷的大小
  • 单点故障会造成数据丢失
  • 依赖底层的数据保护

创建分布式卷的命令格式:
gluster volume create 卷名 节点1@文件系统 节点2@文件系统 ……

2.条带卷

  • 根据偏移量将文件分为 N 块(N个条带节点),轮询的存储在每个 Brick (2)Server 节点;
  • 存储大文件时,性能尤为突出;
  • 不具备冗余性,类似 raid0
    在这里插入图片描述

条带卷的特点:

(1)数据被分割成更小块分布到块服务器群中的不同条带区;
(2)分布减少了负载且更小的文件加速了存取的速度;
(3)没有数据冗余

创建条带卷的命令格式:
gluster volume create 卷名 stripe 条带数 节点1@文件系统 节点2@文件系统 ……

3. 复制卷:

(1)同一个文件保存一份或多分副本;
(2)复制模式因为要保存副本,所以磁盘利用率较低;
(3)多个节点上的存储空间不一致,那么将安装木桶效应取最低节点的容量(4)作为该卷的总容量

在这里插入图片描述

复制卷的特点:

(1)卷中所有的服务器均保存一个完整的副本;
(2)卷的副本数量可由客户创建的时候决定;
(3)至少由两个块服务器或更多服务器;
(4)具备容灾冗余性。

创建复制卷的命令格式:
gluster volume create 卷名 replica 2 transport tcp 节点1@文件系统 节点2@文件系统 ……

4.分布式条带卷:

(1)兼顾分布式和条带卷的功能;
(2)主要用于大文件访问处理;
(3)至少最少需要 4 台服务器。

在这里插入图片描述

创建分布式条带卷命令格式:
gluster volume create 卷名 stripe 2 transport tcp 节点1@文件系统 节点2@文件系统 节点3@文件系统 节点4@文件系统 …………

注意,创建分布式条带卷,服务器数目是条带数的倍数(至少两倍)

5.分布式复制卷:

(1)兼顾分布式卷和复制卷的功能;
(2)用于需要冗余的情况下

在这里插入图片描述

创建分布式复制卷的命令格式:
gluster volume create 卷名 replica 2 transport tcp 节点1@文件系统 节点2@文件系统 节点3@文件系统 节点4@文件系统 ……

注意,创建分布式条带卷,服务器数目是条带数的倍数(至少两倍)

实验

1.在实验的开始就先关闭防火墙和核心防护

setenforce 0 临时关闭
systemctl stop firewalld 关闭防火墙

2.我们在四台虚拟机每天分别添加四块磁盘

3.因挂载的磁盘我们要进行分区和格式化,但是因为操作数量过多,那么我们可以写一个 shell脚本,代替这繁琐的工作

[root@localhost ~]# vi test.sh

#!/bin/bash
for k in $(ls /dev/sd[b-z])
do
  echo -e "n\np\n\n\n\nw\n" |fdisk $V
  mkfs.xfs -i size=512 ${k}1 &>/dev/null
  sleep 1
  M=$(echo "$V" |awk -F "/" '{print $3}')
  mkdir -p /data/${M}1 &>/dev/null
  echo -e "${k}1 /data/${M}1 xfs defaults 0 0\n" >>/etc/fstab
  mount -a &>/dev/null
done

[root@localhost ~]# scp test.sh root@20.0.0.20:/root
[root@localhost ~]# scp test.sh root@20.0.0.80:/root
[root@localhost ~]# scp test.sh root@20.0.0.90:/root

4.每台节点都设置主机名,方便管理,并设置好映射关系(4个节点都做)

[root@localhost ~]# hostnamectl set-hostname node1
[root@localhost ~]# su
[root@node1 ~]# vi /etc/hosts   ##设置主机映射关系
20.0.0.50   node1
20.0.0.20  node2
20.0.0.80   node3
20.0.0.90   node4

5.搭建yum源,因为版本原因,建议不直接用线网源,找到对应版本安装(4个节点都做)

[root@node1 ~]# cd /etc/yum.repos.d/
[root@node1 yum.repos.d]# mv C* backup/
[root@node1 yum.repos.d]# ls
backup  GLFS.repo
[root@node1 yum.repos.d]# vi GLFS.repo
[GLFS]
name=glfs
baseurl=http://mirror.centos.org/centos/$releasever/storage/$basearch/gluster-3.12/
gpgcheck=0
enabled=1

6.安装gluster服务器,并设时间同步(4个节点都做)

[root@node1 ~]# yum -y install glusterfs  glusterfs-fuse glusterfs-rdma
[root@node1 ~]# yum install glusterfs-server   

[root@node2 ~]# systemctl enable glusterd
[root@node2 ~]# systemctl start glusterd
[root@node2 ~]# systemctl status glusterd
● glusterd.service - GlusterFS, a clustered file-system server
   Loaded: loaded (/usr/lib/systemd/system/glusterd.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2020-10-25 16:45:14 CST; 27s ago
     Docs: man:glusterd(8)
  Process: 20851 ExecStart=/usr/sbin/glusterd -p /var/run/glusterd.pid --log-level $LOG_LEVEL $GLUSTERD_OPTIONS (code=exited, 
  ……省略部分
[root@node1 ~]# ntpdate ntp1.aliyun.com 

添加另外三台到存储信任池(只需要在其中一个节点做即可,另外三个自动匹配)

[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      ##邻居数为3

7.制作分布式卷

[root@node1 ~]# gluster volume create dis-vol node1:/data/sdb1 node2:/data/sdb1 force
volume create: dis-vol: success: please start the volume to access data
[root@node1 ~]# gluster volume list     ##查看虚拟卷列表,可以看到刚刚建立的分布式卷
dis-vol

[root@node1 ~]# gluster volume info dis-vol    ##检查分布式卷的信息 
Volume Name: dis-vol
Type: Distribute
Volume ID: 76584c83-81af-4048-beca-38f73a802c2f
Status: Created                        ##这时候是刚刚创建的初始状态,还未启动
Snapshot Count: 0
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: node1:/data/sdb1
Brick2: node2:/data/sdb1    ##可以在状态中看到两个节点
Options Reconfigured:
transport.address-family: inet
storage.fips-mode-rchecksum: on
nfs.disable: on

[root@node1 ~]# gluster volume start dis-vol     ##启动分布式卷
volume start: dis-vol: success
[root@node1 ~]# gluster volume info dis-vol 
 
Volume Name: dis-vol
Type: Distribute
Volume ID: 76584c83-81af-4048-beca-38f73a802c2f
Status: Started                 ##状态为启动状态
Snapshot Count: 0
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: node1:/data/sdb1
Brick2: node2:/data/sdb1
Options Reconfigured:
transport.address-family: inet
storage.fips-mode-rchecksum: on
nfs.disable: on
[root@node1 ~]# gluster volume status    ##可以查看详细状态,包括PID号
Status of volume: dis-vol
Gluster process                             TCP Port  RDMA Port  Online  Pid
‘------------------------------------------------------------------------------'
Brick node1:/data/sdb1                      49152     0          Y       23046
Brick node2:/data/sdb1                      49152     0          Y       22414
 
Task Status of Volume dis-vol
'------------------------------------------------------------------------------'
There are no active volume tasks

8.创建条带卷

[root@node4 ~]# gluster volume create stripe-vol stripe 2 node1:/data/sdc1 node2:/data/sdc1 force   ##创建条带卷
volume create: stripe-vol: success: please start the volume to access data
[root@node4 ~]# gluster volume start stripe-vol   ##启动条带卷
volume start: stripe-vol: success
[root@node4 ~]# gluster volume info stripe-vol    ##查看信息
Volume Name: stripe-vol
Type: Stripe                     ##类型为条带卷
Volume ID: fe295188-8b4e-4af3-8e01-c976aae78219
Status: Started                ##启动状态
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2  ##条带卷*2
Transport-type: tcp
Bricks:
Brick1: node1:/data/sdc1
Brick2: node2:/data/sdc1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on

9.创建复制卷

[root@node4 ~]# gluster volume create rep-vol replica 2 node3:/data/sdb1 node4:/data/sdb1 force   ##创建复制卷
volume create: rep-vol: success: please start the volume to access data
[root@node4 ~]# gluster volume start rep-vol   ##启动复制卷
volume start: rep-vol: success
[root@node4 ~]# gluster volume info rep-vol
Volume Name: rep-vol
Type: Replicate   ##类型为复制卷
Volume ID: 4c543697-e4dd-41a3-a6e8-a15232fc2441
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2   ##复制卷*2
Transport-type: tcp
Bricks:
Brick1: node3:/data/sdb1
Brick2: node4:/data/sdb1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off

10.创建分布式条带卷

[root@node4 ~]# gluster volume create dis-stripe stripe 2 node1:/data/sdd1 node2:/data/sdd1 node3:/data/sdd1 node4:/data/sdd1 force   ##创建分布式条带卷,(不能少于4个文件系统)
volume create: dis-stripe: success: please start the volume to access data
[root@node4 ~]# gluster volume start dis-stripe
volume start: dis-stripe: success
[root@node4 ~]# gluster volume info dis-stripe
Volume Name: dis-stripe
Type: Distributed-Stripe     ##类型为分布卷 — 条带卷
Volume ID: 6e67b6ec-b1a7-407f-96dd-63c591aab737
Status: Started       ##启动状态
Snapshot Count: 0
Number of Bricks: 2 x 2 = 4    ##分布卷*2 + 条带卷*2
Transport-type: tcp     ##传输协议是TCP
Bricks:
Brick1: node1:/data/sdd1
Brick2: node2:/data/sdd1
Brick3: node3:/data/sdd1
Brick4: node4:/data/sdd1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on

11.创建分布式复制卷

[root@node4 ~]# gluster volume create dis-rep replica 2 node1:/data/sde1 node2:/data/sde1 node3:/data/sde1 node4:/data/sde1 force   ##创建分布式复制卷(同样不能少于4)
volume create: dis-rep: success: please start the volume to access data
[root@node4 ~]# gluster volume start dis-rep  
volume start: dis-rep: success
[root@node4 ~]# gluster volume info dis-rep  ##查看信息
Volume Name: dis-rep
Type: Distributed-Replicate   ##类型为分布式复制卷
Volume ID: d5697f48-3ded-4f4e-b499-c3dd08a247c8
Status: Started
Snapshot Count: 0
Number of Bricks: 2 x 2 = 4  ##分布卷*2 + 复制卷*2
Transport-type: tcp   ##TCP传输协议
Bricks:
Brick1: node1:/data/sde1
Brick2: node2:/data/sde1
Brick3: node3:/data/sde1
Brick4: node4:/data/sde1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off

12.查看卷列表

[root@node1 ~]# gluster volume list  ##可以查看到建立的五个卷
dis-rep
dis-stripe
dis-vol
rep-vol
stripe-vol

13.其他操作:

1、删除卷(先停止,再删除)

gluster volume stop 卷名

gluster volume delete 卷名

2、黑白名单设置:

gluster volume set 卷名 auth.reject 192.168.220.100 //拒绝某台主机挂载

gluster volume set 卷名 auth.allow 192.168.220.100 //允许某台主机挂载

二、客户端挂载测试

1.安装相关软件包并做主机映射

[root@localhost ~]# yum -y install glusterfs  glusterfs-fuse    ##安装这两个软件,支持gluster挂载
[root@localhost ~]# vi /etc/hosts   ##先给几个节点添加主机名映射
20.0.0.50   node1
20.0.0.20   node2
20.0.0.80   node3
20.0.0.90   node4

2.创建挂载目录并挂载

挂载分布卷
[root@localhost ~]# mkdir -p /test/dis
[root@localhost ~]# mount.glusterfs node1:dis-vol /test/dis/ 
###挂载条带卷
[root@web yum.repos.d]# mkdir -p /test/stripe
[root@web yum.repos.d]# mount.glusterfs node1:stripe-vol /test/stripe/
###挂载复制卷
[root@web yum.repos.d]# mkdir /test/rep
[root@web yum.repos.d]# mount.glusterfs node3:rep-vol /test/rep/
###挂载分布式条带卷
[root@web yum.repos.d]# mkdir /test/dis-str
[root@web yum.repos.d]# mount.glusterfs node2:dis-stripe /test/dis-str/
###挂载分布式复制卷
[root@web yum.repos.d]# mkdir /test/dis-rep
[root@web yum.repos.d]# mount.glusterfs node4:dis-rep /test/dis-rep/ 

3.查看挂载信息

[root@web yum.repos.d]# df -Th
Filesystem              Type            Size  Used Avail Use% Mounted on
……省略部分
node1:dis-vol           fuse.glusterfs   40G   65M   40G   1% /test/dis
node1:stripe-vol        fuse.glusterfs   40G   65M   40G   1% /test/stripe
node3:rep-vol           fuse.glusterfs   20G   33M   20G   1% /test/rep
node2:dis-stripe        fuse.glusterfs   80G  130M   80G   1% /test/dis-str
node4:dis-rep           fuse.glusterfs   40G   65M   40G   1% /test/dis-rep

挂载信息总结: 分布式、条带式、分布条带式卷可用空间为各个磁盘空间的总和,而复制卷和分布式复制卷的可用空间大小为空间的一半,但是安全性更高

三、测试各类型卷

1.在客户机创建5个测试文件,每个大小为40M

[root@web ~]# dd if=/dev/zero of=/demo1.log bs=1M count=40
[root@web ~]# dd if=/dev/zero of=/demo2.log bs=1M count=40
[root@web ~]# dd if=/dev/zero of=/demo3.log bs=1M count=40
[root@web ~]# dd if=/dev/zero of=/demo4.log bs=1M count=40
[root@web ~]# dd if=/dev/zero of=/demo5.log bs=1M count=40
[root@web ~]# ls /demo*
/demo1.log  /demo2.log  /demo3.log  /demo4.log  /demo5.log

2.分别拷贝到5个不同的挂载点中

[root@web ~]# cp /demo* /test/dis
[root@web ~]# cp /demo* /test/stripe
[root@web ~]# cp /demo* /test/rep
[root@web ~]# cp /demo* /test/dis-str
[root@web ~]# cp /demo* /test/dis-rep

3.查看验证

(1)验证分布式卷

[root@node1 ~]# ll -h /data/sdb1/   ##查看node1节点
total 160M
-rw-r--r--. 2 root root 40M Oct 28 01:54 demo1.log
-rw-r--r--. 2 root root 40M Oct 28 01:54 demo2.log
-rw-r--r--. 2 root root 40M Oct 28 01:54 demo3.log
-rw-r--r--. 2 root root 40M Oct 28 01:54 demo4.log
[root@node2 ~]# ll -h /data/sdb1/   ##查看node2节点
total 40M
-rw-r--r-- 2 root root 40M Oct 27 23:46 demo5.log
You have new mail in /var/spool/mail/root

总结:分布式卷中文件以完整的文件形式存放在各个节点中,每个节点存放一部分文件

(2)测试条带卷

[root@node1 ~]#  ll -h /data/sdc1  ##查看节点1中的文件,只有20M
total 101M
-rw-r--r--. 2 root root 20M Oct 28 01:54 demo1.log
-rw-r--r--. 2 root root 20M Oct 28 01:54 demo2.log
-rw-r--r--. 2 root root 20M Oct 28 01:54 demo3.log
-rw-r--r--. 2 root root 20M Oct 28 01:54 demo4.log
-rw-r--r--. 2 root root 20M Oct 28 01:54 demo5.log
[root@node2 ~]#  ll -h /data/sdc1   ##在查看节点2中的文件
total 101M
-rw-r--r--. 2 root root 20M Oct 28 01:54 demo1.log
-rw-r--r--. 2 root root 20M Oct 28 01:54 demo2.log
-rw-r--r--. 2 root root 20M Oct 28 01:54 demo3.log
-rw-r--r--. 2 root root 20M Oct 28 01:54 demo4.log
-rw-r--r--. 2 root root 20M Oct 28 01:54 demo5.log

总结,条带卷中每个文件被拆成N(条带数)个部分,分别存放在不同节点中,每个节点都只存放文件的1/N

(3)测试复制卷

[root@node3 ~]# ll -h /data/sdb1   ##查看节点3
total 200M
-rw-r--r--. 2 root root 40M Oct 28 00:41 demo1.log
-rw-r--r--. 2 root root 40M Oct 28 00:41 demo2.log
-rw-r--r--. 2 root root 40M Oct 28 00:41 demo3.log
-rw-r--r--. 2 root root 40M Oct 28 00:41 demo4.log
-rw-r--r--. 2 root root 40M Oct 28 00:41 demo5.log
[root@node4 ~]# ll -h /data/sdb1   ##查看节点4
total 200M
-rw-r--r--. 2 root root 40M Oct 28 00:41 demo1.log
-rw-r--r--. 2 root root 40M Oct 28 00:41 demo2.log
-rw-r--r--. 2 root root 40M Oct 28 00:41 demo3.log
-rw-r--r--. 2 root root 40M Oct 28 00:41 demo4.log
-rw-r--r--. 2 root root 40M Oct 28 00:41 demo5.log

总结:在复制卷中,每个文件会以备份的形式存放在各个节点中,每个节点都有一套完整的文件

(4)测试分布式条带卷

[root@node1 ~]# ll -h /data/sdd1   ##查看节点1
total 81M
-rw-r--r--. 2 root root 20M Oct 28 01:54 demo1.log
-rw-r--r--. 2 root root 20M Oct 28 01:54 demo2.log
-rw-r--r--. 2 root root 20M Oct 28 01:54 demo3.log
-rw-r--r--. 2 root root 20M Oct 28 01:54 demo4.log
[root@node2 ~]# ll -h /data/sdd1  ##查看节点2
total 80M
-rw-r--r-- 2 root root 20M Oct 27 23:46 demo1.log
-rw-r--r-- 2 root root 20M Oct 27 23:46 demo2.log
-rw-r--r-- 2 root root 20M Oct 27 23:46 demo3.log
-rw-r--r-- 2 root root 20M Oct 27 23:46 demo4.log
[root@node3 ~]# ll -h /data/sdd1   ##查看节点3
total 21M
-rw-r--r--. 2 root root 20M Oct 28 00:41 demo5.log
[root@node4 ~]# ll -h /data/sdd1   ##查看节点4
total 21M
-rw-r--r--. 2 root root 20M Oct 28 00:41 demo5.log

总结:分布式条带卷先以分布式卷的形式,两两一组,保存完整的文件,再对各组的文件进行条带式拆分存储,将组内的文件分成两部分存在组内的服务器上,即一个组内的两台服务器存放的文件可以组成一部分完整的文件,另一组同理,两个组各自持有的那部分文件相加就是完全完整的文件

(5)分布式复制卷

[root@node1 ~]# ll -h /data/sde1   ##查看节点1
total 160M
-rw-r--r--. 2 root root 40M Oct 28 02:27 demo1.log
-rw-r--r--. 2 root root 40M Oct 28 02:27 demo2.log
-rw-r--r--. 2 root root 40M Oct 28 02:27 demo3.log
-rw-r--r--. 2 root root 40M Oct 28 02:27 demo4.log
[root@node2 ~]# ll -h /data/sde1   ##查看节点2
total 160M
-rw-r--r-- 2 root root 40M Oct 28 00:20 demo1.log
-rw-r--r-- 2 root root 40M Oct 28 00:20 demo2.log
-rw-r--r-- 2 root root 40M Oct 28 00:20 demo3.log
-rw-r--r-- 2 root root 40M Oct 28 00:20 demo4.log
[root@node3 ~]# ll -h /data/sde1   ##查看节点3
total 40M
-rw-r--r--. 2 root root 40M Oct 28 01:15 demo5.log
[root@node4 ~]# ll -h /data/sde1   ##查看节点4
total 40M
-rw-r--r--. 2 root root 40M Oct 28 01:15 demo5.log

总结:分布式复制卷两两一组,每组保存整套完整的文件,组组之间进行备份,当一台节点挂掉,数据不受影响

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值