GlusterFS分布式存储系统

释放双眼,带上耳机,听听看~!

1. 分布式文件系统理论基础

1.1 分布式文件系统出现

  • 计算机通过文件系统管理,存储数据,而现在数据信息爆炸的时代中人们可以获取的数据成指数倍的增长,单纯通过增加硬盘个数来扩展计算机文件系统的存储容量的方式,已经不能满足目前的需求。
  • 分布式文件系统可以有效解决数据的存储和管理难题,将固定于某个地点的某个文件系统,扩展到任意多个地点/多个文件系统,众多的节点组成一个文件系统网络。每个节点可以分布在不同的地点,通过网络进行节点间的通信和数据传输。人们在使用分布式文件系统时,无需关心数据是存储在哪个节点上,或者是从哪个节点从获取的,只需要像使用本地文件系统一样管理和存储文件系统中的数据。

1.2 典型代表NFS

NFS(Network File System)即网络文件系统,它允许网络中的计算机之间通过TCP/IP网络共享资源。在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件,就像访问本地文件一样。NFS的优点如下:

1.2.1 节约使用的磁盘空间

客户端经常使用的数据可以集中存放在一台机器上,并使用NFS发布,那么网络内部所有计算机可以通过网络访问,不必单独存储。

1.2.2 节约硬件资源

NFS还可以共享软驱,CDROM和ZIP等的存储设备,减少整个网络上的可移动设备的数量。

1.2.3 用户主目录设定

对于特殊用户,如管理员等,为了管理的需要,可能会经常登陆到网络中所有的计算机,若每个客户端,均保存这个用户的主目录很繁琐,而且不能保证数据的一致性。实际上,经过NFS服务的设定,然后在客户端指定这个用户的主目录位置,并自动挂载,就可以在任何计算机上使用用户主目录的文件。

1.3 面临的问题

  • 存储空间不足,需要更大容量的存储
  • 直接用NFS挂载存储,有一定风险,存在单点故障
  • 某些场景不能满足需求,大量的访问磁盘IO是瓶颈

1.4 GlusterFS概述

  • GlusterFS是Scale-Out存储解决方案Gluster的核心,它是一个开源的分布式文件系统,具有强大的横向扩展能力,通过扩展能够支持数PB存储容量和处理数千客户端。GlusterFS借助TCP/IP或InfiniBand RDMA网络将物理分布的存储资源聚集在一起,使用单一全局命名空间来管理数据。
  • GlusterFS支持运行在任何标准IP网络上标准应用程序的标准客户端,用户可以在全局统一的命令空间中使用NFS/CIFS等标准协议来访问应用程序。GlusterFS使得用户可摆脱原有的独立,高成本的封闭存储系统,能够利用普通廉价的存储设备来部署可集中管理,横向扩展,虚拟化的存储池,存储容量可扩展至TB/PB级。
  • 目前glusterfs已被redhat收购,它的官方网站是:http://www.gluster.org/

超高性能(64个节点时吞吐量也就是带宽甚至达到32GB/s)

1.5 GlusterFS企业主要应用场景

理论和实践上分析,GlusterFS目前主要适用大文件存储场景,对于小文件尤其是海量小文件(小于1M),存储效率和访问性能都表现不佳。海量小文件LOSF问题是工业界和学术界公认的难题,GlusterFS作为通用的分布式文件系统,并没有对小文件作额外的优化措施(小于1M),性能不好也是可以理解的。

1.5.1 Media

文档,图片,音频,视频

1.5.2 Shared storage

云存储,虚拟化存储,HPC(高性能计算)

1.5.3 Big data

日志文件,RFID(射频识别)数据

2. 部署安装

2.1 GlusterFS 安装前的准备

  • 电脑一台,内存>=4G,可用磁盘空间大于50G
  • 安装VMWARE Workstation虚拟机软件
  • 安装好四台CentOS-6-x86_64(6.2-6.8都可以)的虚拟机
  • 基本系统:1核CPU+1024M内存+10G硬盘
  • 网络选择:网络地址转换(NAT)
  • 关闭iptables和SELinux
  • 预装glusterfs软件包

Linux_node1
192.168.200.151
mystorage01
多添加两块各10G的sdb和sdc
Linux_node2
192.168.200.152
mystorage02
多添加两块各10G的sdb和sdc
Linux_node3
192.168.200.153
mystorage03
多添加两块各10G的sdb和sdc
Linux_node4
192.168.200.154
mystorage04
多添加两块各10G的sdb和sdc
Linux_node5
192.168.200.155
WebServer

2.2 GlusterFS 安装(以下在四台glusterfs服务器上同时操作)

2.2.1 添加hosts文件实现集群主机之间相互能够解析


1
2
3
4
5
6
1[root@mystorage01 ~]# tail -4 /etc/hosts
2192.168.200.151 glusterfs01
3192.168.200.152 glusterfs02
4192.168.200.153 glusterfs03
5192.168.200.154 glusterfs04
6

2.2.2 关闭selinux和防火墙


1
2
3
4
5
6
1[root@mystorage01 ~]# setenforce 0
2[root@mystorage01 ~]# service iptables stop
3iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
4iptables: Flushing firewall rules:                         [  OK  ]
5iptables: Unloading modules:                               [  OK  ]
6

2.2.3 安装GlusterFS必备依赖rpm包


