GFS分布式文件系统

一、GlusterFS概述

GlusterFS简介

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

GlusterFS特点

  • 扩展性和高性能
  • 高可用性
  • 全局统一命名空间
  • 弹性卷管理
  • 基于标准协议

GlusterFS术语

  • Brick
  • Volume
  • FUSE
  • VFS
  • Glusterd

模块化堆栈式架构

  • 模块化、堆栈式的架构
  • 通过对模块的组合,实现复杂的功能

二、GlusterFS工作原理

GlusterFS工作流程

  • 客户端或应用程序通过GlusterFS的挂载点访问数据
  • Linux系统内核通过VFS API收到请求并处理
  • VFS将数据递交给FUSE内核文件系统,FUSE文件系统则是将数据通过/dev/fuse设备文件递交给了GlusterFS client端
  • GlusterFS client收到数据后,client根据配置文件的配置对数据进行处理
  • 通过网络将数据传递至远端的GlusterFS Server,并且将数据写入到服务器存储设备上

弹性HASH算法

  • 通过HASH算法得到一个32位的整数
  • 划分为N个连续的子空间,每个空间对应一个Brick
  • 弹性HASH算法的优点
    1.保证数据平均分布在每一个Brick中
    2.解决了对元数据服务器的依赖,进而解决了单点故障以及访问瓶颈
  • 四个Brick节点的GlusterFS卷,平均分配232次方的区间的范围空间
  • 访问文件时,通过计算该文件的HASH值,从而对应到Brick存储空间

三、GlusterFS的卷类型

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

分布式卷

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

条带卷

  • 根据偏移量将文件分成N快(N个条带节点),轮询的存储在每个Brick Server节点
  • 存储大文件时,性能尤为突出
  • 不具备冗余性,类似Raid0

从多个server中同时读取文件,效率提升

  • 特点
    1.数据被分割成更小快分布到快服务器群中的不同条带区
    2.分布减少了负载且更小的文件加速,存储的速度
    3.没有数据冗余
  • 创建条带卷
    创建了一个名为Stripe-volume的条带卷,文件将被分块轮询的存储在Server1:/dir1和Server2:/dir2两个Brick中
    gluster volume create stripe-volume stripe 2 transport tcp server1:/dir1 server2:/dir2
    

复制卷

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

分布式条带卷

  • 分布式条带卷
    1.兼顾分布式卷和条带卷的功能
    2.主要用于大文件访问处理
    3.至少需要4太服务器
  • 创建分布式条带卷
    创建了名为dis-stripe的分布式条带卷,配置分布式的条带卷时,卷中Brick所包含的存储服务器数必须是条带卷数的倍数(>=2倍)
    gluster volume create dis-stripe stripe 2 transport tcp server1:/dir1 server2:/dir2 server3:/dir3 server4:/dir4
    

分布式复制卷

  • 分布式复制卷
    1.兼顾分布式卷和复制卷的功能
    2.用于需要冗余的情况
  • 创建分布式复制卷
    创建名为dis-rep的分布式条带卷,配置分布式复制卷时,卷中Brick所包含的存储服务器数必须时条带数的倍数(>=2倍)
    gluster volume create dis-rep replica 2 transport tcp server1:/dir1 server2:/dir2 server3:/dir3 server4:/dir4
    

四、部署群集环境流程

群集环境

node1:192.168.10.10
node2:192.168.10.20
node3:192.168.10.30
node4:192.168.10.40
client:192.168.10.50

卷类型

dis-volume 分布式卷

stripe-volume 条带卷

rep-volume 复制卷

dis-stripe 分布式条带卷

dis-rep 分布式复制卷

部署群集环境

1.准备环境
2.关闭防火墙和Selinux
3.配置hosts文件
4.安装软件
5.启动GlusterFS
6.添加节点
7.查看集群状态

部署GFS

node节点配置

1.修改主机名,关闭防火墙并修改hosts文件,在四台node节点上添加映射
[root@localhost ~]# hostnamectl set-hostname node1
[root@localhost ~]# su
[root@node1 ~]# setenforce 0
[root@node1 ~]# systemctl stop firewalld

