分布式存储

分布式存储

Glusterfs分布式文件系统

GlusterFS简介

PB级容量  高可用性  基于文件系统级别共享  分布式

   GlusterFS(GNU ClusterFile System)是一种全对称的开源分布式文件系统,所谓全对称是指GlusterFS采用弹性哈希算法,没有中心节点,所有节点全部平等。GlusterFS配置方便,稳定性好,可轻松达到PB级容量,数千个节点。
   2011年被红帽收购,之后推出了基于GlusterFS的 Red Hat Storage Server,增加了针对KVM的许多特性。可用作为KVM存储image存储集群,也可以为LB或HA提供存储。


GlusterFS重要特性:
支持多种卷类型(类似RAID0/1/5/10)
支持卷级别的压缩
支持NFS
支持SMB
支持Hadoop
支持Openstack

GlusterFS重要概念:
brick:              GlusterFS的基本单元,以节点服务器目录形式展现。
Volume:             多个 bricks 的逻辑集合
GlusterFS Server:数据存储服务器,即组成GlusterFs存储集群的节点。
GlusterFS Client:   使用GlusterFS存储服务器的服务器。

准备环境

4台虚拟机(当然可以更多节点)
操作系统		 IP					主机名	
Centos7.4		192.168.62.203	   node1
Centos7.4		192.168.62.204	   node2
Centos7.4		192.168.62.135     node3
Centos7.4		192.168.62.166     node4

为了试验效果我们可以将其中一台机器作为客户端使用
所有机器关闭防火墙
# systemctl stop firewalld && setenforce 0
分别修改主机名称:
[root@192 ~]# hostnamectl set-hostname node1
[root@192 ~]# hostnamectl set-hostname node2
[root@192 ~]# hostnamectl set-hostname node3
[root@192 ~]# hostnamectl set-hostname node4
配置解析,所有机器:
[root@192 yum.repos.d]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.62.131 node01
192.168.62.231 node02
192.168.62.168 node03
192.168.62.166 node04
安装glusterfs服务(所有主机)
记得安装epel扩展源
[root@node1 ~]# yum install centos-release-gluster glusterfs-server samba rpcbind -y
这条命令需要敲两遍

#注意:当使用客户端的时候需要安装的包为:
yum install centos-release-gluster glusterfs-server samba rpcbind -y
安装两次,和集群一块做相互解析
在客户端安装上之后就可以使用挂载命令了。
安装之前记得开启yum缓存
内网环境,需要找到下载的这些rpm安装包
[root@node1 ~]# ls glusterfs/
glusterfs-3.10.3-1.el7.x86_64.rpm            glusterfs-client-xlators-3.10.3-1.el7.x86_64.rpm  
glusterfs-server-3.10.3-1.el7.x86_64.rpm  glusterfs-api-3.10.3-1.el7.x86_64.rpm  
glusterfs-fuse-3.10.3-1.el7.x86_64.rpm     userspace-rcu-0.7.16-3.el7.x86_64.rpm
glusterfs-cli-3.10.3-1.el7.x86_64.rpm        glusterfs-libs-3.10.3-1.el7.x86_64.rpm

所有节点启动服务并设置为开机自启
[root@node1 ~]# systemctl start glusterd.service
[root@node1 ~]# systemctl enable glusterd.service
[root@node1 ~]# glusterfs -V
glusterfs 7.3
创建Glusterfs集群
添加节点的过程就是创建集群的过程,在node01一台上操作就可以,不需要添加本节点
[[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: 1a99d57f-9575-4ba0-9cc9-9c2d3b4b4e3f
State: Peer in Cluster (Connected)

Hostname: node3
Uuid: 06f43aee-3edb-4cc5-b886-fee2e52c8b7f
State: Peer in Cluster (Connected)

Hostname: node4
Uuid: 64556459-b332-463f-9e2c-4067650544e0
State: Peer in Cluster (Connected)

从集群中删除节点
[root@node1 ~]# gluster peer detach node4
All clients mounted through the peer which is getting detached need to be remounted using one of the other active peers in the trusted storage pool to ensure client gets notification on any changes done on the gluster configuration and if the same has been done do you want to proceed? (y/n) y
peer detach: success
[root@node1 ~]# gluster peer status
Number of Peers: 2

Hostname: node2
Uuid: 1a99d57f-9575-4ba0-9cc9-9c2d3b4b4e3f
State: Peer in Cluster (Connected)

Hostname: node3
Uuid: 06f43aee-3edb-4cc5-b886-fee2e52c8b7f
State: Peer in Cluster (Connected)
[root@node1 ~]# gluster peer probe node4  #在重新加回来
peer probe: success.

glusgerfs卷的类型

基本类型:条带,复制,哈希。然后还有两两组合总共加起来共7种,新版的还有冗余卷

分布卷

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-If7G70iw-1584709672112)(assets/1571580499141.png)]

