GFS原理及配置过程

GlusterFS概述

简介

Glusterfs是一个开源的分布式文件系统,是Scale存储的核心,能够处理千数量级的客户端.在传统的解决 方案中Glusterfs能够灵活的结合物理的,虚拟的和云资源去体现高可用和企业级的性能存储.
Glusterfs通过TCP/IP或InfiniBand RDMA网络链接将客户端的存储资块源聚集在一起,使用单一的全局命名空间来管理数据,磁盘和内存资源.
Glusterfs基于堆叠的用户空间设计,可以为不同的工作负载提供高优的性能.

特点

扩展性和高性能

GlusterFS利用双重特性来提供几TB至数PB的高扩展存储解决方案。Scale-Out架构允许通过简单地增加资源来提高存储容量和性能,磁盘、计算和I/O资源都可以独立增加,支持10GbE和InfiniBand等高速网络互联。Gluster弹性哈希(Elastic Hash)解除了GlusterFS对元数据服务器的需求,消除了单点故障和性能瓶颈,真正实现了并行化数据访问。

高可用性

GlusterFS可以对文件进行自动复制,如镜像或多次复制,从而确保数据总是可以访问,甚至是在硬件故障的情况下也能正常访问。自我修复功能能够把数据恢复到正确的状态,而且修复是以增量的方式在后台执行,几乎不会产生性能负载。GlusterFS没有设计自己的私有数据文件格式,而是采用操作系统中主流标准的磁盘文件系统(如EXT3、ZFS)来存储文件,因此数据可以使用各种标准工具进行复制和访问。

全局统一命名空间

全局统一命名空间将磁盘和内存资源聚集成一个单一的虚拟存储池,对上层用户和应用屏蔽了底层的物理硬件。存储资源可以根据需要在虚拟存储池中进行弹性扩展,比如扩容或收缩。当存储虚拟机映像时,存储的虚拟映像文件没有数量限制,成千虚拟机均通过单一挂载点进行数据共享。虚拟机I/O可在命名空间内的所有服务器上自动进行负载均衡,消除了SAN环境中经常发生的访问热点和性能瓶颈问题。

弹性卷管理

数据储存在逻辑卷中,逻辑卷可以从虚拟化的物理存储池进行独立逻辑划分而得到。存储服务器可以在线进行增加和移除,不会导致应用中断。逻辑卷可以在所有配置服务器中增长和缩减,可以在不同服务器迁移进行容量均衡,或者增加和移除系统,这些操作都可在线进行。文件系统配置更改也可以实时在线进行并应用,从而可以适应工作负载条件变化或在线性能调优。

基于标准协议

Gluster存储服务支持NFS, CIFS, HTTP, FTP以及Gluster原生协议,完全与POSIX标准兼容。现有应用程序不需要作任何修改或使用专用API,就可以对Gluster中的数据进行访问。这在公有云环境中部署Gluster时非常有用,Gluster对云服务提供商专用API进行抽象,然后提供标准POSIX接口。

GlusterFS相关术语

  • Brick:GFS中的存储单元,通过是一个受信存储池中的服务器的一个导出目录。可以通过主机名和目录名来标识,如’SERVER:EXPORT’
  • Volume:一组bricks的逻辑集合(卷)
  • FUSE:Filesystem Userspace是一个可加载的内核模块,其支持非特权用户创建自己的文件系统而不需要修改内核代码。通过在用户空间运行文件系统的代码通过FUSE代码与内核进行桥接。
  • VFS:虚拟文件系统
  • Glusterd:Gluster management daemon,要在trusted storage pool中所有的服务器上运行。
    Node:一个拥有若干brick的设备
    Client: 挂载了GFS卷的设备
    RDMA:远程直接内存访问,支持不通过双方的OS进行直接内存访问。
    RRDNS:round robin DNS是一种通过DNS轮转返回不同的设备以进行负载均衡的方法
    Self-heal:用于后台运行检测复本卷中文件和目录的不一致性并解决这些不一致。
    Split-brain:脑裂
    Volfile:glusterfs进程的配置文件,通常位于/var/lib/glusterd/vols/volname