1
2
3
4
5
6
7
1[root@mystorage01 rpm]# pwd
2/root/rpm
3[root@mystorage01 rpm]# yum -y install createrepo
4[root@mystorage01 rpm]# which createrepo
5/usr/bin/createrepo
6[root@mystorage01 rpm]# createrepo -v .
7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
1[root@mystorage01 rpm]# cat /etc/yum.repos.d/CentOS-Media.repo
2[c6-media]
3name=CentOS-$releasever - Media
4baseurl=file:///media/CentOS/
5        file:///media/cdrom/
6        file:///media/cdrecorder/
7gpgcheck=1
8enabled=1
9gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
10[rpm]
11name=rpm
12baseurl=file:///root/rpm/
13gpgcheck=0
14enabled=1
15[root@mystorage01 rpm]# yum -y clean all
16[root@mystorage04 rpm]# yum makecache
17

1
2
3
4
5
6
1[root@mystorage01 rpm]# yum -y install glusterfs-server glusterfs-cli glusterfs-geo-replication
2[root@mystorage01 rpm]# rpm -qa glusterfs-server glusterfs-cli glusterfs-geo-replication
3glusterfs-geo-replication-3.7.20-1.el6.x86_64
4glusterfs-cli-3.7.20-1.el6.x86_64
5glusterfs-server-3.7.20-1.el6.x86_64
6

2.3 配置glusterfs

2.3.1 查看glusterfs版本信息


1
2
3
4
5
6
7
8
9
10
11
12
1[root@mystorage01 ~]# which glusterfs
2/usr/sbin/glusterfs
3[root@mystorage01 ~]# glusterfs -V
4glusterfs 3.7.20 built on Jan 30 2017 15:39:27
5Repository revision: git://git.gluster.com/glusterfs.git
6Copyright (c) 2006-2013 Red Hat, Inc. <http://www.redhat.com/>
7GlusterFS comes with ABSOLUTELY NO WARRANTY.
8It is licensed to you under your choice of the GNU Lesser
9General Public License, version 3 or any later version (LGPLv3
10or later), or the GNU General Public License, version 2 (GPLv2),
11in all cases as published by the Free Software Foundation.
12

2.3.2 启动服务并添加开机自启动


1
2
3
4
5
6
7
8
1[root@mystorage01 ~]# /etc/init.d/glusterd status   #查看服务状态
2glusterd is stopped
3[root@mystorage01 ~]# /etc/init.d/glusterd start    #启动
4Starting glusterd:                                         [  OK  ]
5[root@mystorage01 ~]# /etc/init.d/glusterd status   #查看服务状态
6glusterd (pid  1826) is running...
7[root@mystorage01 ~]# chkconfig glusterd on         #添加开机启动
8

2.3.3 存储主机加入信任存储池

虚拟机添加信任存储池
特别提示:只需要让一个虚拟机进行添加操作即可。但自己并不需要添加信任自己


1
2
3
4
5
6
7
8
1#确保所有的虚拟机的glusterd服务都处于开启状态,然后执行如下操作
2[root@mystorage01 ~]# gluster peer probe glusterfs02
3peer probe: success.
4[root@mystorage01 ~]# gluster peer probe glusterfs03
5peer probe: success.
6[root@mystorage01 ~]# gluster peer probe glusterfs04
7peer probe: success.
8

2.3.4 查看虚拟机信任状态添加结果


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1[root@mystorage01 ~]# gluster peer status
2Number of Peers: 3
3
4Hostname: glusterfs02
5Uuid: ab7d1773-9e64-4b3b-bdaf-b03d7522b669
6State: Peer in Cluster (Connected)
7
8Hostname: glusterfs03
9Uuid: f050b487-32c0-4aad-8d16-bb139e8927a8
10State: Peer in Cluster (Connected)
11
12Hostname: glusterfs04
13Uuid: 4c26a391-636c-4c25-bae8-c9181c26ca2f
14State: Peer in Cluster (Connected)
15

这里可以查看每台虚拟机的信任状态,他们此时彼此都应该已经互有信任记录了

2.3.5 配置前的准备工作


1
2
3
4
5
6
1#链接光盘源,安装xfs支持包(Centos7已经不再需要安装)
2#四台服务器都要安装
3[root@mystorage01 ~]# yum -y install xfsprogs
4[root@mystorage01 ~]# rpm -qa xfsprogs
5xfsprogs-3.1.1-14.el6.x86_64
6

在企业里我们还需要分区然后才能进行格式化。但是我们这里就省略了,我们直接格式化每台虚拟机的那块10G硬盘


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
1[root@mystorage01 ~]# ll /dev/sd*
2brw-rw----. 1 root disk 8,  0 Sep 28 02:05 /dev/sda
3brw-rw----. 1 root disk 8,  1 Sep 28 02:05 /dev/sda1
4brw-rw----. 1 root disk 8,  2 Sep 28 02:05 /dev/sda2
5brw-rw----. 1 root disk 8, 16 Sep 28 02:05 /dev/sdb
6brw-rw----. 1 root disk 8, 32 Sep 28 02:05 /dev/sdc
7
8[root@mystorage01 ~]# mkfs.ext4 /dev/sdb
9mke2fs 1.41.12 (17-May-2010)
10/dev/sdb is entire device, not just one partition!
11Proceed anyway? (y,n) y
12Filesystem label=
13OS type: Linux
14Block size=4096 (log=2)
15Fragment size=4096 (log=2)
16Stride=0 blocks, Stripe width=0 blocks
17655360 inodes, 2621440 blocks
18131072 blocks (5.00%) reserved for the super user
19First data block=0
20Maximum filesystem blocks=2684354560
2180 block groups
2232768 blocks per group, 32768 fragments per group
238192 inodes per group
24Superblock backups stored on blocks:
25    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
26
27Writing inode tables: done                            
28Creating journal (32768 blocks): done
29Writing superblocks and filesystem accounting information: done
30
31This filesystem will be automatically checked every 30 mounts or
32180 days, whichever comes first.  Use tune2fs -c or -i to override.
33

