GlusterFS 分布式文件系统的卷类型及配置详解

一、GlusterFS相关概念:

GlusterFS 是一个开源的分布式文件系统,同时也是Scale-Out存储解决方案Gluster的核心,在存储数据方面有强大的横向扩展能力。GlusterFS主要由存储服务器、客户端及NFS/Samba存储网关(可选组件)组成。GlusterFS架构中最大的设计特点是没有元数据服务器组件,也就是说没有主/从服务器之分,每一个节点都可以是主服务器。
.
1、Gluster相关参考文档如下(我下面的配置是基于本地yum配置的,若需要搭建最新版本,可直接按照下面的文档链接进行配置):
.
**Gluster官网 ?*https://wiki.centos.org/SpecialInterestGroup/Storage/gluster-Quickstart
**基于centos7/Redhat安装Gluster官方文档:**https://blog.csdn.net/daydayup_gzm/article/details/52748812
.
2、 GlusterFS相关术语:
.

Brick(存储块):指可信主机池中由主机提供的用于物理存储的专用分区。
Volume(逻辑卷):一个逻辑卷是一组Brick的集合。卷是数据存储的逻辑设备。
FUSE:是一个内核模块,允许用户自己创建文件系统,无须修改内核代码。
Glusterd(后台管理进程):在存储群集中的每个节点上都要运行。
VFS:内核空间对用户空间提供的访问磁盘的接口。

3、GlusterFS的卷类型:

  • 分布式卷:相当于Windows中的跨区卷,只是扩大了磁盘空间,不具有容错能力;
  • 条带卷:相当于Windows中的带区卷,属于RAID 0级别,一份文件会在多个磁盘上进行读写,文件越大,读写效率越高,但不具有容错能力;
  • 复制卷:相当于Windows中的镜像卷,属于RAID 1级别,具有容错能力,读性能高,但写性能下降,因为要将同一份文件同步写入在多个Brick上。
  • 分布式条带卷:brick server数量是条带数(数据块分布的brick数量)的倍数,兼具分布式卷和条带卷的特点。
  • 分布式复制卷:brick server数量是镜像数(数据副本数量)的倍数,兼具分布式卷和复制卷的特点。
  • 条带复制卷:类似于RAID 10,同时具备条带卷和复制卷的特点。
  • 分布式条带复制卷:三种基本卷的复合卷,通常用于map reduce应用。
    在以上几种卷类型中,有些可能无法理解透彻,但是没关系,在生产环境中,大多数公司考虑到磁盘的利用率,会使用RAID5,或者RAID 10,关于RAID 5卷的配置可以参考:GlusterFS Dispersed Volume(纠错卷)总结。

4、下面介绍GlusterFS一些卷类型的特点(不包括RAID5):

1、分布式卷(类似Windows中的跨区卷):
.
分布式卷是GlusterFS的默认卷,在创建卷时,默认选项是创建分布式卷。在该模式下,并没有对文件进行分块处理,文件直接存储在某个server节点上。
.
分布式卷具有如下特点:
.

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

2、条带卷(类似Windows中的带区卷,也称为RAID 0):
.
stripe模式相当于RAID 0,在该模式下,根据偏移量将文件分成N块(N个条带节点),轮询地存储在每个Brick Server节点。节点把每个数据块都作为普通文件存入本地文件系统,通过扩展属性记录总块数和每块的序号。在配置时指定条带数必须等于卷中Brick 所包含的存储服务器数,在存储大文件时,性能尤为突出,但是不具备冗余性。
.
条带卷具有如下特点:
.

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

3、复制卷(类似于Windows中的镜像卷,也称为RAID 1)
.
复制模式,即同一文件保存一份或多份副本,每个节点上保存相同的内容和目录结构。复制模式因为要保存副本,所以磁盘利用率较低,如果多个节点上的存储空间不一致,那么将按照木桶效应取最低节点的容量作为该卷的总容量。复制卷具有冗余性,即使一个节点损坏,也不影响数据的正常使用。
.
复制卷具有如下特点:

1、卷中所有的服务器均保存一个完整的副本。
2、卷的副本数量可由客户创建的时候决定。
3、至少有两个块服务器或更多服务器。
4、具备冗余性。
4、分布式复制卷(也称为RAID 10):

分布式复制卷兼顾分布式卷和复制卷的功能,主要用于需要冗余的情况下。
.
二、GlusterFS各种卷类型的部署及客户端挂载使用:
.
环境如下:

相关信息:

磁盘挂载信息:

.
准备工作:
**1、在所有节点上进行操作:**根据上表中添加磁盘,通过fdisk命令进行分区,mkfs格式化,创建相应的挂载目录,并将格式化的磁盘挂载到相应的目录中,最后修改/etc/fstab配置文件,使其永久挂载。
可参考博文:https://blog.51cto.com/14154700/2350748
2、配置防火墙放行流量
3、本地yum仓库:https://pan.baidu.com/s/1ZzURDjGsue7cPnVPdKFCvA **(提取码:309q) **
开始部署:
.
node1的配置:

配置hosts文件
[root@node1 /]# vim /etc/hosts                 # 添加四个节点的解析
...............      //  省略部分内容
192.168.1.10    node1
192.168.1.20    node2
192.168.1.30    node3
192.168.1.40    node4
[root@node1 /]# mount /dev/sr0 /media/           # 挂在本地yum仓库
mount: /dev/sr0 is write-protected, mounting read-only
[root@node1 /]# rm -rf /etc/yum.repos.d/*         #删除原有yum配置文件(或者移走也行)
[root@node1 /]# vim /etc/yum.repos.d/a.repo           # 编写yum配置文件
[yum]
baseurl=file:///media
gpgcheck=0

[root@node1 /]# yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma      # yum安装 gluster,所有节点都需要做
[root@node1 /]# systemctl start glusterd                  # 启动服务
[root@node1 /]# systemctl enable glusterd

node2的配置:
.
因为所有节点大部分配置都是相同的,所以我们可以使用scp命令来将配置好的节点文件复制来使用

[root@node2 /]# scp root@192.168.1.10:/etc/hosts /etc/              # 将hosts解析文件复制过来
The authenticity of host '192.168.1.10 (192.168.1.10)' can't be established.
ECDSA key fingerprint is 68:df:0f:ac:c7:75:df:02:88:7d:36:6a:1a:ae:27:23.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.10' (ECDSA) to the list of known hosts.
root@192.168.1.10's password:             # 输入密码
hosts                                                100%  234     0.2KB/s   00:00    
[root@node2 /]# rm -rf /etc/yum.repos.d/*
[root@node2 /]# scp root@192.168.1.10:/etc/yum.repos.d/* /etc/yum.repos.d/
root@192.168.1.10's password: 
a.repo                                               100%   39     0.0KB/s   00:00    
[root@node2 /]# mount /dev/sr0 /media                   # 挂载yum仓库
[root@node2 /]# yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma     # 安装软件
[root@node2 /]# systemctl start glusterd          # 启动服务
[root@node2 /]# systemctl enable glusterd

node3和node4照着node2配置操作就可以
.
添加节点(接下来的所有配置,在任意一台节点上执行都可以,我这里在node1上执行):