模块化堆栈式架构

1、模块化、堆栈式的架构
2、通过对模块的组合,实现复杂的功能
GlusterFS采用模块化、堆栈式的架构,可通过灵活的配置支持高度定制化的应用环境,比如大文件存储、海量小文件存储、云存储、多传输协议应用等。每个功能以模块形式实现,然后以积木方式进行简单的组合,即可实现复杂的功能。比如,Replicate模块可实现RAID1,Stripe模块可实现RAID0,通过两者的组合可实现RAID10和RAID01,同时获得高性能和高可靠性。如下图所示

GlusterFS工作原理

弹性hash算法

1、通过hash算法得到一个32位的整数
2、划分为N个连续的子空间,每个空间对应一个Brick
3、弹性hash算法的优点

  • 保证数据平均分布在每一个Brick中
  • 解决了对元数据服务器的依赖,进而解决了单点故障以及访问瓶颈

GlusterFS工作流程

1、客户端或应用程序通过GlusterFS的挂载点访问数据,对于用户来说,集群系统的存在对用户是完全透明的,用户感觉不到是操作本地系统还是远端的集群系统。
2、用户的这个操作被递交给 本地linux系统的VFS来处理。
3、VFS将数据递交给FUSE内核文件系统, fuse文件系统则是将数据通过/dev/fuse设备文件递交给了GlusterFS client端,所以, 我们可以将 fuse文件系统理解为一个代理。
4、GlusterFS client 收到数据后,client根据配置文件的配置对数据进行处理
5、通过网络将数据传递至远端的GlusterFS Server,并且将数据写入到服务器存储设备上

GlusterFS的卷类型

分布式卷

  • 没有对文件进行分块处理
  • 通过扩展文件属性保存hash值
  • 支持的底层文件系统有ext4、zfs、xfs等
  • 特点
    文件分布在不同的服务器,不具备冗余性
    可以灵活的扩展卷的大小
    单点故障会造成数据丢失
    依赖底层的数据保护
  • 创建分布式卷
    创建一个名为dis-vol的分布式卷,文件将根据hash分布在node1:/data/sdb node2:/data/sdb中
gluster volume create dis-vol node1:/data/sdb node2:/data/sdb force

条带卷

1、根据偏移量将文件分成N块(N个条带节点),轮询的存储在每个Brick Server节点
2、存储大文件时,性能尤为突出
3、不具备冗余性,类似Raid0
4、特点
数据被分割成更小块分布到块服务器中的不同条带区
分布减少了负载且更小的文件加速了存取的速度
没有数据冗余
5、创建条带卷
创建了一个名为stripe-vol的条带卷,文件将被分块轮询的存储在node1:/data/sdc node2:/data/sdc中

gluster volume create stripe-vol stripe 2 transport tcp node1:/data/sdc node2:/data/sdc
(transport不指明时默认是RDMA)

复制卷

1、同一个文件保存一份或多份副本
2、因为要保存副本,所以磁盘利用率较低
3、若多个节点上的存储空间不一致,将按照木桶效应取最低节点的容量作为该卷的总容量
4、特点
卷中所有的服务器均保存一个完整的副本
卷的副本数量可由客户创建的时候决定
至少有两个块服务器或更多服务器
具备冗余性
5、创建复制卷
创建名为rep-vol的复制卷,文件将同时存储两个副本,分别在node3:/data/sdb node4:/data/sdb两个Brick中

gluster volume create rep-vol replica 2 node3:/data/sdb node4:/data/sdb force

分布式条带卷

1、兼顾分布式卷和条带卷的功能
2、主要用于大文件访问处理
3、最少需要4台服务器
4、创建分布式条带卷
创建了名为dis-stripe的分布式条带卷,配置分布式的条带卷时,卷中Brick所包含的存储服务器数必须是条带数的倍数(>=2倍)

gluster volume create dis-stripe stripe 2 node1:/data/sdd node2:/data/sdd node3:/data/sdd node4:/data/sdd force

