GFS 分布式文件系统简述与Gluster群集部署

一、GFS 概述

1.1 Gluster简介

  • 开源的分布式文件系统
  • 由存储服务器、客户端以及NFS/Samba存储网管组成
  • 无元数据服务器
  • GlusterFS特点
    扩展性和高性能
    高可用性
    全局统一命名空间
    弹性卷管理
    基于标准协议

1.2 Gluster常用术语

  • Brick:GFS中的存储单元,通过是一个受信存储池中的服务器的一个导出目录。可以通过主机名和目录名来标识,如’SERVER:EXPORT’
  • Volume:卷
  • FUSE:内核文件系统,Filesystem Userspace是一个可加载的内核模块,其支持非特权用户创建自己的文件系统而不需要修改内核代码。通过在用户空间运行文件系统的代码通过FUSE代码与内核进行桥接。
  • VFS:虚拟文件系统
  • Glusterd:Gluster management daemon,要在trusted storage pool中所有的服务器上运行。

1.3 Gluster结构与工作原理

结构
模块化堆栈式架构
模块化、堆栈式的架构
通过对模块的组合,实现复杂的功能
工作原理
1、客户端或应用程序通过GlusterFS的挂载点访问数据
2、linux系统内核通过VFS API收到请求并处理
3、VFS将数据递交给FUSE内核文件系统, fuse文件系统则是将数据通过/dev/fuse设备文件递交给了GlusterFS client端
4、GlusterFS client 收到数据后,client根据配置文件的配置对数据进行处理
5、通过网络将数据传递至远端的GlusterFS Server,并且将数据写入到服务器存储设备上

1.4 GlusterFS 算法

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

二、GlusterFS 的卷类型

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

2.1 分布式卷

  • 没有对文件进行分块处理
  • 通过扩展文件属性保存Hash值
  • 支持的底层文件系统有 EXT3、EXT4、ZFS、XFS 等
  • 没有分块处理,文件只能存在一个server中,效率不提升
    分布式特点
    文件分布在不同的服务器,不具备冗余性
    更容易和廉价低扩展卷的大小
    单点故障会造成数据丢失
    依赖底层的数据保护
    创建分布式卷
gluster volume  create  dis-volume  server1:/dir1   server2:/dir2   s erver3:/dir3
## 指定名称为 dis-volume    包含 server1:/dir1   server2:/dir2   s erver3:/dir3

2.2 条带卷

  • 根据偏移量将文件分成N块(N个条带节点),轮询的存储在每个Brick Server节点
  • 存储大文件时,性能尤为突出
  • 不具备冗余性,类似Raid0
    特点
    数据被分割成更小块分布式到块服务器群中的不同条带区
    分布减少了负载且更小的文件加速了存取的速度
    没有数据冗余
    创建条带卷
gluster volume  create  stripe-volume stripe 2   transport   tcp   server1:/dir1  server2:/dir2
## 名称为 stripe-volume    每个文件分为两块(stripe  2) ,  指定传输协议为tcp(transport   tcp)  包含server1:/dir1  server2:/dir2

2.3 复制卷

  • 同一文件保存一份或者多份
  • 因为要保存副本,所以磁盘利用率低
  • 若多个节点上的存储空间一致,将按照木桶效应取最低点节点的容量作为改卷的总容量
    特点
    卷中所有的服务器均保存一个完整的副本
    卷的副本数量可由客户创建的时候决定
    至少有两个块服务器或更多服务器
    具备冗余性
    创建复制卷
gluster volume  create  rep-volume replica 2   transport   tcp   server1:/dir1  server2:/dir2  
# 创建名为rep-volume的复制卷,文件将同时保存两份副本,分别再Server1:/dir1 和Server2:/dir2 中

2.4 分布式条带卷

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

2.5 分布式复制卷

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

创建命令

创建了名为dis-rep 的分布式复制卷,配置分布式的条带卷时,卷中Brick所包含的存储服务器必须是条带数的倍数(>=2倍)
gluster volume create dis-rep replica 2  node1:/data/sde1 node2:/data/sde1 node3:/data/sde1  node4:/data/sde1  force

三、Gluster群集部署

3.1 实验环境

4台虚拟机 IP地址分别为
node1 192.168.233.100
node2 192.168.233.100
node3 192.168.233.180
node4 192.168.233.50
每台虚拟机添加4个大小为20G的硬盘

3.2 实验准备工作

root@localhost ~]# hostnamectl set-hostname node1  ## 4台服务器依次修改主机名
[root@localhost ~]# su
[root@node1 ~]# vim /etc/hosts     ## 四台都要写入 主机名要和IP地址对应   用 scp /etc/hosts  [email protected]:/etc/hosts  为了方便  可以传输过去
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.233.100 node1
192.168.233.200 node2
192.168.233.180 node3
192.168.233.50 node4
[root@node1 ~]# systemctl stop firewalld ## 四台服务器都关闭防火墙   清空规则没用  还是会有干扰
[root@node1 ~]# setenforce 0

3.3 配置yum源 安装Gluster

  • 每台节点都要装