[root@node1 /]# gluster peer probe node1
peer probe: success. Probe on localhost not needed             # 表示当前就在node1上,已经存在,不需要再添加了
[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: b25b967a-0ec6-4e2e-841f-b13368ec6d73
State: Peer in Cluster (Connected)             #如果某个节点显示Disconnected,请检查hosts配置文件

Hostname: node3
Uuid: 3ce5c3aa-c1da-4112-825d-998e71220423
State: Peer in Cluster (Connected)

Hostname: node4
Uuid: 0c543cae-ec0c-4249-8600-605e0f552b11
State: Peer in Cluster (Connected)

创建卷:
1、创建分布式卷:

[root@node1 /]# gluster volume create dis-volume node1:/e6 node2:/e6 force        # force:强制      ; 其中“dis-volume”为卷名,没有指定类型,默认创建的是分布式卷。
volume create: dis-volume: success: please start the volume to access data
[root@node1 /]# gluster volume info dis-volume             # 查看该卷相关信息,通过修改卷名也可以查看其它卷的信息
 
Volume Name: dis-volume
Type: Distribute
Volume ID: 09a6443c-a544-475d-9084-28892ce0093f
Status: Started
Snapshot Count: 0
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: node1:/e6
Brick2: node2:/e6
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
[root@node1 /]# gluster volume start dis-volume             # 启用该卷
volume start: dis-volume: success

2、创建条带卷:

[root@node1 /]# gluster volume create stripe-volume stripe 2 node1:/d5 node2:/d5 force
volume create: stripe-volume: success: please start the volume to access data
#创建条带卷,指定条带卷的个数为2个。“stripe-volume”为卷名
#指定类型为stripe,数值为2,而且后面跟了2个brick  server,所以创建的是条带卷
[root@node1 /]# gluster volume start stripe-volume                    # 启用该卷
volume start: stripe-volume: success

3、创建复制卷:

[root@node1 /]# gluster volume create rep-volume replica 2 node3:/d5 node4:/d5 force
volume create: rep-volume: success: please start the volume to access data
#指定类型为“replica”,数值为“2”,而且后面跟了两个brick server,所以创建的是复制卷
[root@node1 /]# gluster volume start  rep-volume              # 启用该卷
volume start: rep-volume: success

4、创建分布式条带卷:

[root@node1 /]# gluster volume create dis-stripe stripe 2 node1:/b3 node2:/b3 node3:/b3 node4:/b3 force
volume create: dis-stripe: success: please start the volume to access data
#指定类型为stripe,数值为2,而且后面跟了4个brick server,所以创建的是分布式条带卷
[root@node1 /]# gluster volume start dis-stripe               # 启用
volume start: dis-stripe: success

5、创建分布式复制卷:

[root@node1 /]# gluster volume create dis-rep replica 2 node1:/c4 node2:/c4 node3:/c4 node4:/c4 force
volume create: dis-rep: success: please start the volume to access data
#指定类型为replica,数值为2,而且后面跟了4个brick  server,是2的两倍,所以创建的是分布式复制卷
[root@node1 /]# gluster volume start dis-rep
volume start: dis-rep: success

至此需要的卷就创建完毕了。
.
部署 Gluster 客户端:
.
1、安装客户端软件

[root@client /]# rm -rf /etc/yum.repos.d/*
[root@client /]# scp root@192.168.1.10:/etc/yum.repos.d/* /etc/yum.repos.d/
root@192.168.1.10's password: 
a.repo                                               100%   39     0.0KB/s   00:00  
# 挂载本地yum仓库
[root@client /]# yum -y install glusterfs glusterfs-fuse            # yum安装客户端

2、创建挂载目录:
[root@client /]# mkdir -p /test/{dis,stripe,rep,dis_and_stripe,dis_and_rep}
[root@client /]# ls /test/
dis dis_and_rep dis_and_stripe rep stripe
3、修改hosts文件:(直接scp复制也可以)

[root@client /]# scp root@192.168.1.10:/etc/hosts /etc/
The authenticity of host '192.168.1.10 (192.168.1.10)' can't be established.
ECDSA key fingerprint is 68:df:0f:ac:c7:75:df:02:88:7d:36:6a:1a:ae:27:23.
Are you sure you want to continue connecting (yes/no)? yesd
Warning: Permanently added '192.168.1.10' (ECDSA) to the list of known hosts.
root@192.168.1.10's password: 
hosts                                                100%  234     0.2KB/s   00:00  
[root@client /]# cat /etc/hosts
..................              // 省略部分
192.168.1.10	node1
192.168.1.20	node2
192.168.1.30	node3
192.168.1.40	node4

4、挂载 Gluster 文件系统:
[root@client /]# mount -t glusterfs node1:dis-volume /test/dis
[root@client /]# mount -t glusterfs node1:stripe-volume /test/stripe
[root@client /]# mount -t glusterfs node1:rep-volume /test/rep/
[root@client /]# mount -t glusterfs node1:dis-stripe /test/dis_and_stripe/
[root@client /]# mount -t glusterfs node1:dis-rep /test/dis_and_rep/
[root@client /]# df -h # 查看挂载信息,如果挂载不成功,请检查hosts解析文件
文件系统 容量 已用 可用 已用% 挂载点
… // 省略部分
node1:dis-volume 12G 65M 12G 1% /test/dis
node1:stripe-volume 10G 65M 10G 1% /test/stripe
node1:rep-volume 5.0G 33M 5.0G 1% /test/rep
node1:dis-stripe 12G 130M 12G 2% /test/dis_and_stripe
node1:dis-rep 8.0G 65M 8.0G 1% /test/dis_and_rep
5、修改fstab文件,设置自动挂载:
[root@client /]# vim /etc/fstab
… // 省略部分
node1:stripe-volume /test/stripe glusterfs defaults,_netdev 0 0
node1:rep-volume /test/rep glusterfs defaults,_netdev 0 0
node1:dis-stripe /test/dis_and_stripe glusterfs defaults,_netdev 0 0
node1:dis-rep /test/dis_and_rep glusterfs defaults,_netdev 0 0
node1:dis-volume /test/dis glusterfs defaults,_netdev 0 0

GlusterFS维护命令:

[root@node1 /]# gluster volume list             // 查看卷的列表
dis-rep
dis-stripe
dis-volume
rep-volume
stripe-volume
[root@node1 /]# gluster volume info                  // 查看所有卷的信息
 
Volume Name: dis-rep
Type: Distributed-Replicate
Volume ID: f57c0228-4a5f-4995-8fac-87f9bc034c33
Status: Started
Snapshot Count: 0
Number of Bricks: 2 x 2 = 4
Transport-type: tcp
Bricks:
Brick1: node1:/c4
Brick2: node2:/c4
Brick3: node3:/c4
Brick4: node4:/c4
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
................            // 省略部分
[root@node1 /]# gluster volume status                  // 查看卷的状态
Status of volume: dis-rep
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick node1:/c4                             49155     0          Y       13656
Brick node2:/c4                             49155     0          Y       13443
Brick node3:/c4                             49154     0          Y       13480
Brick node4:/c4                             49154     0          Y       13334
Self-heal Daemon on localhost               N/A       N/A        Y       13676
Self-heal Daemon on node2                   N/A       N/A        Y       13463
Self-heal Daemon on node4                   N/A       N/A        Y       13354
Self-heal Daemon on node3                   N/A       N/A        Y       13500
 
Task Status of Volume dis-rep
------------------------------------------------------------------------------
[root@node1 ~]# gluster volume stop dis-stripe             #停止一个卷
Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
volume stop: dis-stripe: success
[root@node1 ~]# gluster volume delete dis-stripe           #删除一个卷
Deleting volume will erase all information abe. Do you want to continue? (y/n) y
volume delete: dis-stripe: success
[root@node1 ~]# gluster volume set dis-rep auth.allow 192.168.1.*,10.1.1.*            
#设置只允许特定网段的客户端访问卷dis-rep
volume set: success
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值