GlusterFS简介
开源的分布式文件系统
由存储服务器、客户端以及NFS/Samba存储网关组成
无元数据服务器
GlusterFS特点
扩展性和高性能
高可用性
全局统一命名空间
弹性卷管理
基于标准协议
GlusterFS术语
Brick
Volume
FUSE
VFS
Glusterd
模块化堆栈式架构
模块化、堆栈式的架构
通过对模块的组合,实现复杂的功能
GlusterFS工作流程
弹性HASH算法
通过HASH算法得到一个32位的整数
划分为N个连续的子空间,每个空间对应一个Brick
弹性HASH算法的优点
保证数据平均分布在每一个Brick中
解决了对元数据服务器的依赖,进而解决了单点故障以及访问瓶颈
GlusterFS的卷类型
分布式卷
没有对文件进行分块处理
通过扩展文件属性保存HASH值
支持的底层文件系统有EXT3、EXT4、ZFS、XFS等
分布式卷的特点
文件分布在不同的服务器,不具备冗余性
更容易和廉价地扩展卷地大小
单点故障会造成数据丢失
依赖底层的数据保护
条带卷
根据偏移量将文件分层N块(N个条带节点),轮询地存储在每个Brick Server节点
存储大文件时,性能尤为突出
不具备冗余性,类型Reid0
条带卷的特点
数据被分割成更小块分布到块服务器群中的不同条带区
分布减少了负载且更小的文件加速了存取的速度
没有数据冗余
创建条带卷
创建了一个名为Stripe-volume的条带卷,文件将被分块轮询的存储在Server1:/dir1和Server2:/dir2两个Brick中
gluster volume create stripe-volume stripe 2 transport tcp server1:/dir1 server2:/dir2
复制卷
同一文件保存一份或多份副本
因为要保存副本,所以磁盘利用率较低
若多个节点上的存储空间不一致,将按照磁盘容量最低节点的容量作为该卷的总容量
复制卷的特点
卷中所有的服务器均保存一个完整的副本
卷的副本数量可由客户创建的时候决定
至少有两个块服务器或更多服务器
具备冗余性
创建复制卷
创建了一个名为rep-volume的条带卷,文件将同时存储两个副本,分布在Server1:/dir1和Server2:/dir2两个Brick中
gluster volume create rep-volume replica 2 transport tcp server1:/dir1 server2:/dir2
分布式条带卷
兼顾分布式卷和条带卷的功能
主要用于大文件访问处理
至少最少需要4台服务器
创建分布式条带卷
创建了名为dis-stripe的分布式条带卷,配置分布式的条带卷时,卷中Brick所包含的存储服务器数必须是条带数的倍数(>=2倍)
gluster volume create dis-stripe stripe 2 transport tcp server1:/dir1 server2:/dir2 server3:/dir3 server4:/dir4
分布式复制卷
兼顾分布式卷和复制卷的功能
用于需要冗余的情况
GlusterFS部署
群集环境
主机名 | IP地址 |
---|---|
node1 | 20.0.0.10 |
node2 | 20.0.0.20 |
node3 | 20.0.0.30 |
node4 | 20.0.0.40 |
client | 20.0.0.50 |
部署
每个node节点上设置四个磁盘,每个磁盘5G
添加映射(node1、node2、node3、node4和client上设置)
[root@node1 yum.repos.d]# systemctl stop firewalld
[root@node1 yum.repos.d]# setenforce 0
[root@node1 ~]# vi /etc/hosts #node1上演示
20.0.0.10 node1
20.0.0.20 node2
20.0.0.30 node3
20.0.0.40 node4
解压缩并安装软件(node1、node2、node3、node4和client上安装)
[root@node1 ~]# unzip gfsrepo.zip #node上演示
[root@node1 ~]# cd /etc/yum.repos.d/ #设置源
[root@node1 yum.repos.d]# vi GLFS.repo
[GLFS]
name=glfs
baseurl=file:///root/gfsrepo
gpgcheck=0
enabled=1
[root@node1 yum.repo.d]# rm -rf local.repo
[root@node1 ~]# yum -y install glusterfs glusterfs-server gluster-fuse glusterfs-rdma
开启服务
[root@node1 yum.repos.d]# systemctl start glusterd.service
[root@node1 yum.repos.d]# systemctl enable glusterd.service
[root@node1 yum.repos.d]# systemctl status glusterd.service
时间同步(node1、node2、node3、node4上安装)
[root@node1 ~]# ntpdate ntp1.aliyun.com
添加入存储信任池只要在一台主机上添加其他机器(node1上设置)
[root@node1 yum.repos.d]# gluster peer probe node2
peer probe: success.
[root@node1 yum.repos.d]# gluster peer probe node3
peer probe: success.
[root@node1 yum.repos.d]# gluster peer probe node4
peer probe: success.
查看节点状态
[root@node1 yum.repos.d]# gluster peer status
Number of Peers: 3
Hostname: node2
Uuid: 4f51d9b8-c635-498a-82ee-b46d841e4fa1
State: Peer in Cluster (Connected)
Hostname: node3
Uuid: b675a395-4dde-4b3d-8f8f-62c23b11abc7
State: Peer in Cluster (Connected)
Hostname: node4
Uuid: 3425cbbc-ce66-4c43-9934-3ed07d15f956
State: Peer in Cluster (Connected)
初始化磁盘(node1、node2、node3、node4)
[root@node1 yum.repos.d]# fdisk -l
[root@node1 yum.repos.d]# fdisk /dev/sdb
[root@node1 yum.repos.d]# fdisk /dev/sdb
[root@node1 yum.repos.d]# fdisk /dev/sdb
[root@node1 yum.repos.d]# fdisk /dev/sdb
[root@node1 yum.repos.d]# fdisk -l
[root@node1 yum.repos.d]# mkfs.ext4 /dev/sdb1
[root@node1 yum.repos.d]# mkfs.ext4 /dev/sdc1
[root@node1 yum.repos.d]# mkfs.ext4 /dev/sdd1
[root@node1 yum.repos.d]# mkfs.ext4 /dev/sde1
创建卷类型(node1、node2、node3、node4)
挂载磁盘
[root@node1 yum.repos.d]# mkdir -p /data/{sdb1,sdc1,sdd1,sde1}
[root@node1 yum.repos.d]# mount /dev/sdb1 /data/sdb1
[root@node1 yum.repos.d]# mount /dev/sdc1 /data/sdc1
[root@node1 yum.repos.d]# mount /dev/sdd1 /data/sdd1
[root@node1 yum.repos.d]# mount /dev/sde1 /data/sde1
[root@node1 yum.repos.d]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root xfs 37G 4.5G 33G 13% /
devtmpfs devtmpfs 897M 0 897M 0% /dev
tmpfs tmpfs 912M 0 912M 0% /dev/shm
tmpfs tmpfs 912M 9.1M 903M 1% /run
tmpfs tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sr0 iso9660 4.3G 4.3G 0 100% /mnt
/dev/sda1 xfs 1014M 179M 836M 18% /boot
tmpfs tmpfs 183M 12K 183M 1% /run/user/42
tmpfs tmpfs 183M 0 183M 0% /run/user/0
/dev/sdb1 ext4 4.8G 20M 4.6G 1% /data/sdb1
/dev/sdc1 ext4 4.8G 20M 4.6G 1% /data/sdc1
/dev/sdd1 ext4 4.8G 20M 4.6G 1% /data/sdd1
/dev/sde1 ext4 4.8G 20M 4.6G 1% /date/sde1
分布式卷
[root@node1 yum.repos.d]# 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@node1 yum.repos.d]# gluster volume info dis-vol #查看状态信息
Volume Name: dis-vol
Type: Distribute
Volume ID: 88e88b9f-b3bc-4946-ac11-c7a90ec17acf
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@node1 yum.repos.d]# gluster volume start dis-vol #开启
volume start: dis-vol: success
[root@node1 yum.repos.d]# gluster volume status dis-vol #查看状态
Status of volume: dis-vol
Gluster process TCP Port RDMA Port Online Pid
------------------------------------------------------------------------------
Brick node1:/data/sdb1 49152 0 Y 2924
Brick node2:/data/sdb1 49152 0 Y 2915
Task Status of Volume dis-vol
------------------------------------------------------------------------------
There are no active volume tasks
条带卷
[root@node1 yum.repos.d]# gluster volume create stripe-vol stripe 2 node3:/data/sdb1 node4:/data/sdb1 force
volume create: stripe-vol: success: please start the volume to access data
[root@node1 yum.repos.d]# gluster volume info stripe-vol
Volume Name: stripe-vol
Type: Stripe
Volume ID: a6f10da6-c933-469a-9c84-49f55c3ede0e
Status: Created
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: node3:/data/sdb1
Brick2: node4:/data/sdb1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
[root@node1 yum.repos.d]# gluster volume start stripe-vol
volume start: stripe-vol: success
[root@node1 yum.repos.d]# gluster volume status stripe-vol
Status of volume: stripe-vol
Gluster process TCP Port RDMA Port Online Pid
------------------------------------------------------------------------------
Brick node3:/data/sdb1 49152 0 Y 13678
Brick node4:/data/sdb1 49152 0 Y 13759
Task Status of Volume stripe-vol
------------------------------------------------------------------------------
There are no active volume tasks
复制卷
[root@node1 yum.repos.d]# gluster volume create rep-vol replica 2 node1:/data/sdc1 node2:/data/sdc1 force
volume create: rep-vol: success: please start the volume to access data
[root@node1 yum.repos.d]# gluster volume info rep-vol
Volume Name: rep-vol
Type: Replicate
Volume ID: 80ffeed8-6031-40a8-a2c3-80701d36d791
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@node1 yum.repos.d]# gluster volume start rep-vol
volume start: rep-vol: success
[root@node1 yum.repos.d]# gluster volume status rep-vol
Status of volume: rep-vol
Gluster process TCP Port RDMA Port Online Pid
------------------------------------------------------------------------------
Brick node1:/data/sdc1 49153 0 Y 3110
Brick node2:/data/sdc1 49153 0 Y 3065
Self-heal Daemon on localhost N/A N/A Y 3130
Self-heal Daemon on node2 N/A N/A Y 3085
Self-heal Daemon on node3 N/A N/A Y 13749
Self-heal Daemon on node4 N/A N/A Y 13837
Task Status of Volume rep-vol
------------------------------------------------------------------------------
There are no active volume tasks
分布式条带卷
[root@node1 yum.repos.d]# 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@node1 yum.repos.d]# gluster volume info dis-stripe
Volume Name: dis-stripe
Type: Distributed-Stripe
Volume ID: 58895adb-c659-432c-a41a-5dbb741cc718
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@node1 yum.repos.d]# gluster volume start dis-stripe
volume start: dis-stripe: success
[root@node1 yum.repos.d]# gluster volume status dis-stripe
Status of volume: dis-stripe
Gluster process TCP Port RDMA Port Online Pid
------------------------------------------------------------------------------
Brick node1:/data/sdd1 49154 0 Y 3213
Brick node2:/data/sdd1 49154 0 Y 3144
Brick node3:/data/sdd1 49153 0 Y 13807
Brick node4:/data/sdd1 49153 0 Y 13889
Task Status of Volume dis-stripe
------------------------------------------------------------------------------
There are no active volume tasks
分布式复制卷
[root@node1 yum.repos.d]# 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@node1 yum.repos.d]# gluster volume info dis-rep
Volume Name: dis-rep
Type: Distributed-Replicate
Volume ID: 57dc83f8-a6ae-4af4-9d4c-75a0da661fff
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
[root@node1 yum.repos.d]# gluster volume start dis-rep
volume start: dis-rep: success
[root@node1 yum.repos.d]# gluster volume status dis-rep
Status of volume: dis-rep
Gluster process TCP Port RDMA Port Online Pid
------------------------------------------------------------------------------
Brick node1:/data/sde1 49155 0 Y 3283
Brick node2:/data/sde1 49155 0 Y 3195
Brick node3:/data/sde1 49154 0 Y 13867
Brick node4:/data/sde1 49154 0 Y 13947
Self-heal Daemon on localhost N/A N/A Y 3303
Self-heal Daemon on node3 N/A N/A Y 13887
Self-heal Daemon on node4 N/A N/A Y 13967
Self-heal Daemon on node2 N/A N/A Y 3215
Task Status of Volume dis-rep
------------------------------------------------------------------------------
There are no active volume tasks
查看卷列表
[root@node1 yum.repos.d]# gluster volume list
dis-rep
dis-stripe
dis-vol
rep-vol
stripe-vol
挂载卷(客户机)
[root@client ~]# mkdir -p /text/{dis,stripe,rep,dis-stripe,dis-rep} #创建挂载目录
[root@client ~]# mount.glusterfs node1:dis-vol /text/dis #挂载分布卷
[root@client ~]# mount.glusterfs node1:stripe-vol /text/stripe #挂载条带卷
[root@client ~]# mount.glusterfs node1:rep-vol /text/rep #挂载复制卷
[root@client ~]# mount.glusterfs node1:dis-stripe /text/dis-stripe #挂载分布式条带卷
[root@client ~]# mount.glusterfs node1:dis-rep /text/dis-rep #挂载分布式复制卷
[root@client ~]# df -Th #查看磁盘占用情况
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root xfs 17G 1.5G 16G 9% /
devtmpfs devtmpfs 901M 0 901M 0% /dev
tmpfs tmpfs 912M 0 912M 0% /dev/shm
tmpfs tmpfs 912M 8.7M 904M 1% /run
tmpfs tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sr0 iso9660 4.3G 4.3G 0 100% /mnt
/dev/sda1 xfs 1014M 143M 872M 15% /boot
tmpfs tmpfs 183M 0 183M 0% /run/user/0
node1:dis-vol fuse.glusterfs 9.6G 41M 9.1G 1% /text/dis
node1:stripe-vol fuse.glusterfs 9.6G 41M 9.1G 1% /text/stripe
node1:rep-vol fuse.glusterfs 4.8G 21M 4.6G 1% /text/rep
node1:dis-stripe fuse.glusterfs 20G 81M 19G 1% /text/dis-stripe
node1:dis-rep fuse.glusterfs 9.6G 41M 9.1G 1% /text/dis-rep
测试
创建文件
创建测试文件
[root@client ~]# dd if=/dev/zero of=/demo1.log bs=40M count=1
记录了1+0 的读入
记录了1+0 的写出
41943040字节(42 MB)已复制,0.185274 秒,226 MB/秒
[root@client ~]# dd if=/dev/zero of=/demo2.log bs=40M count=1
记录了1+0 的读入
记录了1+0 的写出
41943040字节(42 MB)已复制,0.1539 秒,273 MB/秒
[root@client ~]# dd if=/dev/zero of=/demo3.log bs=40M count=1
记录了1+0 的读入
记录了1+0 的写出
41943040字节(42 MB)已复制,0.141536 秒,296 MB/秒
[root@client ~]# dd if=/dev/zero of=/demo4.log bs=40M count=1
记录了1+0 的读入
记录了1+0 的写出
41943040字节(42 MB)已复制,0.149856 秒,280 MB/秒
[root@client ~]# dd if=/dev/zero of=/demo5.log bs=40M count=1
记录了1+0 的读入
记录了1+0 的写出
41943040字节(42 MB)已复制,0.139292 秒,301 MB/秒
查看文件
[root@client ~]# cd /
[root@client /]# ll
拷贝文件到挂载目录下
[root@client /]# cp demo* /text/dis
[root@client /]# cp demo* /text/stripe
[root@client /]# cp demo* /text/rep
[root@client /]# cp demo* /text/dis-stripe
[root@client /]# cp demo* /text/dis-rep
查看文件
[root@client /]# ll /text/dis
[root@client /]# ll /text/stripe
[root@client /]# ll /text/rep
[root@client /]# ll /text/dis-stripe
[root@client /]# ll /text/dis-rep
查看分布式卷分布情况(node1:/data/sdb1,node2:/data/sdb1)
[root@node1 yum.repos.d]# ls -lh /data/sdb1
总用量 161M
-rw-r--r--. 2 root root 40M 11月 17 10:14 demo1.log
-rw-r--r--. 2 root root 40M 11月 17 10:14 demo2.log
-rw-r--r--. 2 root root 40M 11月 17 10:14 demo3.log
-rw-r--r--. 2 root root 40M 11月 17 10:14 demo4.log
drwx------. 2 root root 16K 11月 17 09:14 lost+found
[root@node2 yum.repos.d]# ls -lh /data/sdb1
总用量 41M
-rw-r--r--. 2 root root 40M 11月 17 10:14 demo5.log
drwx------. 2 root root 16K 11月 17 09:14 lost+found
查看条带卷分布情况(node3:/data/sdb1,node4:/data/sdb1)
[root@node3 yum.repos.d]# ls -lh /data/sdb1
总用量 101M
-rw-r--r--. 2 root root 20M 11月 17 10:14 demo1.log
-rw-r--r--. 2 root root 20M 11月 17 10:14 demo2.log
-rw-r--r--. 2 root root 20M 11月 17 10:14 demo3.log
-rw-r--r--. 2 root root 20M 11月 17 10:14 demo4.log
-rw-r--r--. 2 root root 20M 11月 17 10:14 demo5.log
drwx------. 2 root root 16K 11月 17 09:14 lost+found
[root@node4 yum.repos.d]# ls -lh /data/sdb1
总用量 101M
-rw-r--r--. 2 root root 20M 11月 17 10:14 demo1.log
-rw-r--r--. 2 root root 20M 11月 17 10:14 demo2.log
-rw-r--r--. 2 root root 20M 11月 17 10:14 demo3.log
-rw-r--r--. 2 root root 20M 11月 17 10:14 demo4.log
-rw-r--r--. 2 root root 20M 11月 17 10:14 demo5.log
drwx------. 2 root root 16K 11月 17 09:14 lost+found
查看复制卷分布情况(node1:/data/sdc1,node2:/data/sdc1)
[root@node1 yum.repos.d]# ls -lh /data/sdc1
总用量 201M
-rw-r--r--. 2 root root 40M 11月 17 10:14 demo1.log
-rw-r--r--. 2 root root 40M 11月 17 10:14 demo2.log
-rw-r--r--. 2 root root 40M 11月 17 10:14 demo3.log
-rw-r--r--. 2 root root 40M 11月 17 10:14 demo4.log
-rw-r--r--. 2 root root 40M 11月 17 10:14 demo5.log
drwx------. 2 root root 16K 11月 17 09:14 lost+found
[root@node2 yum.repos.d]# ls -lh /data/sdc1
总用量 201M
-rw-r--r--. 2 root root 40M 11月 17 10:14 demo1.log
-rw-r--r--. 2 root root 40M 11月 17 10:14 demo2.log
-rw-r--r--. 2 root root 40M 11月 17 10:14 demo3.log
-rw-r--r--. 2 root root 40M 11月 17 10:14 demo4.log
-rw-r--r--. 2 root root 40M 11月 17 10:14 demo5.log
drwx------. 2 root root 16K 11月 17 09:14 lost+found
查看分布式条带卷分布情况(node1:/data/sdd1 node2:/data/sdd1 node3:/data/sdd1 node4:/data/sdd1)
[root@node1 yum.repos.d]# ls -lh /data/sdd1
总用量 81M
-rw-r--r--. 2 root root 20M 11月 17 10:15 demo1.log
-rw-r--r--. 2 root root 20M 11月 17 10:15 demo2.log
-rw-r--r--. 2 root root 20M 11月 17 10:15 demo3.log
-rw-r--r--. 2 root root 20M 11月 17 10:15 demo4.log
drwx------. 2 root root 16K 11月 17 09:14 lost+found
[root@node2 yum.repos.d]# ls -lh /data/sdd1
总用量 81M
-rw-r--r--. 2 root root 20M 11月 17 10:15 demo1.log
-rw-r--r--. 2 root root 20M 11月 17 10:15 demo2.log
-rw-r--r--. 2 root root 20M 11月 17 10:15 demo3.log
-rw-r--r--. 2 root root 20M 11月 17 10:15 demo4.log
drwx------. 2 root root 16K 11月 17 09:14 lost+found
[root@node3 yum.repos.d]# ls -lh /data/sdd1
总用量 21M
-rw-r--r--. 2 root root 20M 11月 17 10:15 demo5.log
drwx------. 2 root root 16K 11月 17 09:14 lost+found
[root@node4 yum.repos.d]# ls -lh /data/sdd1
总用量 21M
-rw-r--r--. 2 root root 20M 11月 17 10:15 demo5.log
drwx------. 2 root root 16K 11月 17 09:14 lost+found
查看分布式复制卷分布情况(node1:/data/sde1 node2:/data/sde1 node3:/data/sde1 node4:/data/sde1)
[root@node1 yum.repos.d]# ls -lh /data/sde1
总用量 161M
-rw-r--r--. 2 root root 40M 11月 17 10:15 demo1.log
-rw-r--r--. 2 root root 40M 11月 17 10:15 demo2.log
-rw-r--r--. 2 root root 40M 11月 17 10:15 demo3.log
-rw-r--r--. 2 root root 40M 11月 17 10:15 demo4.log
drwx------. 2 root root 16K 11月 17 09:14 lost+found
[root@node2 yum.repos.d]# ls -lh /data/sde1
总用量 161M
-rw-r--r--. 2 root root 40M 11月 17 10:15 demo1.log
-rw-r--r--. 2 root root 40M 11月 17 10:15 demo2.log
-rw-r--r--. 2 root root 40M 11月 17 10:15 demo3.log
-rw-r--r--. 2 root root 40M 11月 17 10:15 demo4.log
drwx------. 2 root root 16K 11月 17 09:14 lost+found
[root@node3 yum.repos.d]# ls -lh /data/sde1
总用量 41M
-rw-r--r--. 2 root root 40M 11月 17 10:15 demo5.log
drwx------. 2 root root 16K 11月 17 09:14 lost+found
[root@node4 yum.repos.d]# ls -lh /data/sde1
总用量 41M
-rw-r--r--. 2 root root 40M 11月 17 10:15 demo5.log
drwx------. 2 root root 16K 11月 17 09:14 lost+found
访问控制
仅拒绝:
[root@node1 yum.repos.d]# gluster volume set dis-vol auth.reject 20.0.0.50
volume set: success
仅允许
[root@node1 yum.repos.d]# gluster volume set dis-vol auth.allow 20.0.0.50
volume set: success