分布式复制卷

1、兼顾分布式卷和复制卷的功能
2、用于需要冗余的情况
3、创建分布式复制卷
创建名为dis-rep的分布式条带卷,配置分布式复制卷时,卷中Brick所包含的存储服务器数必须是条带数的倍数(>=2倍)

gluster volume create dis-rep replica 2 node1:/data/sde node2:/data/sde node3:/data/sde node4:/data/sde force

部署GlusterFS卷

实验环境

node1
20.0.0.11

node2
20.0.0.12

node3
20.0.0.13

node4
20.0.0.15

安装软件

服务端:glusterfs;glusterfs-server;glusterfs-fuse;glusterfs-rdma
客户端:glusterfs;glusterfs-fuse

###
glusterfs:命令软件包
glusterfs-server:glusterfs服务软件
glusterfs-fuse:内核模块软件
glusterfs-rdma:通讯协议RDMA软件包
###

实现步骤

构建存储池子

1.每个节点添加4块磁盘,每块都是20G,格式化后进行挂载
在这里插入图片描述

[root@server1 ~]# fdisk -l
………………
磁盘 /dev/sdb: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/sdd: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 字节
………………

2.格式化磁盘并挂载

[root@server1 ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0x5aa97b7b 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):n #创建分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p #新建主分区
分区号 (1-4,默认 1): #回车,默认1
起始 扇区 (2048-41943039,默认为 2048): #回车,默认2048MB
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039): #回车,默认41943039
将使用默认值 41943039
分区 1 已设置为 Linux 类型,大小设为 20 GiB 

命令(输入 m 获取帮助):w #保存分区信息
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。

###
同样操作创建sdc,sdd,sde
###

[root@server1 ~]# fdisk -l
磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O 大小(最小/最佳)512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x5aa97b7b

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496   83  Linux

磁盘 /dev/sdc:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O 大小(最小/最佳)512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xb32d6804

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048    41943039    20970496   83  Linux

磁盘 /dev/sdd:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O 大小(最小/最佳)512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x1efc4291

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdd1            2048    41943039    20970496   83  Linux

磁盘 /dev/sde:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O 大小(最小/最佳)512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x4131ad0b

   设备 Boot      Start         End      Blocks   Id  System
/dev/sde1            2048    41943039    20970496   83  Linux

格式化磁盘,设置文件系统为xfs

[root@server1 ~]# mkfs -t xfs /dev/sdb1 
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242624 blocks
262131 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2153775104
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成   

[root@server1 ~]# mkfs -t xfs /dev/sdc1 #相同操作格式化其余磁盘
[root@server1 ~]# mkfs -t xfs /dev/sdd1
[root@server1 ~]# mkfs -t xfs /dev/sde1

创建挂载目录

[root@server1 ~]# mkdir /data 
[root@server1 data]# mkdir sdb sdc sdd sde

[root@server1 ~]# vi /etc/fstab #将以下磁盘信息添加到自动挂载目录末尾
/dev/sdb1              /data/sdb                             xfs    defaults        0 0
/dev/sdc1              /data/sdc                             xfs    defaults        0 0
/dev/sdd1              /data/sdd                             xfs    defaults        0 0
/dev/sde1              /data/sde                             xfs    defaults        0 0

[root@server1 ~]# mount -a #更新挂载信息

[root@server1 ~]# df -Th #查看挂载信息
………………
/dev/sdb1               xfs       20G   45M   19G    1% /data/sdb
/dev/sdc1               xfs       20G   45M   19G    1% /data/sdc
/dev/sdd1               xfs       20G   45M   19G    1% /data/sdd
/dev/sde1               xfs       20G   45M   19G    1% /data/sde

也采用如下的脚本进行格式化并挂载到系统中

[root@server1 ~]# vim sd.sh 
#!/bin/bash
for i in {b,c,d,e}
do

    echo "n
           p



           w" | fdisk /dev/sd$i
         mkdir -p /data/sd$i
         mkfs.xfs /dev/sd${i}1