在四台机器上执行mkdir -p /gluster/brick1 建立挂在块设备的目录
挂载磁盘到文件系统(4台都做,步骤相同)


1
2
3
4
5
6
7
8
9
10
1[root@mystorage01 ~]# mkdir -p /gluster/brick1
2[root@mystorage01 ~]# mount /dev/sdb /gluster/brick1
3[root@mystorage01 ~]# df -h
4Filesystem                        Size  Used Avail Use% Mounted on
5/dev/mapper/vg_yangwenbo-lv_root   18G  992M   16G   6% /
6tmpfs                             491M     0  491M   0% /dev/shm
7/dev/sda1                         485M   33M  427M   8% /boot
8/dev/sr0                          4.2G  4.2G     0 100% /media/cdrom
9/dev/sdb                          9.9G  151M  9.2G   2% /gluster/brick1
10

继续重复以上步骤,将第二块磁盘sdc格式化,并挂载到每台虚拟机的/gluster/brick2上

4台虚拟机加入开机自动挂载


1
2
3
4
5
6
1[root@mystorage01 ~]# echo "mount /dev/sdb /gluster/brick1" >> /etc/rc.local
2[root@mystorage01 ~]# echo "mount /dev/sdc /gluster/brick2" >> /etc/rc.local
3[root@mystorage01 ~]# tail -2 /etc/rc.local
4mount /dev/sdb /gluster/brick1
5mount /dev/sdc /gluster/brick2
6

2.3.6 创建volume分布式卷

基本卷:

  • 分布式卷(Distributed)
  • 复制卷(Replicated)
  • 条带式卷(Striped)

复合卷:

  • 分布式复制卷(Distributed Replicated):
  • 分布式条带卷(Distributed Striped):
  • 复制条带卷(Replicated Striped):
  • 分布式复制条带卷(Distributed Replicated Striped)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
1#创建分布式卷(在glusterfs01上操作)
2[root@mystorage01 ~]# gluster volume create gs1 glusterfs01:/gluster/brick1 glusterfs02:/gluster/brick1 force
3volume create: gs1: failed: Volume gs1 already exists
4
5#启动创建的卷(在glusterfs01上操作)
6[root@mystorage01 ~]# gluster volume start gs1
7volume start: gs1: success
8
9#然后我们发现4台虚拟机都能看到如下信息(在任意虚拟机上操作)
10[root@mystorage02 ~]# gluster volume info
11
12Volume Name: gs1     #卷名
13Type: Distribute     #分布式
14Volume ID: f1a2933a-311c-4e66-9fb7-0bcb148b53ed     #ID号
15Status: Started         #启动状态
16Number of Bricks: 2     #一共两个块设备
17Transport-type: tcp     #tcp的连接方式
18Bricks:                 #块信息
19Brick1: glusterfs01:/gluster/brick1
20Brick2: glusterfs02:/gluster/brick1
21Options Reconfigured:
22performance.readdir-ahead: on
23

2.3.7 volume的两种挂载方式

(1)以glusterfs方式挂载


1
2
3
4
5
6
7
8
9
10
11
12
13
1#挂载卷到目录(在glusterfs01上操作)
2
3[root@mystorage01 ~]# mount -t glusterfs 127.0.0.1:/gs1 /mnt     #将本地的分布式卷gs01挂载到/mnt目录下
4[root@mystorage01 ~]# df -h
5Filesystem                        Size  Used Avail Use% Mounted on
6/dev/mapper/vg_yangwenbo-lv_root   18G  992M   16G   6% /
7tmpfs                             491M     0  491M   0% /dev/shm
8/dev/sda1                         485M   33M  427M   8% /boot
9/dev/sr0                          4.2G  4.2G     0 100% /media/cdrom
10/dev/sdb                          9.9G  151M  9.2G   2% /gluster/brick1
11/dev/sdc                          9.9G  151M  9.2G   2% /gluster/brick2
12127.0.0.1:/gs1                     20G  302M   19G   2% /mnt     #挂载成功,我们看到磁盘空间已经整合
13

1
2
3
4
5
1#在挂载好的/mnt目录里创建实验文件(在glusterfs01上操作)
2[root@mystorage01 ~]# touch /mnt/{1..5}
3[root@mystorage01 ~]# ls /mnt/
41  2  3  4  5  lost+found
5

1
2
3
4
5
6
7
8
9
10
11
12
13
1#在其他虚拟机上挂载分布式卷gs1,查看同步挂载结果
2[root@mystorage02 ~]# mount -t glusterfs 127.0.0.1:/gs1 /mnt
3[root@mystorage02 ~]# ls /mnt/
41  2  3  4  5  lost+found
5
6[root@mystorage03 ~]# mount -t glusterfs 127.0.0.1:/gs1 /mnt
7[root@mystorage03 ~]# ls /mnt/
81  2  3  4  5  lost+found
9
10[root@mystorage04 ~]# mount -t glusterfs 127.0.0.1:/gs1 /mnt
11[root@mystorage04 ~]# ls /mnt/
121  2  3  4  5  lost+found
13

(2)以NFS方式进行挂载

在挂载之前我们先来看一下如何打开glusterfs的NFS挂载方式


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1[root@mystorage01 ~]# gluster volume status    #查看分布式卷的状态
2Status of volume: gs1
3Gluster process                             TCP Port  RDMA Port  Online  Pid
4------------------------------------------------------------------------------
5Brick glusterfs01:/gluster/brick1           49152     0          Y       2202
6Brick glusterfs02:/gluster/brick1           49152     0          Y       1769
7NFS Server on localhost                     N/A       N/A        N       N/A     #本地分布式卷NFS挂载未开启
8NFS Server on glusterfs03                   N/A       N/A        N       N/A  
9NFS Server on glusterfs04                   N/A       N/A        N       N/A  
10NFS Server on glusterfs02                   N/A       N/A        N       N/A  
11
12Task Status of Volume gs1
13------------------------------------------------------------------------------
14There are no active volume tasks
15

