GFS 分布式文件系统

一、GlusterFS 概述

1.1、GlusterFS 简介

开源的分布式文件系统

有存储服务器、客户端以及NFS/Samba 存储网关组成

无元数据服务器

1.2、GlusterFS 特点

扩展性和高性能

高可用性

全局统一命名空间

弹性卷管理

基于标准协议

1.3、常用术语

Brick:GFS中的存储单元,通过是一个受信存储池中的服务器的一个导出目录。可以通过主机名和目录名来标识,如’SERVER:EXPORT’

Volume:卷

FUSE:内核文件系统,Filesystem Userspace是一个可加载的内核模块,其支持非特权用户创建自己的文件系统而不需要修改内核代码。通过在用户空间运行文件系统的代码通过FUSE代码与内核进行桥接。

VFS:虚拟文件系统

Glusterd:Gluster management daemon,要在trusted storage pool中所有的服务器上运行。

1.4、GFS 的结构及弹性HASH算法

■ 模块化堆栈式架构

模块化、堆栈式的架构

通过对模块的组合,实现复杂的功能d
在这里插入图片描述
■弹性HASH算法

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

二、GlusterFS 工作原理

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

三、GlusterFS 的卷类型

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

3.1、分布式卷

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

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

创建分布式卷命令:

gluster volume create dis-volume server1:/dir1 server2:/dir2

3.2、条带卷

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

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

创建条带卷命令:

 gluster volume create stripe-volume stripe 2 transport tcp server1:/dir1 server2:/dir2

3.3、复制卷

同一文件保存一份或多分副本

复制模式因为要保存副本,所以磁盘利用率较低

多个节点上的存储空间不一致,那么将按照木桶效应取最低节点的容量作为该卷的总容量
在这里插入图片描述
复制卷的特点:

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

创建复制卷命令:

gluster volume create rep-volume replica 2 transport tcp server1:/dir1 server2:/dir2

3.4、分布式条带卷

兼顾分布式卷和条带卷的功能
主要用于大文件访问处理
至少最少需要4台服务器
在这里插入图片描述

创建分布式条带卷的命令:

gluster volume create rep-volume replica 2 transport tcp server1:/dir1 server2:/dir2

3.5、分布式复制卷

兼顾分布式卷和复制卷的功能

用于需要冗余的情况下
在这里插入图片描述
创建分布式复制卷的命令:

gluster volume create rep-volume replica 2 transport tcp server1:/dir1 server2:/dir2

3.6、命令补充

删除卷时,信任池中不能有主机处于宕机状态,否则删除不成功


gluster volume stop dis-vol
yes

gluster volume delete dis-vol


#######访问控制##########
//仅拒绝
gluster volume set dis-vol auth.reject 20.0.0.25

//仅允许
gluster volume set dis-vol auth.allow 20.0.0.25

四、GlusterFS 平台部署

4.1、实验环境

VMware软件

一台centos7.4虚拟机,IP地址为:20.0.0.21,主机名为:node1,添加4块磁盘,均为20G大小

一台centos7.4虚拟机,IP地址为:20.0.0.22,主机名为:node2,添加4块磁盘,均为20G大小

一台centos7.4虚拟机,IP地址为:20.0.0.23,主机名为:node3,添加4块磁盘,均为20G大小

一台centos7.4虚拟机,IP地址为:20.0.0.24,主机名为:node4,添加4块磁盘,均为20G大小

一台centos7.4虚拟机,IP地址为:20.0.0.25,主机名为:client,当做测试机使用

防火墙,内核防护关闭

4.2、开局配置

所有的节点node都操作下面这些步骤,这里以node1:20.0.0.21为列

[root@node1 ~]# vi /etc/hosts
20.0.0.21 node1
20.0.0.22 node2
20.0.0.23 node3
20.0.0.24 node4

更改主机名
hostnamectl set-hostname node1
hostnamectl set-hostname node2
hostnamectl set-hostname node3
hostnamectl set-hostname node4

创建自动格式化,自动永久挂载脚本

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

[root@node1 ~]# chmod +x gsf.sh 
[root@node1 ~]# ./gsf.sh
[root@node1 ~]# scp gsf.sh 20.0.0.22:/
[root@node1 ~]# scp gsf.sh 20.0.0.23:/
[root@node1 ~]# scp gsf.sh 20.0.0.24:/

搭建线网yum仓库

[root@node1 abc]# cd /etc/yum.repos.d/
[root@node1 yum.repos.d]# mkdir bak
[root@node1 yum.repos.d]# mv C* /bak
[root@node1 yum.repos.d]# vim local.repo