分布巻
分布卷也称为哈希卷,多个文件在多个 brick 上使用哈希算法随机存储。
分布存储是Glusterfs 默认使用的存储卷类型。以两个存储块的逻辑卷为例,文件file1可能被存放在brick1或brick2中,但不会在每个块中都存一份。分布存储不提供数据冗余保护。
应用场景:   大量小文件
优点:       读/写性能好
缺点:       如果存储或服务器故障,数据将丢失
创建数据分区
所有server节点分别创建/data0/gluster目录,所谓brick的位置,用于存储数据
# mkdir -p /data0/gluster

创建volume,在控制节点上操作
[root@node1 yum.repos.d]# gluster
Welcome to gluster prompt, type 'help' to see the available commands.
gluster> volume create datavol1 transport tcp node1:/data0/gluster/data1 #创建卷node2:/data0/gluster/data1 node3:/data0/gluster/data1 node4:/data0/gluster/data1 force

volume create: datavol1: success: please start the volume to access data

启动volume
因为默认是分布巻(哈希卷),所以卷的类型没有指定,datavol1 这个volume拥有4个brick,分布在4个peer节点
gluster> volume start datavol1
volume start: datavol1: success

查看卷信息
gluster> volume info datavol1
 
Volume Name: datavol1
Type: Distribute
Volume ID: c01c8a3e-5554-4d09-8e1c-c6531f4a6e1f
Status: Started
Snapshot Count: 0
Number of Bricks: 4
Transport-type: tcp
Bricks:
Brick1: node1:/data0/gluster/data1
Brick2: node2:/data0/gluster/data1
Brick3: node3:/data0/gluster/data1
Brick4: node4:/data0/gluster/data1
Options Reconfigured:
transport.address-family: inet
storage.fips-mode-rchecksum: on
nfs.disable: on

查看卷状态
gluster> volume status datavol1
Status of volume: datavol1
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick node1:/data0/gluster/data1            49152     0          Y       1858 
Brick node2:/data0/gluster/data1            49152     0          Y       1784 
Brick node3:/data0/gluster/data1            49152     0          Y       1781 
Brick node4:/data0/gluster/data1            49152     0          Y       1781 
 
Task Status of Volume datavol1
------------------------------------------------------------------------------
There are no active volume tasks
===================================================================================
删除卷
需要提前停止卷运行
gluster> volume stop datavol1  #停止
Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
volume stop: datavol1: success
gluster> volume delete datavol1  #删除
Deleting volume will erase all information about the volume. Do you want to continue? (y/n) y
volume delete: datavol1: success

找台虚拟机作为客户端,去挂载
[root@node4 ~]# mount -t glusterfs node01:/datavol1 /mnt
[root@node4 ~]# touch  /mnt/fenbu1.txt      #会随机分配到某个节点上
================================================================
去各个节点查看,不一定分布到哪个节点
[root@node1 ~]# ls /data0/gluster/data1/
fenbu.txt
[root@node4 ~]# touch /mnt/fenbu2.txt
[root@node4 ~]# ls /data0/gluster/data1/
fenbu2.txt

[root@node4 ~]# touch /mnt/fenbu3.txt  #在创建一个

以上是volume的状态信息,可以看到在每一个节点上启动一个volume后,gluster会自动的启动相关的进程,Port机监听的端口。
    glusterd      #管理进程
    glusterfsd   #brick进程,因为本机上只有一个brick。
复制卷

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ERaSfVKt-1584709672115)(assets/1571581145182.png)]