cat>>/etc/fstab<<EOF
/dev/sd${i}1 /data/sd$i xfs defaults 0 0
EOF

done
mount -a

[root@server1 ~]# ./sd.sh 

[root@server1 ~]# df -Th #务必检查挂载情况
………………
/dev/sdb1               xfs        20G   33M   20G    1% /data/sdb
/dev/sdc1               xfs        20G   33M   20G    1% /data/sdc
/dev/sdd1               xfs        20G   33M   20G    1% /data/sdd
/dev/sde1               xfs        20G   33M   20G    1% /data/sde

3.修改主机名,添加主机名解析到本地hosts文件中(以node1为例)

[root@server1 ~]# hostnamectl set-hostname node1
[root@server1 ~]# bash

[root@node1 ~]# vim /etc/hosts
20.0.0.11 node1
20.0.0.12 node2
20.0.0.13 node3
20.0.0.15 node4

4.安装glusterfs相应软件并启动服务 (以node1为例)
四台node主机都搭建本地yum仓库,安装GLFS软件

[root@node1 ~]# unzip gfsrepo.zip #解压GFS压缩包,此时在/root目录下

[root@node1 ~]# vim /etc/yum.repos.d/GLFS.repo #配置GLF本地源,其他本地源全部放入备份文件中
[GLFS]
name=glfs
baseurl=file:///root/gfsrepo #选择本地源仓库路径
gpgcheck=0
enabled=1

[root@node1 ~]# yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma #安装GLFS软件

[root@node1 ~]# systemctl start glusterd.service #启动GLFS软件
[root@node1 ~]# systemctl enable glusterd.service #设置GLFS开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/glusterd.service to /usr/lib/systemd/system/glusterd.service.

5.时间同步

[root@node1 ~]# ntpdate ntp.aliyun.com

6.构建存储池子(在任意节点即可,需将节点全部安装后设置)
###peer:匹配,probe:添加

[root@node1 ~]# gluster peer probe node2 #添加节点2
peer probe: success. 
[root@node1 ~]# gluster peer probe node3 #添加节点3
peer probe: success. 
[root@node1 ~]# gluster peer probe node4 #添加节点4
peer probe: success. 
[root@node1 ~]# gluster peer status #查看节点状态
Number of Peers: 3

Hostname: node2
Uuid: 3e355e63-e3fa-4d2b-b74f-ef06868073db
State: Peer in Cluster (Connected)

Hostname: node3
Uuid: 5c80ee28-089b-4a12-8f3b-4fd8c3252c4e
State: Peer in Cluster (Connected)

Hostname: node4
Uuid: 0ebbf32b-3e23-4458-9ff0-6648b880ec87
State: Peer in Cluster (Connected)

根据规划创建如下卷

卷名称卷类型空间大小(GB)Brick
dis-vol分布式卷40node1:/data/sdb;node2:/data/sdb
stripe-vol条带卷40node1:/data/sdc;node2:/data/sdc
rep-vol复制卷20node3:/data/sdb;node4:/data/sdb
dis-stripe分布式条带卷80node1:/data/sdd;node2:/data/sdd;node3:/data/sdd;node4:/data/sdd
dis-rep分布式复制卷40node1:/data/sde;node2:/data/sde;node3:/data/sde;node4:/data/sde

客户端

添加4个服务器节点的主机名解析

[root@client ~]# vim /etc/hosts
20.0.0.11 node1
20.0.0.12 node2
20.0.0.13 node3
20.0.0.15 node4

安装glusterfs软件

[root@client ~]# yum -y install glusterfs glusterfs-fuse

创建5个40M的文件