[centos]
name=CentOS
baseurl=http://mirror.centos.org/centos/$releasever/storage/$basearch/gluster-3.12/
gpgcheck=0
enabled=1


[root@node1 yum.repos.d]# yum clean all
[root@node1 yum.repos.d]# yum list

[root@node1 yum.repos.d]# yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma
[root@node1 yum.repos.d]# ntpdate ntp1.aliyun.com

4.3、配置节点信息 任意一台

[root@node1 ~]# gluster peer probe node2   ##添加池子,peer匹配, probe信任+节点名称
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: 542a7be9-1a0c-43be-89db-57fe4db5a56f
State: Peer in Cluster (Connected)

Hostname: node3
Uuid: 2ca567f1-e92e-4215-9b09-e6c5e1f08f35
State: Peer in Cluster (Connected)

Hostname: node4
Uuid: 9110ff49-ab25-45d0-85fb-ad67fc266d7c
State: Peer in Cluster (Connected)
[root@node1 ~]# gluster peer status
Number of Peers: 3

换任意节点都可以看到池子

4.4、创建分布式卷

[root@node2 ~]# 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@node2 ~]# gluster volume info dis-vol 
Volume Name: dis-vol                                                           
Type: Distribute                                                                        
Volume ID: 028c2554-a6d6-48cd-a3ad-8778998c42da          
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
nfs.disable: on

开启分布式卷组
[root@node2 ~]# gluster volume start dis-vol 
volume start: dis-vol: success

查看是不是开启状态
[root@node2 ~]# gluster volume info dis-vol 
Volume Name: dis-vol
Type: Distribute
Volume ID: 028c2554-a6d6-48cd-a3ad-8778998c42da
Status: Started
Snapshot Count: 0

4.5、创建条带卷

[root@node2 ~]# 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@node2 ~]# gluster volume info stripe-vol 
 Volume Name: stripe-vol
Type: Stripe
Volume ID: 4b9fe354-a14c-4cfa-9dbc-b887cf101d7c
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@node2 ~]# gluster volume start stripe-vol 
volume start: stripe-vol: success
[root@node2 ~]# gluster volume info stripe-vol 
 Volume Name: stripe-vol
Type: Stripe
Volume ID: 4b9fe354-a14c-4cfa-9dbc-b887cf101d7c
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2

4.6、创建复制卷

[root@node2 ~]# 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@node2 ~]# gluster volume info rep-vol 
 Volume Name: rep-vol
Type: Replicate
Volume ID: bb87f9dc-8260-44b8-8ba3-53aab9ae10be
Status: Created
Snapshot Count: 0
Xlator 1: BD
Capability 1: thin
Capability 2: offload_copy
Capability 3: offload_snapshot
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: node3:/data/sdb1
Brick1 VG: 
Brick2: node4:/data/sdb1
Brick2 VG: 
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off


[root@node2 ~]# gluster volume start rep-vol 
volume start: rep-vol: success

4.7、创建分布式条带

[root@node2 ~]# 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@node2 ~]# gluster volume info dis-stripe 
 Volume Name: dis-stripe
Type: Distributed-Stripe
Volume ID: 37af4c7c-4dcc-47a6-89b7-91443343b0a0
Status: Created
Snapshot Count: 0
Number of Bricks: 2 x 2 = 4
Transport-type: 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

[root@node2 ~]# gluster volume start dis-stripe 
volume start: dis-stripe: success
[root@node2 ~]# gluster volume info dis-stripe 
 
Volume Name: dis-stripe
Type: Distributed-Stripe
Volume ID: 37af4c7c-4dcc-47a6-89b7-91443343b0a0
Status: Started
Snapshot Count: 0
Number of Bricks: 2 x 2 = 4
Transport-type: 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

4.8、创建分布式复制卷

[root@node2 ~]# 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@node2 ~]# gluster volume info dis-rep 
 
Volume Name: dis-rep
Type: Distributed-Replicate
Volume ID: 12e0a204-b09d-427e-a43d-743fd709a096
Status: Created
Snapshot Count: 0
Number of Bricks: 2 x 2 = 4
Transport-type: 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

[root@node2 ~]# gluster volume start dis-rep 
volume start: dis-rep: success
[root@node2 ~]# gluster volume info dis-rep 
 