以上结果是是什么原因呢?
如果NFS Server的挂载端口显示N/A表示未开启挂载功能,这是由于要先进行nfs挂载是需要装两个nfs的软件包的rpcbind和nfs-utils
当然就算系统装了这两个软件包,那么我们也需要开启rpcbind服务,然后在重启glusterfs服务才能够进行nfs挂载的操作。
现在我们就来开启glusterfs01的nfs挂载功能,如下:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
1#在glusterfs01上执行如下操作
2[root@mystorage01 ~]# rpm -qa nfs-utils
3nfs-utils-1.2.3-75.el6_9.x86_64    #查看是否安装nfs-utils
4[root@mystorage01 ~]# rpm -qa rpcbind
5rpcbind-0.2.0-13.el6_9.1.x86_64    #查看是否安装rpcbind
6
7[root@mystorage01 ~]# /etc/init.d/rpcbind status    #查看rpcbind服务状态
8rpcbind is stopped
9[root@mystorage01 ~]# /etc/init.d/rpcbind start     #开启rpcbind服务
10Starting rpcbind:                                          [  OK  ]
11[root@mystorage01 ~]# /etc/init.d/glusterd restart  #重启glusterd服务
12Stopping glusterd:                                         [  OK  ]
13Starting glusterd:                                         [  OK  ]
14

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1[root@mystorage01 ~]# gluster volume status
2Status of volume: gs1
3Gluster process                             TCP Port  RDMA Port  Online  Pid
4------------------------------------------------------------------------------
5Brick glusterfs01:/gluster/brick1           49152     0          Y       2202
6Brick glusterfs02:/gluster/brick1           49152     0          Y       1769
7NFS Server on localhost                     2049      0          Y       3280     #出现具体的端口就表明开启了
8NFS Server on glusterfs02                   N/A       N/A        N       N/A  
9NFS Server on glusterfs04                   N/A       N/A        N       N/A  
10NFS Server on glusterfs03                   N/A       N/A        N       N/A  
11
12Task Status of Volume gs1
13------------------------------------------------------------------------------
14There are no active volume tasks
15

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1#依次在其它三台服务器上操作即可
2[root@mystorage01 ~]# gluster volume status
3Status of volume: gs1
4Gluster process                             TCP Port  RDMA Port  Online  Pid
5------------------------------------------------------------------------------
6Brick glusterfs01:/gluster/brick1           49152     0          Y       2202
7Brick glusterfs02:/gluster/brick1           49152     0          Y       1769
8NFS Server on localhost                     2049      0          Y       3280
9NFS Server on glusterfs02                   2049      0          Y       2125
10NFS Server on glusterfs04                   2049      0          Y       2063
11NFS Server on glusterfs03                   2049      0          Y       2057
12
13Task Status of Volume gs1
14------------------------------------------------------------------------------
15There are no active volume tasks
16

接下来,我们尝试在准备好的第五台虚拟机WebServer上进行nfs方式的挂载


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
1#在Webserver上进行如下操作
2[root@WebServer ~]# yum -y install nfs-utils
3[root@WebServer ~]# rpm -qa nfs-utils
4nfs-utils-1.2.3-39.el6.x86_64
5[root@WebServer ~]# mount -o nolock -t nfs 192.168.200.151:/gs1 /mnt
6[root@WebServer ~]# ls /mnt
71  2  3  4  5  lost+found       #挂载成功
8
9[root@WebServer ~]# touch /mnt/benet      #创建文件测试
10[root@WebServer ~]# ls /mnt
111  2  3  4  5  benet  lost+found
12
13#在glusterfs任意虚拟机上进行如下操作
14[root@glusterfs04 ~]# mount -t glusterfs 127.0.0.1:/gs1 /mnt   #如果之前已挂载,请忽略此步
15[root@mystorage04 ~]# ls /mnt
161  2  3  4  5  benet  lost+found          #数据已经同步
17

2.3.8 创建分布式复制卷


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1#在任意一台gluster虚拟机上进行如下操作
2[root@mystorage01 ~]# gluster volume create gs2 replica 2 glusterfs03:/gluster/brick1 glusterfs04:/gluster/brick1 force
3volume create: gs2: success: please start the volume to access data
4[root@mystorage01 ~]# gluster volume info gs2
5
6Volume Name: gs2
7Type: Replicate                 #复制卷
8Volume ID: 29e00864-685e-4bfd-8299-dce52cf2eb16
9Status: Created
10Number of Bricks: 1 x 2 = 2
11Transport-type: tcp
12Bricks:
13Brick1: glusterfs03:/gluster/brick1
14Brick2: glusterfs04:/gluster/brick1
15Options Reconfigured:          
16performance.readdir-ahead: on
17[root@mystorage01 ~]# gluster volume start gs2       #启动卷
18volume start: gs2: failed: Volume gs2 already started
19

2.3.9 创建分布式条带卷


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
1[root@mystorage01 ~]# gluster volume create gs3 stripe 2 glusterfs01:/gluster/brick2 glusterfs02:/gluster/brick2 force
2volume create: gs3: success: please start the volume to access data
3[root@mystorage01 ~]# gluster volume info gs3
4
5Volume Name: gs3
6Type: Stripe                     #条带卷
7Volume ID: 66edb2a5-dccb-42f5-b951-9360082080f2
8Status: Created
9Number of Bricks: 1 x 2 = 2
10Transport-type: tcp
11Bricks:
12Brick1: glusterfs01:/gluster/brick2
13Brick2: glusterfs02:/gluster/brick2
14Options Reconfigured:
15performance.readdir-ahead: on    
16[root@mystorage01 ~]# gluster volume start gs3       #启动卷
17volume start: gs3: failed: Volume gs3 already started
18