[root@client ~]# dd if=/dev/zero of=/opt/test1.txt bs=1M count=40
记录了40+0 的读入
记录了40+0 的写出
41943040字节(42 MB)已复制,0.0152728 秒,2.7 GB/[root@client ~]# dd if=/dev/zero of=/opt/test2.txt bs=1M count=40
记录了40+0 的读入
记录了40+0 的写出
41943040字节(42 MB)已复制,0.018502 秒,2.3 GB/[root@client ~]# dd if=/dev/zero of=/opt/test3.txt bs=1M count=40
记录了40+0 的读入
记录了40+0 的写出
41943040字节(42 MB)已复制,0.0577598 秒,726 MB/[root@client ~]# dd if=/dev/zero of=/opt/test4.txt bs=1M count=40
记录了40+0 的读入
记录了40+0 的写出
41943040字节(42 MB)已复制,0.0817769 秒,513 MB/[root@client ~]# dd if=/dev/zero of=/opt/test5.txt bs=1M count=40
记录了40+0 的读入
记录了40+0 的写出
41943040字节(42 MB)已复制,0.0869931 秒,482 MB/

创建分布式卷

[root@node1 data]#  gluster volume create dis-vol node1:/data/sdb node2:/data/sdb force #gluster volume create:创建分布式卷,dis-vol:自己定义的名称,node1:/data/sdb node2:/data/sdb:指定的节点,force:强制执行
volume create: dis-vol: success: please start the volume to access data
[root@node1 data]# gluster volume info dis-vol #查看分布式卷信息
Volume Name: dis-vol
Type: Distribute
Volume ID: 464ada88-ea95-4f7c-9e38-6ab0bc9a2e29
Status: Created #关闭状态,没有被应用
Snapshot Count: 0
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: node1:/data/sdb #两个节点
Brick2: node2:/data/sdb
Options Reconfigured:
transport.address-family: inet
nfs.disable: on

[root@node1 ~]# gluster volume list #查看创建的卷
dis-vol

[root@node1 data]# 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: 464ada88-ea95-4f7c-9e38-6ab0bc9a2e29
Status: Started #开启状态
Snapshot Count: 0
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: node1:/data/sdb
Brick2: node2:/data/sdb
Options Reconfigured:
transport.address-family: inet
nfs.disable: on

客户端挂载分布式卷到/test/dis目录下,并将5个测试文件拷贝进去

[root@client ~]# mkdir -p /text/dis #创建挂载点
[root@client ~]# mount.glusterfs node1:dis-vol /text/dis/ #挂载
[root@client ~]# df -Th
文件系统       类型            容量  已用  可用 已用% 挂载点
/dev/sda3      xfs              58G  3.8G   54G    7% /
devtmpfs       devtmpfs        898M     0  898M    0% /dev
tmpfs          tmpfs           912M     0  912M    0% /dev/shm
tmpfs          tmpfs           912M  9.0M  903M    1% /run
tmpfs          tmpfs           912M     0  912M    0% /sys/fs/cgroup
/dev/sda1      xfs             297M  157M  141M   53% /boot
tmpfs          tmpfs           183M   28K  183M    1% /run/user/0
/dev/sr0       iso9660         4.4G  4.4G     0  100% /mnt
node1:dis-vol  fuse.glusterfs   40G   65M   40G    1% /text/dis

将创建的5个测试文件拷贝进挂载点

[root@client ~]# cp /opt/test* /text/dis/

node1和node2节点中查看5个文件分布情况

node1
[root@node1 ~]# ll /data/sdb
总用量 122880
-rw-r--r--. 2 root root 41943040 13 21:49 test1.txt
-rw-r--r--. 2 root root 41943040 13 21:49 test3.txt
-rw-r--r--. 2 root root 41943040 13 21:49 test4.txt
node1分到3个文件
node2
[root@node2 ~]# ll /data/sdb
总用量 81920
-rw-r--r--. 2 root root 41943040 13 21:49 test2.txt
-rw-r--r--. 2 root root 41943040 13 21:49 test5.txt
node2分到2个文件

创建复制卷

[root@node1 ~]# gluster volume create rep-vol replica 2 node3:/data/sdb node4:/data/sdb force #创建复制卷,replica 2:两个分片
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:/data/sdb                       49152     0          Y       52554
Brick node4:/data/sdb                       49152     0          Y       46604
Self-heal Daemon on localhost               N/A       N/A        Y       4098 
Self-heal Daemon on node3                   N/A       N/A        Y       52574
Self-heal Daemon on node2                   N/A       N/A        Y       15725
Self-heal Daemon on node4                   N/A       N/A        Y       46624
 