多个文件在多个brick上复制多份,brick 的数目要与需要复制的份数相等,建议brick分布在不同的服务器上。
复制卷和条带卷必须要指定卷的类型,复制卷就是每一个brick中的数据都是一样的,都是写入数据的完整备份。
所以容量会减少一半,当然性能上也会有所消耗.

应用场景:   对可靠性和读性能要求高的场景
优点:       读性能好
缺点:       写性能差
[root@node4 ~]# gluster
Welcome to gluster prompt, type 'help' to see the available commands.

创建复制卷
gluster> volume create datavol2 replica 2 transport tcp node1:/data0/gluster/data2 node2:/data0/gluster/data2 force  #创建卷
volume create: datavol2: success: please start the volume to access data

启动volume
gluster> volume start datavol2
volume start: datavol2: success

查看volume状态
gluster> volume status datavol2
Status of volume: datavol2
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick node1:/data0/gluster/data2            49153     0          Y       11961
Brick node2:/data0/gluster/data2            49153     0          Y       11858
Self-heal Daemon on localhost               N/A       N/A        Y       12031
Self-heal Daemon on node3                   N/A       N/A        Y       11857
Self-heal Daemon on node2                   N/A       N/A        Y       11879
Self-heal Daemon on node1                   N/A       N/A        Y       11982
 
Task Status of Volume datavol2
------------------------------------------------------------------------------
There are no active volume tasks
 
查看卷信息 
gluster> volume info  datavol2
 
Volume Name: datavol2
Type: Replicate
Volume ID: cb872ec7-6ce0-4635-bea2-d2e8d08dfac5
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: node1:/data0/gluster/data2
Brick2: node2:/data0/gluster/data2
Options Reconfigured:
transport.address-family: inet
storage.fips-mode-rchecksum: on
nfs.disable: on
performance.client-io-threads: off
想要看到需要挂载
关于数据,存储节点会同步控制节点的数据,控制节点不会同步存储节点的数据
[root@node3 ~]# mount -t glusterfs node1:/datavol2/ /mnt
[root@node3 ~]# ls /mnt/
[root@node3 ~]# cd /mnt/
[root@node3 mnt]# touch a.txt  #创建测试数据

测试
[root@node1 ~]# ls /data0/gluster/data2/
a.txt

[root@node2 ~]# ls /data0/gluster/data2
a.txt

条带卷

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-zEi0dicq-1584709672117)(assets/1571581976341.png)]

将文件分成条带,存放在多个 brick上,默认条带大小128K
条带卷在处理大文件的时候会有一定的作用,它会将文件拆分几个部分,分别存在两个条带上即两个brick上。这个实际用的较少

应用场景:   大文件
优点:       适用于大文件存储
缺点:       可靠性低,brick 故障会导致数据全部丢失
创建条带卷
gluster> volume create datavol3 stripe 2 node01:/data0/gluster/data3 node02:/data0/gluster/data3 force
stripe option not supported
创建了一下,好像现在不支持了
复合卷
复合卷
复合卷就是分布式复制,分布式条带,分布式条带复制卷,像分布式复制,分布式条带这两个是比较常用的,像分布式条带复制卷三种揉一块儿的用的都比较少,
分布复制卷

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-TdDr6aVR-1584709672120)(assets/1571622957681.png)]

多个文件在多个节点哈希存储,在多个brick 复制多份存储。

应用场景:   大量文件读和可靠性要求高的场景
优点:       高可靠性,读性能高
缺点:       牺牲存储空间,写性能差

这里我们用4个brick
哈希复制卷是一对一对组成复制卷,所以要选择不同的节点上的brick组成复制卷,这样一个数据的副本就会分布在不同的节点上,不管那个节点宕机,另外一个节点都会数据的完整副本。
制作
[root@node3 ~]# gluster
Welcome to gluster prompt, type 'help' to see the available commands.
gluster> volume create data_rd replica 2 node1:/data0/gluster/data_rd_1 node2:/data0/gluster/data_rd_1 node1:/data0/gluster/data_rd_2 node2:/data0/gluster/data_rd_2 force  #创建卷
volume create: data_rd: success: please start the volume to access data

查看信息
gluster> volume info data_rd
 