3.进行卷的数据写入测试

在WebServer服务器挂载创建的三种类型卷gs1,gs2,gs3,进行数据写入测试

3.1 分布式卷gs1的数据写入测试


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1#在WebServer上进行数据写入操作
2[root@WebServer ~]# mount -o nolock -t nfs 192.168.200.150:/gs1 /mnt
3[root@WebServer ~]# df -h
4Filesystem                        Size  Used Avail Use% Mounted on
5/dev/mapper/vg_yangwenbo-lv_root   18G  963M   16G   6% /
6tmpfs                             491M     0  491M   0% /dev/shm
7/dev/sda1                         485M   33M  427M   8% /boot
8/dev/sr0                          4.2G  4.2G     0 100% /media/cdrom
9192.168.200.151:/gs1               20G  301M   19G   2% /mnt
10
11[root@WebServer ~]# ls /mnt/
12[root@WebServer ~]# touch /mnt/{1..10}
13[root@WebServer ~]# ls /mnt/
141  10  2  3  4  5  6  7  8  9  
15

1
2
3
4
5
6
1#在glusterfs01和glusterfs02上进行查看(看看数据到底写入了哪个盘)
2[root@glusterfs01 ~]# ls /gluster/brick1
31  5  7  8  9
4[root@glusterfs02 ~]# ls /gluster/brick1
510  2  3  4  6
6

结论:分布式卷的数据存储方式是将数据平均写入到每个整合的磁盘中,类似于raid0,写入速度快,但这样磁盘一旦损坏没有纠错能力。

3.2 分布式复制卷gs2的数据写入测试


1
2
3
4
5
6
7
8
9
10
11
12
13
1#在WebServer上进行数据写入操作
2[root@WebServer ~]# mount -o nolock -t nfs 192.168.200.151:/gs2 /mnt
3[root@WebServer ~]# df -h
4Filesystem                        Size  Used Avail Use% Mounted on
5/dev/mapper/vg_yangwenbo-lv_root   18G  963M   16G   6% /
6tmpfs                             491M     0  491M   0% /dev/shm
7/dev/sda1                         485M   33M  427M   8% /boot
8/dev/sr0                          4.2G  4.2G     0 100% /media/cdrom
9192.168.200.151:/gs2              9.9G  151M  9.2G   2% /mnt
10[root@WebServer ~]# touch /mnt/{1..10}
11[root@WebServer ~]# ls /mnt/
121  10  2  3  4  5  6  7  8  9  lost+found
13

1
2
3
4
5
6
1#在glusterfs03和glusterfs04上进行查看(看看数据到底写入了哪个盘)
2[root@mystorage03 ~]# ls /gluster/brick1
31  10  2  3  4  5  6  7  8  9  lost+found
4[root@mystorage04 ~]# ls /gluster/brick1
51  10  2  3  4  5  6  7  8  9  lost+found
6

结论:分布式复制卷的数据存储方式为,每个整合的磁盘中都写入同样的数据内容,类似于raid1,数据非常安全,读取性能高,占磁盘容量。

3.3 分布式条带卷gs3的数据写入测试


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
1#在WebServer上进行数据写入操作
2[root@WebServer ~]# mount -o nolock -t nfs 192.168.200.151:/gs3 /mnt
3[root@WebServer ~]# df -h
4Filesystem                        Size  Used Avail Use% Mounted on
5/dev/mapper/vg_yangwenbo-lv_root   18G  963M   16G   6% /
6tmpfs                             491M     0  491M   0% /dev/shm
7/dev/sda1                         485M   33M  427M   8% /boot
8/dev/sr0                          4.2G  4.2G     0 100% /media/cdrom
9192.168.200.151:/gs3               20G  301M   19G   2% /mnt
10[root@WebServer ~]# dd if=/dev/zero of=/root/test bs=1024 count=262144
11262144+0 records in
12262144+0 records out
13268435456 bytes (268 MB) copied, 12.1792 s, 22.0 MB/s
14[root@WebServer ~]# du -sh test
15256M    test
16[root@WebServer ~]# cp test /mnt/       #复制到/mnt目录下
17[root@WebServer ~]# ls /mnt
18lost+found  test
19[root@WebServer ~]# du -sh /mnt/test    #查看大小为256M
20256M    /mnt/test
21

1
2
3
4
5
6
1#在glusterfs01和glusterfs02上进行查看(看看数据到底是怎么存的)
2[root@mystorage01 ~]# du -sh /gluster/brick2/test
3129M    /gluster/brick2/test
4[root@mystorage02 ~]# du -sh /gluster/brick2/test
5129M    /gluster/brick2/test
6

结论:我们发现分布式条带卷,是将数据的容量平均分配到了每个整合的磁盘节点上。大幅提高大文件的并发读访问。

4. 存储卷中brick块设备的扩容

4.1 分布式复制卷的扩容


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1[root@mystorage01 ~]# gluster volume add-brick gs2 replica 2 glusterfs03:/gluster/brick2 glusterfs04:/gluster/brick2 force    #添加两个块设备
2volume add-brick: success
3
4[root@mystorage01 ~]# gluster volume info gs2
5
6Volume Name: gs2
7Type: Distributed-Replicate
8Volume ID: 29e00864-685e-4bfd-8299-dce52cf2eb16
9Status: Started
10Number of Bricks: 2 x 2 = 4    #已经扩容
11Transport-type: tcp
12Bricks:
13Brick1: glusterfs03:/gluster/brick1
14Brick2: glusterfs04:/gluster/brick1
15Brick3: glusterfs03:/gluster/brick2
16Brick4: glusterfs04:/gluster/brick2
17Options Reconfigured:
18performance.readdir-ahead: on
19