Task Status of Volume rep-vol
------------------------------------------------------------------------------
There are no active volume tasks

客户端挂载复制卷到/test/rep-vol目录下,并将5个测试文件拷贝进去

[root@client ~]# mkdir /text/rep-vol
[root@client ~]# mount.glusterfs node1:rep-vol /text/rep-vol/
[root@client ~]# df -Th
文件系统       类型            容量  已用  可用 已用% 挂载点
/dev/sda3      xfs              58G  3.8G   54G    7% /
devtmpfs       devtmpfs        898M     0  898M    0% /dev
tmpfs          tmpfs           912M     0  912M    0% /dev/shm
tmpfs          tmpfs           912M  9.0M  903M    1% /run
tmpfs          tmpfs           912M     0  912M    0% /sys/fs/cgroup
/dev/sda1      xfs             297M  157M  141M   53% /boot
tmpfs          tmpfs           183M   28K  183M    1% /run/user/0
/dev/sr0       iso9660         4.4G  4.4G     0  100% /mnt
node1:dis-vol  fuse.glusterfs   40G  265M   40G    1% /text/dis
node1:rep-vol  fuse.glusterfs   20G   33M   20G    1% /text/rep-vol

[root@client ~]# cp /opt/test* /text/rep-vol/

node3和node4节点中查看5个文件分布情况
node3

[root@node3 ~]# ll /data/sdb
总用量 204800
-rw-r--r-- 2 root root 41943040 13 22:03 test1.txt
-rw-r--r-- 2 root root 41943040 13 22:03 test2.txt
-rw-r--r-- 2 root root 41943040 13 22:03 test3.txt
-rw-r--r-- 2 root root 41943040 13 22:03 test4.txt
-rw-r--r-- 2 root root 41943040 13 22:03 test5.txt

node4

[root@node4 ~]# ll /data/sdb
总用量 204800
-rw-r--r--. 2 root root 41943040 13 22:03 test1.txt
-rw-r--r--. 2 root root 41943040 13 22:03 test2.txt
-rw-r--r--. 2 root root 41943040 13 22:03 test3.txt
-rw-r--r--. 2 root root 41943040 13 22:03 test4.txt
-rw-r--r--. 2 root root 41943040 13 22:03 test5.txt

创建分布式复制卷

[root@node1 ~]# gluster volume create dis-rep replica 2 node1:/data/sde node2:/data/sde node3:/data/sde node4:/data/sde force

[root@node1 ~]# gluster volume start dis-rep 
volume start: dis-rep: success

客户端挂载分布式复制卷到/test/dis-rep目录下,并将5个测试文件拷贝进去

[root@client ~]# mkdir /text/dis-rep
[root@client ~]# mount.glusterfs node1:dis-rep /text/dis-rep/
[root@client ~]# df -Th
文件系统       类型            容量  已用  可用 已用% 挂载点
/dev/sda3      xfs              58G  3.8G   54G    7% /
devtmpfs       devtmpfs        898M     0  898M    0% /dev
tmpfs          tmpfs           912M     0  912M    0% /dev/shm
tmpfs          tmpfs           912M  9.0M  903M    1% /run
tmpfs          tmpfs           912M     0  912M    0% /sys/fs/cgroup
/dev/sda1      xfs             297M  157M  141M   53% /boot
tmpfs          tmpfs           183M   28K  183M    1% /run/user/0
/dev/sr0       iso9660         4.4G  4.4G     0  100% /mnt
node1:dis-vol  fuse.glusterfs   40G  265M   40G    1% /text/dis
node1:rep-vol  fuse.glusterfs   20G  233M   20G    2% /text/rep-vol
node1:dis-rep  fuse.glusterfs   40G   65M   40G    1% /text/dis-rep