Volume Name: dis-rep
Type: Distributed-Replicate
Volume ID: 12e0a204-b09d-427e-a43d-743fd709a096
Status: Started
Snapshot Count: 0
Number of Bricks: 2 x 2 = 4
Transport-type: 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

五、测试

测试机(20.0.0.25)只需要这两个

[root@localhost ~]# yum -y install glusterfs glusterfs-fuse
[root@localhost ~]# vi /etc/hosts

20.0.0.21 node1
20.0.0.22 node2
20.0.0.23 node3
20.0.0.24 node4
[root@localhost ~]# mkdir -p /test/dis                    
[root@localhost ~]# mkdir -p /test/strip
[root@localhost ~]# mkdir -p /test/rep
[root@localhost ~]# mkdir -p /test/dis_stripe
[root@localhost ~]# mkdir -p /test/dis_rep
[root@localhost ~]# mount.glusterfs node1:dis-vol /test/dis                     
[root@localhost ~]# mount.glusterfs node2:stripe-vol /test/strip              
[root@localhost ~]# mount.glusterfs node3:rep-vol /test/rep                   
[root@localhost ~]# mount.glusterfs node4:dis-stripe /test/dis_stripe    
[root@localhost ~]# mount.glusterfs node1:dis-rep /test/dis_rep   

创建5个大小为40M的文件

[root@localhost opt]# dd if=/dev/zero of=/opt/1.log bs=1M count=40
[root@localhost opt]# dd if=/dev/zero of=/opt/2.log bs=1M count=40
[root@localhost opt]# dd if=/dev/zero of=/opt/3.log bs=1M count=40
[root@localhost opt]# dd if=/dev/zero of=/opt/4.log bs=1M count=40
[root@localhost opt]# dd if=/dev/zero of=/opt/5.log bs=1M count=40

复制5个文件,存到刚才创的文件进行存储

[root@localhost opt]# cp * /test/dis
[root@localhost opt]# cp * /test/strip/
[root@localhost opt]# cp * /test/rep/
[root@localhost opt]# cp * /test/dis_stripe/
[root@localhost opt]# cp * /test/dis_rep/

查看分布式卷

[root@node1 ~]# cd /data/sdb1/
[root@node1 sdb1]# ll -h
total 160M
-rw-r--r-- 2 root root 40M Oct 27 13:28 1.log
-rw-r--r-- 2 root root 40M Oct 27 13:28 3.log
-rw-r--r-- 2 root root 40M Oct 27 13:28 4.log
-rw-r--r-- 2 root root 40M Oct 27 13:28 5.log
[root@node2 ~]# cd /data/sdb1/
[root@node2 sdb1]# ll -h
总用量 40M
-rw-r--r-- 2 root root 40M 10月 28 01:28 2.log

查看条带卷

[root@node1 sdb1]# cd /data/
[root@node1 data]# ll -h sdc1/
total 100M
-rw-r--r-- 2 root root 20M Oct 27 13:28 1.log
-rw-r--r-- 2 root root 20M Oct 27 13:28 2.log
-rw-r--r-- 2 root root 20M Oct 27 13:28 3.log
-rw-r--r-- 2 root root 20M Oct 27 13:28 4.log
-rw-r--r-- 2 root root 20M Oct 27 13:28 5.log

[root@node2 sdb1]# cd /data/
[root@node2 data]# ll -h sdc1/
总用量 100M
-rw-r--r-- 2 root root 20M 10月 28 01:28 1.log
-rw-r--r-- 2 root root 20M 10月 28 01:28 2.log
-rw-r--r-- 2 root root 20M 10月 28 01:28 3.log
-rw-r--r-- 2 root root 20M 10月 28 01:28 4.log
-rw-r--r-- 2 root root 20M 10月 28 01:28 5.log

开始破坏性实验,验证卷组

init 0 node1 并去测试机20.0.0.25查看结果
查看分布式卷

[root@localhost test]# ls -lh dis/
total 40M
-rw-r--r-- 1 root root 40M Oct 27 13:28 2.log

查看条带卷

[root@localhost test]# ll
ls: cannot access strip: Transport endpoint is not connected
total 16
drwxr-xr-x 3 root root 4096 Oct 27 13:28 dis
drwxr-xr-x 3 root root 4096 Oct 27 13:28 dis_rep
drwxr-xr-x 3 root root 4096 Oct 27 13:28 dis_stripe
drwxr-xr-x 3 root root 4096 Oct 27 13:28 rep
d????????? ? ?    ?       ?            ? strip

测试成功

猜你喜欢

转载自blog.csdn.net/weixin_48191211/article/details/109335325