特别提示:

  • 对分布式复制卷和分布式条带卷进行扩容时,要特别注意,如果创建卷之初的时候选择的是replica 2 或者stripe 2。那么扩容时,就必须一次性扩容两个或两个的倍数的块设备。
  • 例如你给一个分布式复制卷的replica为2,你在增加bricks的时候数量必须为2,4,6,8等。

4.2 查看扩容后的容量并进行写入测试


1
2
3
4
5
6
7
8
9
10
1#在WebServer上挂载gs2并查看挂载目录的容量
2[root@WebServer ~]# mount -o nolock -t nfs 192.168.200.151:/gs2 /mnt
3[root@WebServer ~]# df -h
4Filesystem                        Size  Used Avail Use% Mounted on
5/dev/mapper/vg_yangwenbo-lv_root   18G  1.2G   16G   8% /
6tmpfs                             491M     0  491M   0% /dev/shm
7/dev/sda1                         485M   33M  427M   8% /boot
8/dev/sr0                          4.2G  4.2G     0 100% /media/cdrom
9192.168.200.151:/gs2               20G  301M   19G   2% /mnt
10

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
1#在WebServer上进行数据写入操作
2[root@WebServer ~]# ls /mnt/
3lost+found
4[root@WebServer ~]# touch /mnt/{11..20}
5[root@WebServer ~]# ls /mnt/
611  12  13  14  15  16  17  18  19  20  lost+found
7
8#在glusterfs03和glusterfs04上查看数据存到哪里去了
9[root@mystorage03 ~]# gluster volume info gs2
10
11Volume Name: gs2
12Type: Distributed-Replicate
13Volume ID: 29e00864-685e-4bfd-8299-dce52cf2eb16
14Status: Started
15Number of Bricks: 2 x 2 = 4
16Transport-type: tcp
17Bricks:
18Brick1: glusterfs03:/gluster/brick1      #组成gs2的块设备就在03和04上
19Brick2: glusterfs04:/gluster/brick1      #组成gs2的块设备就在03和04上
20Brick3: glusterfs03:/gluster/brick2
21Brick4: glusterfs04:/gluster/brick2
22Options Reconfigured:
23performance.readdir-ahead: on
24[root@mystorage03 ~]# ls /gluster/brick1
2511  12  13  14  15  16  17  18  19  20  lost+found
26[root@mystorage03 ~]# ls /gluster/brick2
27lost+found      #什么都没有
28
29[root@mystorage04 ~]# ls /gluster/brick1
3011  12  13  14  15  16  17  18  19  20  lost+found
31[root@mystorage04 ~]# ls /gluster/brick2
32lost+found      #什么都没有
33

过对扩容的gs2进行写入测试,我们发现数据并没有被写入到新加入的块设备中,这是为甚什么?
这是因为,为了数据的安全,新扩容块设备的卷,默认必须先做一次磁盘平衡(块设备同步),如此才能正常开始使用。

4.3 进行磁盘存储的平衡

注意:平衡布局是很有必要的,因为布局结构是静态的,当新的bricks加入现有卷,新创建的文件会分布到旧的bricks中,所以需要平衡布局结构,使新加入的bricks生效。布局平衡只是使新布局生效,并不会在新的布局移动老的数据,如果你想在新布局生效后,重新平衡卷中的数据,还需要对卷中的数据进行平衡。


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1#对gs2进行磁盘存储平衡
2[root@mystorage01 ~]# gluster volume rebalance gs2 start
3volume rebalance: gs2: success: Rebalance on gs2 has been started successfully. Use rebalance status command to check status of the rebalance process.
4ID: 1ec8578b-fc67-4ada-abec-72830aa8201f
5
6#检查gs2块设备磁盘平衡结果
7[root@mystorage03 ~]# ls /gluster/brick1
812  14  15  16  17  lost+found
9[root@mystorage03 ~]# ls /gluster/brick2
1011  13  18  19  20  lost+found
11
12[root@mystorage04 ~]# ls /gluster/brick1
1312  14  15  16  17  lost+found
14[root@mystorage04 ~]# ls /gluster/brick2
1511  13  18  19  20  lost+found
16

执行磁盘存储平衡以后,我们发现数据被复制成了4份在4个块设备中。

5. 存储卷的缩减与删除

5.1 对存储卷中的brick进行缩减

注意:你可能想在线缩小卷的大小,例如:当硬件损坏或者网络故障的时候,你可能想在卷中移除相关的bricks。注意,当你移除bricks的时候,你在gluster的挂载点将不能继续访问是数据,只有配置文件中的信息移除后你才能继续访问bricks的数据。当移除分布式复制卷或者分布式条带卷的时候,移除的bricks数目必须是replica或者stripe的倍数。例如:一个分布式条带卷的stripe是2,当你移除bricks的时候必须是2,4,6,8等。


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
1#先停止卷gs2
2[root@mystorage01 ~]# gluster volume stop gs2
3Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
4volume stop: gs2: success
5
6#然后移除卷,因为是复制卷且replica为2,因此每次移除必须是2的倍数
7[root@mystorage01 ~]# gluster volume remove-brick gs2 replica 2 glusterfs03:/gluster/brick2 glusterfs04:/gluster/brick2 force
8Removing brick(s) can result in data loss. Do you want to Continue? (y/n) y
9volume remove-brick commit force: success
10
11#我们发现gs2的卷已经被移除
12[root@mystorage01 ~]# gluster volume info gs2
13
14Volume Name: gs2
15Type: Replicate
16Volume ID: 29e00864-685e-4bfd-8299-dce52cf2eb16
17Status: Stopped
18Number of Bricks: 1 x 2 = 2
19Transport-type: tcp
20Bricks:
21Brick1: glusterfs03:/gluster/brick1
22Brick2: glusterfs04:/gluster/brick1
23Options Reconfigured:
24performance.readdir-ahead: on
25
26#重新启动卷gs2
27[root@mystorage01 ~]# gluster volume start gs2
28volume start: gs2: success
29