[root@client ~]# cp /opt/test* /text/dis-rep/

node1、node2、node3和node4节点中查看5个文件分布情况
node1

[root@node1 ~]# ll /data/sde
总用量 122880
-rw-r--r--. 2 root root 41943040 13 22:10 test1.txt
-rw-r--r--. 2 root root 41943040 13 22:10 test3.txt
-rw-r--r--. 2 root root 41943040 13 22:10 test4.txt

node2

[root@node2 ~]# ll /data/sde
总用量 122880
-rw-r--r--. 2 root root 41943040 13 22:10 test1.txt
-rw-r--r--. 2 root root 41943040 13 22:10 test3.txt
-rw-r--r--. 2 root root 41943040 13 22:10 test4.txt

node3

[root@node3 ~]# ll /data/sde
总用量 81920
-rw-r--r-- 2 root root 41943040 13 22:10 test2.txt
-rw-r--r-- 2 root root 41943040 13 22:10 test5.txt

node4

[root@node4 ~]# ll /data/sde
总用量 81920
-rw-r--r--. 2 root root 41943040 13 22:10 test2.txt
-rw-r--r--. 2 root root 41943040 13 22:10 test5.txt
node1和node2节点中互为备份的存了三个文件
node3和node4节点中互为备份的存了剩下的两个文件

破坏测试

将node2宕机掉模拟故障,查看客户端中挂载点中依然存在的文件

[root@client text]# ll -h dis
总用量 120M
-rw-r--r--. 1 root root 40M 13 05:49 test1.txt
-rw-r--r--. 1 root root 40M 13 05:49 test3.txt
-rw-r--r--. 1 root root 40M 13 05:49 test4.txt
[root@client text]# ll -h dis-rep
总用量 200M
-rw-r--r--. 1 root root 40M 13 06:10 test1.txt
-rw-r--r--. 1 root root 40M 13 06:10 test2.txt
-rw-r--r--. 1 root root 40M 13 06:10 test3.txt
-rw-r--r--. 1 root root 40M 13 06:10 test4.txt
-rw-r--r--. 1 root root 40M 13 06:10 test5.txt
[root@client text]# ll -h rep-vol
总用量 200M
-rw-r--r--. 1 root root 40M 13 06:03 test1.txt
-rw-r--r--. 1 root root 40M 13 06:03 test2.txt
-rw-r--r--. 1 root root 40M 13 06:03 test3.txt
-rw-r--r--. 1 root root 40M 13 06:03 test4.txt
-rw-r--r--. 1 root root 40M 13 06:03 test5.txt

复制卷、分布式复制卷的数据完整
条带卷数据全部丢失,分布式卷丢失一部分

GlusterFS常用命令

1.启动/关闭/查看glusterd服务

/etc/init.d/glusterd start

/etc/init.d/glusterd stop

/etc/init.d/glusterd status

2.开机自动启动glusterd服务

chkconfig glusterd on

3.为存储池添加/移除服务器节点
在其中一个节点上操作即可:

gluster peer probe <SERVER>

gluster peer detach <SERVER>

注意,移除节点时,需要提前将该节点上的Brick移除。

4.创建/启动/停止/删除卷

gluster volume create <NEW-VOLNAME>[stripe <COUNT> | replica <COUNT>] [transport [tcp | rdma | tcp,rdma]] <NEW-BRICK1> <NEW-BRICK2> <NEW-BRICK3> <NEW-BRICK4>...

gluster volume start <VOLNAME>

gluster volume stop <VOLNAME>

gluster volume delete <VOLNAME>

注意,删除卷的前提是先停止卷。

5.客户端以glusterfs方式挂载

mount.glusterfs <SERVER>:/<VOLNAME><MOUNTDIR>
或
mount -t glusterfs <SERVER>:/<VOLNAME><MOUNTDIR>

6.查看卷信息
列出集群中的所有卷:

gluster volume list

查看集群中的卷信息:

gluster volume info [all]

查看集群中的卷状态:

gluster volume status [all]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值