[root@node1 ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.10 node1
192.168.10.20 node2
192.168.10.30 node3
192.168.10.40 node4
2.所有node节点上都添加四块硬盘并完成挂载
init6 ## 重启
[root@node1 ~]# fdisk -l

磁盘 /dev/sda:64.4 GB, 64424509440 字节,125829120 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000b00a4

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   125829119    61864960   8e  Linux LVM

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/sdd:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/sdc:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/sde:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

所有节点上的硬盘格式化

[root@node1 ~]# mkfs.ext4 /dev/sdb
[root@node1 ~]# mkfs.ext4 /dev/sdc
[root@node1 ~]# mkfs.ext4 /dev/sdd
[root@node1 ~]# mkfs.ext4 /dev/sde

所有节点上创建挂载点并挂载

[root@node1 ~]# mkdir {/b1,/c1,/d1,/e1}
[root@node1 ~]# mount /dev/sdb /b1
[root@node1 ~]# mount /dev/sdc /c1
[root@node1 ~]# mount /dev/sdd /d1
[root@node1 ~]# mount /dev/sde /e1
[root@node1 ~]# df -Th  
/dev/sdb                ext4       20G   45M   19G    1% /b1
/dev/sdc                ext4       20G   45M   19G    1% /c1
/dev/sdd                ext4       20G   45M   19G    1% /d1
/dev/sde                ext4       20G   45M   19G    1% /e1
3.安装并启动gluster
[root@node1 ~]# unzip gfsrepo.zip
[root@node1 ~]# yum clean all
[root@node1 ~]# yum makecache
[root@node1 ~]# vi /etc/yum.repos.d/gfs.repo
[gfs]
name=gfs
baseurl=file:///root/gfsrepo
gpgcheck=0
enabled=1
[root@node1 ~]# yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma
[root@node1 ~]# systemctl start glusterd.service 
[root@node1 ~]# systemctl enable glusterd.service 
[root@node1 ~]# systemctl status glusterd.service
4.将节点添加到信任池

node1节点操作即可

[root@node1 yum.repos.d]# gluster peer probe node2
 peer probe: success. 
[root@node1 yum.repos.d]# gluster peer probe node3
peer probe: success. 
[root@node1 yum.repos.d]# gluster peer probe node4
peer probe: success. 

查看所有节点

[root@node1 yum.repos.d]# gluster peer status
Number of Peers: 3
   
Hostname: node2
Uuid: 8e720eb2-e73e-431c-8c1d-788ffc386580
State: Peer in Cluster (Connected)
   
Hostname: node3
Uuid: 60354787-f8ad-4214-b3c6-42cb8996f233
State: Peer in Cluster (Connected)
   
Hostname: node4
Uuid: f61ecc1a-dee7-4ba6-b38e-4816ae1c986f
State: Peer in Cluster (Connected)

client客户端配置

1.修改主机名,关闭防火墙并修改hosts文件,在客户机上添加地址映射

[root@localhost ~]# hostnamectl set-hostname client
[root@localhost ~]# su
[root@client ~]# setenforce 0
[root@client ~]# systemctl stop firewalld
[root@client ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.10 node1
192.168.10.20 node2
192.168.10.30 node3
192.168.10.40 node4
[root@client ~]# unzip gfsrepo.zip
[root@client ~]# yum clean all
[root@client ~]# yum makecache
[root@client ~]# vi /etc/yum.repos.d/gfs.repo
[gfs]
name=gfs
baseurl=file:///root/gfsrepo
gpgcheck=0
enabled=1
[root@client ~]# yum -y install glusterfs glusterfs-fuse
[root@client ~]# dd if=/dev/zero of=/test1.txt bs=1M count=40
[root@client ~]# dd if=/dev/zero of=/test2.txt bs=1M count=40
[root@client ~]# dd if=/dev/zero of=/test3.txt bs=1M count=40
[root@client ~]# dd if=/dev/zero of=/test4.txt bs=1M count=40
[root@client ~]# dd if=/dev/zero of=/test5.txt bs=1M count=40

创建卷

创建分布式卷
[root@node1 ~]# gluster volume create dis-vol node1:/b1 node2:/b1 force
volume create: dis-vol: success: please start the volume to access data
##列表
[root@node1 yum.repos.d]# gluster volume list
dis-vol
[root@node1 ~]# gluster volume info dis-vol 
 
Volume Name: dis-vol
Type: Distribute
Volume ID: 215c49ee-4695-4720-94f4-e9c3d70ce513
Status: Created
Snapshot Count: 0
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: node1:/b1
Brick2: node2:/b1
Options Reconfigured:
transport.address-family: inet
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: 215c49ee-4695-4720-94f4-e9c3d70ce513
Status: Started
Snapshot Count: 0
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: node1:/b1
Brick2: node2:/b1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on

### client端:客户端挂载分布式卷到/test/dis/下,将创建的五个测试文件拷贝到/test/dis/下
[root@client ~]# mkdir -p /test/dis
[root@client ~]# mount.glusterfs node1:dis-vol /test/dis/
[root@client ~]# cp /test* /test/dis/

### node1:查看发布状态
[root@node1 ~]# ll -h /b1   
总用量 121M
drwx------ 2 root root 16K 1月   6 11:26 lost+found
-rw-r--r-- 2 root root 40M 1月   6 11:53 test1.txt
-rw-r--r-- 2 root root 40M 1月   6 11:53 test3.txt
-rw-r--r-- 2 root root 40M 1月   6 11:53 test4.txt
### node2:
[root@node2 ~]# ll -h /b1
总用量 81M
drwx------ 2 root root 16K 1月   6 11:26 lost+found
-rw-r--r-- 2 root root 40M 1月   6 11:53 test2.txt
-rw-r--r-- 2 root root 40M 1月   6 11:53 test5.txt
创建复制卷
[root@node1 ~]# gluster volume create rep-vol replica 2 node3:/b1 node4:/b1 force
volume create: rep-vol: success: please start the volume to access data
[root@node1 ~]# gluster volume start rep-vol
volume start: rep-vol: success
[root@node1 ~]# gluster volume status rep-vol
Status of volume: rep-vol
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick node3:/b1                             49152     0          Y       14160
Brick node4:/b1                             49152     0          Y       3215 

client端:
[root@client ~]# mkdir /test/rep-vol
[root@client ~]# cp /test* /test/rep-vol/
[root@client ~]# mount.glusterfs node1:rep-vol /test/rep-vol/

node3:
[root@node3 ~]# ll -h /b1
总用量 201M
drwx------ 2 root root 16K 1月   6 11:26 lost+found
-rw-r--r-- 2 root root 40M 1月   6 12:07 test1.txt
-rw-r--r-- 2 root root 40M 1月   6 12:07 test2.txt
-rw-r--r-- 2 root root 40M 1月   6 12:07 test3.txt
-rw-r--r-- 2 root root 40M 1月   6 12:07 test4.txt
-rw-r--r-- 2 root root 40M 1月   6 12:07 test5.txt
node4:
[root@node4 ~]# ll -h /b1
总用量 201M
drwx------. 2 root root 16K 1月   6 11:27 lost+found
-rw-r--r--. 2 root root 40M 1月   6 12:07 test1.txt
-rw-r--r--. 2 root root 40M 1月   6 12:07 test2.txt
-rw-r--r--. 2 root root 40M 1月   6 12:07 test3.txt
-rw-r--r--. 2 root root 40M 1月   6 12:07 test4.txt
-rw-r--r--. 2 root root 40M 1月   6 12:07 test5.txt
创建分布式复制卷
[root@node1 ~]# gluster volume create dis-rep replica 2 node1:/e1 node2:/e1 node3:/
e1 node4:/e1 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
[root@node1 ~]# gluster volume status dis-rep 
Status of volume: dis-rep
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick node1:/e1                             49153     0          Y       14889
Brick node2:/e1                             49153     0          Y       14299
Brick node3:/e1                             49153     0          Y       14273
Brick node4:/e1                             49153     0          Y       3340

client端:
[root@client ~]# mkdir /test/dis-rep
[root@client ~]# cp /test* /test/dis-rep/
[root@client ~]# mount.glusterfs node1:dis-rep /test/dis-rep/
node1和node2:
[root@node1 ~]# ll -h /e1
总用量 121M
drwx------ 2 root root 16K 1月   6 11:27 lost+found
-rw-r--r-- 2 root root 40M 1月   6 12:13 test1.txt
-rw-r--r-- 2 root root 40M 1月   6 12:13 test3.txt
-rw-r--r-- 2 root root 40M 1月   6 12:13 test4.txt


node3和node4:
[root@node3 ~]# ll -h /e1
总用量 81M
drwx------ 2 root root 16K 1月   6 11:27 lost+found
-rw-r--r-- 2 root root 40M 1月   6 12:13 test2.txt
-rw-r--r-- 2 root root 40M 1月   6 12:13 test5.txt

破坏测试(客户机上)

[root@client ~]# ll -h /test/dis/
总用量 121M
drwx------. 2 root root 4.0K 1月   6 11:26 lost+found
-rw-r--r--. 1 root root  40M 1月   6 11:53 test1.txt
-rw-r--r--. 1 root root  40M 1月   6 11:53 test3.txt
-rw-r--r--. 1 root root  40M 1月   6 11:53 test4.txt
[root@client ~]# ll -h /test/dis-rep/
总用量 201M
drwx------. 2 root root 4.0K 1月   6 11:27 lost+found
-rw-r--r--. 1 root root  40M 1月   6 12:13 test1.txt
-rw-r--r--. 1 root root  40M 1月   6 12:13 test2.txt
-rw-r--r--. 1 root root  40M 1月   6 12:13 test3.txt
-rw-r--r--. 1 root root  40M 1月   6 12:13 test4.txt
-rw-r--r--. 1 root root  40M 1月   6 12:13 test5.txt
[root@client ~]# ll -h /test/rep-vol/
总用量 201M
drwx------. 2 root root 4.0K 1月   6 11:27 lost+found
-rw-r--r--. 1 root root  40M 1月   6 12:07 test1.txt
-rw-r--r--. 1 root root  40M 1月   6 12:07 test2.txt
-rw-r--r--. 1 root root  40M 1月   6 12:07 test3.txt
-rw-r--r--. 1 root root  40M 1月   6 12:07 test4.txt
-rw-r--r--. 1 root root  40M 1月   6 12:07 test5.txt

访问控制

## 拒绝某个用户
[root@node1 ~]# gluster volume set dis-rep auth.reject 192.168.10.50
volume set: success
## 允许某个用户
[root@node1 ~]# gluster volume set dis-rep auth.allow 192.168.10.50
volume set: success
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值