centos7部署分布式存储glusterfs详解

一、环境准备

1、机器资源

主机名 主机IP 环境

glusterfs-node12.com

192.168.217.12

centos7.6,增加一块10G硬盘

glusterfs-node13.com

192.168.217.13

centos7.6,增加一块10G硬盘

glusterfs-node14.com

192.168.217.14

centos7.6,增加一块10G硬盘

2、介绍

glusterfs是一个开源分布式文件系统,具有强大的横向扩展能力,可支持数pb存储容量和数千客户端,通过网络互联成一个并行的网络文件系统,具有可扩展性、高性能、高可用等特点

常用资源:

​ pool 存储资源池

​ peer 节点

​ volume 卷 必须处于start才可用

​ brick存储单元(硬盘),可增,可减

gluster

glusterfs添加节点是默认本机是localhost,只需要添加其他机器即可,每个节点都是主

glusterfs默认监听49152端口

二、安装部署glusterfs

1、安装glusterfs

#关闭防火墙
[root@glusterfs-node13 ~]# systemctl stop firewalld
[root@glusterfs-node13 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@glusterfs-node13 ~]# setenforce 0
#安装服务
[root@glusterfs-node12 ~]# yum install centos-release-gluster -y
[root@glusterfs-node12 ~]# yum install glusterfs-server -y
#启动服务
[root@glusterfs-node12 ~]# systemctl start glusterd.service
[root@glusterfs-node12 ~]# systemctl enable glusterd.service
[root@glusterfs-node12 ~]# mkdir -p /glusterfs-data
#配置hosts解析
[root@glusterfs-node12 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.217.12        glusterfs-node12.com glusterfs-node12
192.168.217.13        glusterfs-node13.com glusterfs-node13
192.168.217.14        glusterfs-node14.com glusterfs-node14
#拷贝host解析文件至另外两台
[root@glusterfs-node12 ~]# scp /etc/hosts root@192.168.217.13:/etc/
[root@glusterfs-node12 ~]# scp /etc/hosts root@192.168.217.14:/etc/

2、格式化硬盘并挂载

所有节点配置一致,格式化挂载

#格式化硬盘
[root@glusterfs-node12 ~]# mkfs.xfs /dev/sdb
#把磁盘信息写入开机自动挂载的配置文件中去
[root@glusterfs-node12 ~]# blkid /dev/sdb 
[root@glusterfs-node12 ~]# echo 'UUID=9f92625b-91ad-4f02-a425-522a5b909dd8 /glusterfs-data  xfs defaults 0 0'>> /etc/fstab
[root@glusterfs-node12 ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Thu Jun 23 11:10:17 2022
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=64c1b628-c1d0-4a5c-8dbd-de183fb66d18 /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
UUID=9f92625b-91ad-4f02-a425-522a5b909dd8 /glusterfs-data  xfs defaults 0 0
#挂载硬盘
[root@glusterfs-node12 ~]# mount -a
#查看挂载信息
[root@glusterfs-node12 ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 894M     0  894M    0% /dev
tmpfs                    910M     0  910M    0% /dev/shm
tmpfs                    910M   20M  891M    3% /run
tmpfs                    910M     0  910M    0% /sys/fs/cgroup
/dev/mapper/centos-root   37G  4.6G   33G   13% /
/dev/sda1               1014M  185M  830M   19% /boot
tmpfs                    182M   48K  182M    1% /run/user/1000
tmpfs                    182M     0  182M    0% /run/user/0
/dev/sdb                  10G   33M   10G    1% /glusterfs-data

3、添加存储资源池

资源池就相当于集群,往里面添加节点,默认有一个localhost

查看gluster节点信息
[root@glusterfs-node12 ~]# gluster pool list
UUID					Hostname 	State
d432b1ef-da0e-47b8-9f79-b0d3af15f910	localhost	Connected
#添加第二个节点,注意网络畅通,两边防火墙关闭
[root@glusterfs-node12 ~]# gluster peer probe glusterfs-node13.com
peer probe: success
#添加第二个节点,注意网络畅通,两边防火墙关闭
[root@glusterfs-node12 ~]# gluster peer probe glusterfs-node14.com
peer probe: success
#验证节点信息
[root@glusterfs-node12 ~]# gluster pool list
UUID					Hostname            	State
d33c4aca-1d63-4a9e-8bad-619ea5fbbc24	glusterfs-node13.com	Connected 
d728ff97-d37b-4e82-b054-d0635885a129	glusterfs-node14.com	Connected 
d432b1ef-da0e-47b8-9f79-b0d3af15f910	localhost           	Connected

4、glusertfs卷管理

企业中用的最多的就是分布式复制卷

分布式复制卷可以设置复制的数量,如replica设置的是2,那么就表示上传的文件会复制2份,比如上传10个文件实际上是上传了20个文件,起到一定的备份作用,这20个文件会随机分布在各个节点

5、创建一个分布式复制卷

#创建一个分布式卷,副本数最好是节点数的倍数
[root@glusterfs-node12 ~]# gluster volume create web_volume replica 3 glusterfs-node12.com:/glusterfs-data/brick glusterfs-node13.com:/glusterfs-data/brick glusterfs-node14.com:/glusterfs-data/brick  force
volume create: web_volume: success: please start the volume to access data
#查看创建的卷状态
[root@glusterfs-node12 ~]# gluster volume status
Volume web_volume is not started
#启动卷
[root@glusterfs-node12 ~]# gluster volume start web_volume
volume start: web_volume: success
[root@glusterfs-node12 ~]# gluster volume status
Status of volume: web_volume
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick glusterfs-node12.com:/glusterfs-data/
brick                                       49152     0          Y       9137 
Brick glusterfs-node13.com:/glusterfs-data/
brick                                       49152     0          Y       5290 
Brick glusterfs-node14.com:/glusterfs-data/
brick                                       49152     0          Y       56424
Self-heal Daemon on localhost               N/A       N/A        Y       9154 
Self-heal Daemon on glusterfs-node13.com    N/A       N/A        Y       5307 
Self-heal Daemon on glusterfs-node14.com    N/A       N/A        Y       56441
 
Task Status of Volume web_volume
------------------------------------------------------------------------------
There are no active volume tasks
#查看所有创建的卷
[root@glusterfs-node12 ~]# gluster volume list
web_volume

6、查看卷信息

#查看卷详细信息
[root@glusterfs-node12 ~]# gluster volume info web_volume
 
Volume Name: web_volume
Type: Replicate
Volume ID: 6b7a231c-72be-4747-b9bc-a86c67b6b91e
Status: Started          //表示可用
Snapshot Count: 0
Number of Bricks: 1 x 3 = 3
Transport-type: tcp
Bricks:
Brick1: glusterfs-node12.com:/glusterfs-data/brick
Brick2: glusterfs-node13.com:/glusterfs-data/brick
Brick3: glusterfs-node14.com:/glusterfs-data/brick
Options Reconfigured:
cluster.granular-entry-heal: on
storage.fips-mode-rchecksum: on
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off
#创建挂载点
[root@glusterfs-node12 ~]# mkdir /data_gfs
#将共享存储挂载到本机目录
[root@glusterfs-node12 ~]# mount -t glusterfs 192.168.217.12,192.168.217.13,192.168.217.14:/web_volume /data_gfs
#验证挂载
[root@glusterfs-node12 ~]# df -h
文件系统                    容量  已用  可用 已用% 挂载点
devtmpfs                    894M     0  894M    0% /dev
tmpfs                       910M     0  910M    0% /dev/shm
tmpfs                       910M   11M  900M    2% /run
tmpfs                       910M     0  910M    0% /sys/fs/cgroup
/dev/mapper/centos-root      37G  4.6G   33G   13% /
/dev/sdb                     10G   33M   10G    1% /glusterfs-data
/dev/sda1                  1014M  185M  830M   19% /boot
tmpfs                       182M   16K  182M    1% /run/user/42
tmpfs                       182M     0  182M    0% /run/user/0
192.168.217.12:/web_volume   10G  135M  9.9G    2% /data_gfs
#将挂载信息写入开机自动挂载的配置文件中
[root@glusterfs-node12 ~]# echo "192.168.217.12,192.168.217.13,192.168.217.14:/web_volume    /data_gfs  glusterfs defaults        0 0">>/etc/fstab

7、验证

#进入共享存储挂载点写入一个测试文件
[root@glusterfs-node12 ~]# cd /data_gfs/
[root@glusterfs-node12 data_gfs]# echo  "text" >text.txt
#到每个节点上的实际存储目录可以看到,都存储了
[root@glusterfs-node12 data_gfs]# ll /glusterfs-data/brick/

8、共享存储挂载到第二个节点

[root@glusterfs-node13 ~]# mkdir /data_gfs
[root@glusterfs-node13 ~]# echo "192.168.217.12,192.168.217.13,192.168.217.14:/web_volume    /data_gfs  glusterfs defaults        0 0">>/etc/fstab
[root@glusterfs-node13 ~]# mount -a
[root@glusterfs-node13 ~]# df -h
文件系统                    容量  已用  可用 已用% 挂载点
devtmpfs                    470M     0  470M    0% /dev
tmpfs                       487M     0  487M    0% /dev/shm
tmpfs                       487M   16M  471M    4% /run
tmpfs                       487M     0  487M    0% /sys/fs/cgroup
/dev/mapper/centos-root      17G  4.0G   14G   24% /
/dev/sda1                  1014M  172M  843M   17% /boot
tmpfs                        98M   48K   98M    1% /run/user/1000
tmpfs                        98M     0   98M    0% /run/user/0
/dev/sdb                     10G   33M   10G    1% /glusterfs-data
192.168.217.12:/web_volume   10G  135M  9.9G    2% /data_gfs
[root@glusterfs-node13 ~]# ll /data_gfs/
总用量 1
-rw-r--r--. 1 root root 5 7月  25 05:51 text.txt

三、gluster的运维操作

1、常规操作

#查看节点数
gluster pool list
#查看卷的状态
gluster volume status
#查看web_volume卷的详细信息
gluster volume info web_volume
#启动web_volume卷
gluster volume start web_volume
#停止web_volume卷
gluster volume stop web_volume
#删除web_volume卷
gluster volume delete web_volume

2、GlusterFS存储卷设置owner和group

修改gid, uid和server.allow-insecure.
[root@glusterfs-node13 data]# id vdsm
uid=36(vdsm) gid=36(kvm) groups=36(kvm),179(sanlock),107(qemu)
 
[root@150 data01]# gluster
gluster> volume set gfs1 server.allow-insecure on
gluster> volume set gfs1 storage.owner-uid 36
volume set: success
gluster> volume set gfs1 storage.owner-gid 36

3、GlusterFS修复命令

#查看是否有数据不一致
gluster volume heal volumeName info                
#触发修复
gluster volume heal volumeName        
#在卷的所有文件上触发自我修复:
gluster volume heal volumeName full
#查看需要修复的文件列表:
gluster volume heal volumeName info
#查看自我修复的文件列表:
gluster volume heal volumeName info healed
#查看特定卷的自我修复失败的文件列表:
gluster volume heal volumeName info failed
#查看指定卷中处于脑裂状态的文件列表:
gluster volume heal volumeName info split-brain

 

© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容