5.2 对存储卷进行删除


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
1#停止卷gs1
2[root@mystorage01 ~]# gluster volume stop gs1
3Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
4volume stop: gs1: success
5
6#删除卷gs1
7[root@mystorage01 ~]# gluster volume delete gs1
8Deleting volume will erase all information about the volume. Do you want to continue? (y/n) y
9volume delete: gs1: success
10
11#查看卷信息,发现gs1已经没了
12[root@mystorage01 ~]# gluster volume info
13
14Volume Name: gs2
15Type: Replicate
16Volume ID: 29e00864-685e-4bfd-8299-dce52cf2eb16
17Status: Started
18Number of Bricks: 1 x 2 = 2
19Transport-type: tcp
20Bricks:
21Brick1: glusterfs03:/gluster/brick1
22Brick2: glusterfs04:/gluster/brick1
23Options Reconfigured:
24performance.readdir-ahead: on
25
26Volume Name: gs3
27Type: Stripe
28Volume ID: 66edb2a5-dccb-42f5-b951-9360082080f2
29Status: Started
30Number of Bricks: 1 x 2 = 2
31Transport-type: tcp
32Bricks:
33Brick1: glusterfs01:/gluster/brick2
34Brick2: glusterfs02:/gluster/brick2
35Options Reconfigured:
36performance.readdir-ahead: on
37

特别提示:
无论是缩减卷还是删除卷,并不会是清除卷中的数据。数据仍旧会保存在对应磁盘上。

6. 构建企业级分布式存储

6.1 硬件要求

  • 一般选择2U的机型,磁盘STAT盘4T,如果I/O要求比较高,可以采购SSD固态硬盘。为了充分保证系统的稳定性和性能,要求所有glusterfs服务器硬件配置尽量一致,尤其是硬盘数量和大小。机器的RAID卡需要带电池,缓存越大,性能越好。一般情况下,建议做RAID10,如果出于空间要求考虑,需要做RAID5,建议最好能有1-2块硬盘的热备盘。

6.2 系统要求和分区划分

  • 系统要求使用CentOS6.x,安装完成后升级到最新版本,安装的时候,不要使用LVM,建议/boot分区200M,根分区100G,swap分区和内存一样大小,剩余空间给gluster使用,划分单独的硬盘空间。系统安装软件没有特殊要求,建议除了开发工具和基本的管理软件,其他软件一律不装。

6.3 网络环境

网络要求全部千兆环境,gluster服务器至少有2块网卡,1块网卡绑定供gluster使用,剩余一块分配管理网络ip,用于系统管理。如果有条件购买万兆交换机,服务器配置万兆网卡,存储性能会更好。网络方面如果安全性要求高,可以多网卡绑定。

6.4 服务器摆放分布

服务器主备机器要放在不同的机柜,连接不同的交换机,即使一个机柜出现问题,还有一份数据正常访问。

6.5 构建高性能,高可用存储

一般在企业中,采用的是分布式复制卷,因为有数据备份,数据相对安全,分布式条带卷目前对glusterfs来说没有完全成熟,存在一定的是数据安全风险。

6.5.1 开启防火墙端口

一般在企业应用中Linux防火墙是打开的,开通服务器之间访问的端口


1
2
3
1iptables -I INPUT -p tcp --dport 24007:24011 -j ACCEPT
2iptables -I INPUT -p tcp --dport 49152:49162 -j ACCEPT
3

1
2
3
4
5
6
7
8
9
10
11
12
13
1[root@mystorage01 ~]# cat /etc/glusterfs/glusterd.vol
2volume management
3    type mgmt/glusterd
4    option working-directory /var/lib/glusterd
5    option transport-type socket,rdma
6    option transport.socket.keepalive-time 10
7    option transport.socket.keepalive-interval 2
8    option transport.socket.read-fail-log off
9    option ping-timeout 0
10    option event-threads 1
11#   option base-port 49152    #默认端口可以在这里改,因为这个端口可能会和企业里的kvm端口冲突
12end-volume
13

6.5.2 Glusterfs文件系统优化

Auth.allow
IP访问授权
*(allow all)
IP地址
Cluster.min-free-disk
剩余磁盘空间阈值
10%
百分比
Cluster.stripe-block-size
条带大小
128KB
字节
Network.frame-timeout
请求等待时间
1800s
0-1800
Network.ping-timeout
客户端等待时间
42s
0-42
Nfs.disabled
关闭NFS服务
Off
Off\on
Performance.io-thread-count
IO线程数
16
0-65
Performance.cache-refresh-timeout
缓存校验周期
1s
0-61
Performance.cache-size
读缓存大小
32MB
字节

  • Performance.quick-read:优化读取小文件的性能
  • Performance.read-ahead:用预读的方式提高读取的性能,有利于应用频繁持续性的访问文件,当应用完成当前数据块读取的时候,下一个数据块就已经准备好了。
  • Performance.write-behind:写入数据时,先写入缓存内,再写入硬盘内,以提高写入的性能。
  • Performance.io-cache:缓存已经被读过的。

调整方法:
Glusster volume set <卷> <参数>