root@promote ~]# mount -t cifs -o username=wang,password=248569 //192.168.1.162/gfsrepo /mnt

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# mv C* bak
[root@localhost yum.repos.d]# vim GLFS.repo
[GLFS]
name=glfs
baseurl=file:///mnt/
gpgcheck=0
enable=1
[root@localhost ~]# yum clean all
[root@localhost ~]#  yum list
[root@node1 mnt]# yum -y install glusterfs-server  glusterfs-rdma glusterfs-fuse
[root@node1 ~]# systemctl start  glusterd.service    ## gluster服务启动 
[root@node1 ~]# systemctl enable glusterd.service  ## 开机自启动
[root@node1 ~]# systemctl status   glusterd.service  ## 查看状态

3.4 校验时间,添加gluster邻居

[root@node1 ~]# ntpdate ntp1.aliyun.com    ## 确保后面数据是正的
13 Sep 22:20:58 ntpdate[20333]: adjust time server 120.25.115.20 offset 0.000040 sec
#####添加入存储信任池只要在一台主机上添加其他节点即可
[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. 

3.5 查看gluster节点


[root@node1 ~]# gluster peer status    ## 查看所有节点
Number of Peers: 3

Hostname: node2
Uuid: 2cfcfa43-89ba-40ec-ba5e-e6873a40b649
State: Peer in Cluster (Connected)

Hostname: node3
Uuid: b7c73acb-a677-45a4-9e14-6cec62f1cc86
State: Peer in Cluster (Connected)

Hostname: node4
Uuid: d2a4f351-3e22-416b-9a4a-b6713dc6c5c7
State: Peer in Cluster (Connected)

3.6 客户端操作

[root@client ~]# systemctl stop firewalld
[root@client ~]# setenforce 0

[root@client  ~]# mount -t cifs -o username=wang,password=248569 //192.168.1.162/gfsrepo /mnt

[root@client  ~]# cd /etc/yum.repos.d/
[root@client  yum.repos.d]# mkdir bak
[root@client  yum.repos.d]# mv C* bak
[root@client  yum.repos.d]# vim GLFS.repo
[GLFS]
name=glfs
baseurl=file:///mnt/
gpgcheck=0
enable=1

[root@client ~]# yum clean all
[root@client ~]#  yum list
[root@client ~]# yum remove glusterfs-libs.x86_64
[root@client mnt]# yum -y install glusterfs-server  glusterfs-rdma glusterfs-fuse
[root@client ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.233.100 node1
192.168.233.200 node2
192.168.233.180 node3
192.168.233.50 node4

3.7 各种卷的创建

3.7.1 条带卷的创建与存储方式验证

########创建 条带卷 随便哪个node节点都可以
[root@node1 ~]# 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@node1 ~]# gluster volume list  ## 查看卷
stripe-vol
[root@node1 ~]# gluster volume info stripe-vol   ## 查看stripe-vol
 
Volume Name: stripe-vol
Type: Stripe
Volume ID: 164d4e23-51af-47b6-8b77-a8c50b267e52
Status: Created
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: node1:/data/sdc1
Brick2: node2:/data/sdc1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on

[root@node1 ~]# gluster volume start stripe-vol  ## 开启卷 才能挂载
volume start: stripe-vol: success

验证

### 客户端验证条带卷
dd if=/dev/zero of=/demo1.log bs=1M count=40 ## 创建5个用于测试的包,每个40M
dd if=/dev/zero of=/demo2.log bs=1M count=40
dd if=/dev/zero of=/demo3.log bs=1M count=40
dd if=/dev/zero of=/demo4.log bs=1M count=40
dd if=/dev/zero of=/demo5.log bs=1M count=40
[root@client ~]# mkdir -p /test/stripe-vol
[root@client ~]# mount.glusterfs node1:stripe-vol  /test/stripe-vol/ ## 这里node用哪个都可以 挂载 stripe-vol 到  /test/stripe-vol/

[root@client ~]#  cd /
[root@client /]# ls
bin   demo1.log  demo3.log  demo5.log  etc   lib    media  opt   root  sbin  sys   tmp  var
boot  demo2.log  demo4.log  dev        home  lib64  mnt    proc  run   srv   test  usr
[root@client /]# cp -p demo* /test/stripe-vol/   ## 将测试的文件复制到/test/stripe-vol/ 


查看node2
[root@node2 ~]# cd /data/sdc1/
[root@node2 sdc1]# ls -lh
总用量 100M
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo1.log
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo2.log
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo3.log
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo4.log
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo5.log
[root@node1 ~]# cd /data/sdc1/
[root@node1 sdc1]# ls -lh
总用量 100M
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo1.log
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo2.log
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo3.log
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo4.log
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo5.log

3.7.2 分布卷的创建与存储方式验证

  • 节点创建分布卷
创建 分布式卷
[root@node1 sdc1]# 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 sdc1]# gluster volume start dis-vol 
volume start: dis-vol: success
  • 验证
    –客户端
[root@client /]# mount.glusterfs node1:dis-vol  /test/dis-vol/
[root@client /]# cp -p demo* /test/dis-vol/   ## 将测试的文件复制到/test/dis -vol/

[root@node1 sdc1]# cd /data/sdb1/
您在 /var/spool/mail/root 中有新邮件
[root@node1 sdb1]# ls -lh
总用量 160M
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo1.log
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo2.log
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo3.log
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo4.log


[root@node2 sdc1]# cd /data/sdb1/
[root@node2 sdb1]# ls -lh
总用量 40M
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo5.log

3.7.3 复制卷的创建与存储方式验证

  • 创建复制卷
[root@node1 sdb1]# 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@node1 sdb1]# gluster volume start rep-vol 
volume start: rep-vol: success
  • 验证
####### 客户端
[root@client test]# mkdir -p /test/rep-vol
[root@client test]# mount.glusterfs node1:rep-vol  /test/rep-vol/
[root@client /]#  cp -p demo* /test/rep-vol/

## node 3
[root@node3 ~]# cd /data/sdb1/
[root@node3 sdb1]# ls -lh
总用量 200M
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo1.log
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo2.log
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo3.log
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo4.log
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo5.log
#### node 4
[root@node4 ~]# cd /data/sdb1/
[root@node4 sdb1]# ls -lh
总用量 200M
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo1.log
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo2.log
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo3.log
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo4.log
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo5.log

3.7.4 分布式条带卷的创建与存储方式验证

  • 创建分布式条带卷
[root@node1 sdb1]# gluster volume create dis-stripe stripe 2  node1:/data/sdd1 node2:/data/sdd1 node3:/data/sdd1 node4:/data/sdd1 force
volume create: dis-stripe: success: please start the volume to access data
[root@node1 sdb1]# gluster volume start dis-stripe 
volume start: dis-stripe: success
  • 验证
客户端
[root@client /]# mkdir -p /test/dis-stripe
[root@client /]# mount.glusterfs node1:dis-stripe  /test/dis-stripe/
[root@client /]#  cp -p demo* /test/dis-stripe/


验证
[root@node1 sdb1]# cd /data/sdd1/
[root@node1 sdd1]# ls -lh
总用量 80M
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo1.log
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo2.log
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo3.log
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo4.log

[root@node2 sdb1]# cd /data/sdd1/
[root@node2 sdd1]# ls -lh
总用量  80M
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo1.log
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo2.log
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo3.log
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo4.log

[root@node3 sdb1]# cd /data/sdd1/
[root@node3 sdd1]# ls -lh
总用量 20M
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo5.log


[root@node4 sdb1]# cd /data/sdd1/
[root@node4 sdd1]# ls -lh
总用量 20M
-rw-r--r--. 2 root root 20M 9月  14 09:51 demo5.log

3.7.5 分布式复制卷的创建与存储方式验证

  • 创建分布式复制卷
###########################分布式复制卷#######
[root@node1 sdd1]# gluster volume create dis-rep replica 2  node1:/data/sde1 node2:/data/sde1 node3:/data/sde1  node4:/data/sde1  force
volume create: dis-rep: success: please start the volume to access data
[root@node1 sdd1]# gluster volume start dis-rep 
volume start: dis-rep: success

  • 验证
#######客户端#############

[root@client /]# mkdir -p /test/dis-rep
[root@client /]# mount.glusterfs node1:dis-rep  /test/dis-rep/


验证
[root@node1 sdd1]# cd /data/sde1/
[root@node1 sde1]# ls -lh
总用量 160M
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo1.log
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo2.log
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo3.log
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo4.log

[root@node2 sdd1]# cd /data/sde1/
[root@node2 sde1]# ls -lh
总用量 160M
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo1.log
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo2.log
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo3.log
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo4.log


[root@node3 sdd1]# cd /data/sde1/
[root@node3 sde1]# ls -lh
总用量 120M
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo5.log
-rw-r--r--. 2 root root 40M 9月  14 10:36 demo6.log
-rw-r--r--. 2 root root 40M 9月  14 10:37 demo7.log

[root@node4 sdb1]# cd /data/sde1/
[root@node4 sde1]# ls -lh
总用量 120M
-rw-r--r--. 2 root root 40M 9月  14 09:51 demo5.log
-rw-r--r--. 2 root root 40M 9月  14 10:36 demo6.log
-rw-r--r--. 2 root root 40M 9月  14 10:37 demo7.log

3.8 破坏测试

关闭node2 节点
除了复制卷 其他多多少少都会出现问题
条带卷全军覆没,分布式存在挂的节点上的数据没有了

3.9 访问控制

[root@node1 sde1]# gluster volume set dis-rep auth.reject 192.168.233.30  ## 禁止 192.168.233.30 使用dis-rep卷(黑名单)
volume set: success
### 客户端 挂载这个卷失败
[root@client /]# mount.glusterfs node1:dis-rep  /test/dis-rep/
Mount failed. Please check the log file for more details.
[root@node1 sde1]# gluster volume set dis-rep auth.allow  192.168.233.30  ## 仅允许 192.168.233.30 使用dis-rep卷(白名单)

猜你喜欢

转载自blog.csdn.net/weixin_47219725/article/details/108585468