Volume Name: data_rd
Type: Distributed-Replicate
Volume ID: 2d206595-edb9-4bbe-9db6-071c4229bea2
Status: Created
Snapshot Count: 0
Number of Bricks: 2 x 2 = 4  #brick数量为两个复制,两个复制之间构成哈希关系
Transport-type: tcp
Bricks:
Brick1: node1:/data0/gluster/data_rd_1
Brick2: node2:/data0/gluster/data_rd_1
Brick3: node1:/data0/gluster/data_rd_2
Brick4: node2:/data0/gluster/data_rd_2
Options Reconfigured:
transport.address-family: inet
storage.fips-mode-rchecksum: on
nfs.disable: on
performance.client-io-threads: off


启动
gluster> volume start data_rd
volume start: data_rd: success

查看状态
gluster> volume status data_rd
Status of volume: data_rd
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick node1:/data0/gluster/data_rd_1        49154     0          Y       12150
Brick node2:/data0/gluster/data_rd_1        49154     0          Y       12041
Brick node1:/data0/gluster/data_rd_2        49155     0          Y       12170
Brick node2:/data0/gluster/data_rd_2        49155     0          Y       12061
Self-heal Daemon on localhost               N/A       N/A        Y       11857
Self-heal Daemon on node4                   N/A       N/A        Y       12031
Self-heal Daemon on node1                   N/A       N/A        Y       11982
Self-heal Daemon on node2                   N/A       N/A        Y       11879
 
Task Status of Volume data_rd
------------------------------------------------------------------------------
There are no active volume tasks

测试:
随便找一台虚拟机,前提是能和gluster集群各个节点ping通
我这里用node03充当客户端,进行挂载
[root@node3 ~]# umount /mnt/   #先将之前挂载的取消
[root@node3 ~]# mount -t glusterfs node1:/data_rd /mnt
[root@node3 ~]# ls /mnt/
[root@node3 ~]# touch /mnt/test.txt

看node1和node2的是否有test.txt
[root@node1 ~]# ls /data0/gluster/data_rd_1/  #下面有数据
test.txt
[root@node1 ~]# ls /data0/gluster/data_rd_2/  #但这个目录下是空的
[root@node2 ~]# ls /data0/gluster/data_rd_1    #这个目录下是有的
test.txt
[root@node2 ~]# ls /data0/gluster/data_rd_2    #这个目录下是有的

再次创建
[root@node3 ~]# touch /mnt/test2.txt
再次查看
[root@node1 ~]# ls /data0/gluster/data_rd_1/
test.txt
[root@node1 ~]# ls /data0/gluster/data_rd_2/
test2.txt
[root@node2 ~]# ls /data0/gluster/data_rd_1/
test.txt
[root@node2 ~]# ls /data0/gluster/data_rd_2/
test2.txt
可以看到,分布式复制卷的效果。
分布条带卷

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HCRNcorZ-1584709672123)(assets/1571624061763.png)]

gluster> volume create fentiao stripe 2 node03:/data/gluster/data5 node04:/data/gluster/data5 force
stripe option not supported    #也不支持了

各种卷的整理

分布卷:存储数据时,将文件随机存储到各台glusterfs机器上。
        优点:存储数据时,读取速度快
        缺点:一个birck坏掉,文件就会丢失
复制卷:存储数据时,所有文件分别存储到每台glusterfs机器上。
        优点:对文件进行的多次备份,一个brick坏掉,文件不会丢失,其他机器的brick上面有备份
        缺点:占用资源
条带卷:存数据时,一个文件分开存到每台glusterfs机器上
        优点:对大文件,读写速度快
        缺点:一个brick坏掉,文件就会坏掉

ster> volume create fentiao stripe 2 node03:/data/gluster/data5 node04:/data/gluster/data5 force
stripe option not supported #也不支持了


**各种卷的整理**

```shell
分布卷:存储数据时,将文件随机存储到各台glusterfs机器上。
        优点:存储数据时,读取速度快
        缺点:一个birck坏掉,文件就会丢失
复制卷:存储数据时,所有文件分别存储到每台glusterfs机器上。
        优点:对文件进行的多次备份,一个brick坏掉,文件不会丢失,其他机器的brick上面有备份
        缺点:占用资源
条带卷:存数据时,一个文件分开存到每台glusterfs机器上
        优点:对大文件,读写速度快
        缺点:一个brick坏掉,文件就会坏掉
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值