1
2
3
4
5
6
7
8
9
10
11
12
13
14
1[root@mystorage01 ~]# gluster volume info gs2
2
3Volume Name: gs2
4Type: Replicate
5Volume ID: 29e00864-685e-4bfd-8299-dce52cf2eb16
6Status: Started
7Number of Bricks: 1 x 2 = 2
8Transport-type: tcp
9Bricks:
10Brick1: glusterfs03:/gluster/brick1
11Brick2: glusterfs04:/gluster/brick1
12Options Reconfigured:
13performance.readdir-ahead: on
14

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
1[root@mystorage01 ~]# gluster volume set gs2 performance.read-ahead on
2#设置预缓存优化
3volume set: success
4[root@mystorage01 ~]# gluster volume info gs2
5
6Volume Name: gs2
7Type: Replicate
8Volume ID: 29e00864-685e-4bfd-8299-dce52cf2eb16
9Status: Started
10Number of Bricks: 1 x 2 = 2
11Transport-type: tcp
12Bricks:
13Brick1: glusterfs03:/gluster/brick1
14Brick2: glusterfs04:/gluster/brick1
15Options Reconfigured:
16performance.read-ahead: on
17performance.readdir-ahead: on     #已经添加上了
18

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1[root@mystorage01 ~]# gluster volume set gs2 performance.cache-size 256MB
2#设置读缓存大小
3volume set: success
4[root@mystorage01 ~]# gluster volume info gs2
5
6Volume Name: gs2
7Type: Replicate
8Volume ID: 29e00864-685e-4bfd-8299-dce52cf2eb16
9Status: Started
10Number of Bricks: 1 x 2 = 2
11Transport-type: tcp
12Bricks:
13Brick1: glusterfs03:/gluster/brick1
14Brick2: glusterfs04:/gluster/brick1
15Options Reconfigured:
16performance.cache-size: 256MB    #已经添加上了
17performance.read-ahead: on
18performance.readdir-ahead: on
19

6.5.3 监控及日常维护

使用Zabbix自带模板即可。Cpu,内存,主机存活,磁盘空间,主机运行时间,系统load。日常情况要查看服务器的监控值,遇到报警要及时处理。


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
1#以下命令在复制卷的场景下才会有
2
3#gluster volume status gs2        查看节点NFS是否在线
4(开没开端口)
5#gluster volume heal gs2 full     启动完全修复
6#gluster volume heal gs2 info     查看需要修复的文件
7#gluster volume heal gs2 info healed         查看修复成功的文件
8#gluster volume heal gs2 info heal-failed    查看修复失败文件
9#gluster volume heal gs2 info split-brain    查看脑裂的文件
10#gluster volume quota gs2 enable      --激活quota功能
11#gluster volume quota gs2 disable     --关闭quota功能
12#gluster volume quota gs2 limit-usage   /data   10GB --/gs2/data
13目录限制
14#gluster volume quota gs2 list --quota       信息列表
15#gluster volume quota gs2 list /data         --限制目录的quota信息
16#gluster volume set gs2 features.quota-timeout 5    --设置信息的超时事实上时间
17#gluster volume quota gs2 remove /data      -删除某个目录的quota设置
18
19备注:
20quota 功能,主要是对挂载点下的某个目录进行空间限额。如:/mnt/glusterfs/data目录,而不是对组成卷组的空间进行限制
21

7. 生产环境遇到常见故障处理

7.1 硬盘故障

因为底层做了raid配置,有硬件故障,直接更换硬盘,会自动同步数据。(raid5)

7.2 一台主机故障

一台节点故障的情况包括以下类型:

  • 物理故障
  • 同时有多块硬盘故障,造成是数据丢失
  • 系统损坏不可修复

7.3 解决方法:

7.3.1 找一台完全一样的机器,至少要保证硬盘数量和大小一致,安装系统,配置和故障机同样的ip,安装gluster软件,保证配置一样,在其他健康的节点上执行命令gluster peer status,查看故障服务器的uuid


1
2
3
4
5
6
7
8
9
10
11
12
13
1#例如:
2[root@glusterfs03 ~]# gluster peer status
3Number of Peers: 3
4Hostname: glusterfs02
5Uuid: 0b52290d-96b0-4b9c-988d-44062735a8a8
6State: Peer in Cluster (Connected)
7Hostname: glusterfs04
8Uuid: a43ac51b-641c-4fc4-be56-f6873423b462
9State: Peer in Cluster (Connected)
10Hostname: glusterfs01
11Uuid: 198f2c7c-1104-4671-8989-b430b77540e9
12State: Peer in Cluster (Connected)
13

7.3.2 修改新加机器的/var/lib/glusterd/glusterd.info和故障机器的一样


1
2
3
4
1[root@glusterfs04 ~]# cat /var/lib/glusterd/glusterd.info
2UUID=a43ac51b-641c-4fc4-be56-f6873423b462
3operating-version=30712
4

7.3.3 在新机器挂载目录上执行磁盘故障的操作(任意节点)


1
2
3
4
1[root@glusterfs04 ~]# gluster volume heal gs2 full
2Launching heal operation to perform full self heal on volume gs2 has been successful
3Use heal info commands to check status
4

7.3.4 就会自动开始同步,但是同步的时候会影响整个系统的性能,可以查看状态


1
2
3
4
5
6
7
8
1[root@glusterfs04 ~]# gluster volume heal gs2 info
2Brick glusterfs03:/gluster/brick1
3Status: Connected
4Number of entries: 0
5Brick glusterfs04:/gluster/brick1
6Status: Connected
7Number of entries: 0
8

给TA打赏
共{{data.count}}人
人已打赏
安全网络

CDN安全市场到2022年价值76.3亿美元

2018-2-1 18:02:50

安全技术

Redis常用命令

2021-8-18 16:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索