Centos7下GlusterFS分布式存储集群环境部署记录

时间:2022-02-14 20:15:29

0)环境准备

GlusterFS至少需要两台服务器搭建,服务器配置最好相同,每个服务器两块磁盘,一块是用于安装系统,一块是用于GlusterFS。

192.168.10.239 GlusterFS-master(主节点) Centos7.4
192.168.10.212 GlusterFS-slave (从节点) Centos7.4
192.168.10.213 Client (客户端)
----------------------------------------------------------------------------------------

由于GlusterFS需要使用网络,因此还必须事先根据环境设置防火墙规则,关闭SELinux。
这里我将上面三台服务器的防火墙和Selinux全部关闭
[root@GlusterFS-master ~]# setenforce 0
[root@GlusterFS-master ~]# getenforce
[root@GlusterFS-master ~]# cat /etc/sysconfig/selinux |grep "SELINUX=disabled"
SELINUX=disabled

[root@GlusterFS-master ~]# systemctl stop firewalld
[root@GlusterFS-master ~]# systemctl disable firewalld
[root@GlusterFS-master ~]# firewall-cmd --state
not running

------------------------------------------------------------------------------------------
由于GlusterFS并没有服务器与元数据等概念,因此所有服务器的设置都相同。首先要做主机名的设置(如果操作时都用ip地址,不使用主机名,那么就不需要做hosts绑定):
[root@GlusterFS-master ~]# hostnamectl --static set-hostname GlusterFS-master
[root@GlusterFS-master ~]# cat /etc/hostname
GlusterFS-master
[root@GlusterFS-master ~]# vim /etc/hosts
.....
192.168.10.239 GlusterFS-master
192.168.10.212 GlusterFS-slave

[root@GlusterFS-slave ~]# hostnamectl --static set-hostname GlusterFS-slave
[root@GlusterFS-slave ~]# cat /etc/hostname
GlusterFS-slave
[root@GlusterFS-slave ~]# vim /etc/hosts
......
192.168.10.239 GlusterFS-master
192.168.10.212 GlusterFS-slave

------------------------------------------------------------------------------------------
时钟同步
这个问题是集群内部的时间非常重要,如果服务器间的时间有误差,可能会给集群间的通信带来麻烦,
进而导致集群失效。这里采用网络同步时钟的方法,确保两台服务器的时间一致:
[root@GlusterFS-master ~]# yum install -y ntpdate
[root@GlusterFS-master ~]# ntpdate ntp1.aliyun.com
[root@GlusterFS-master ~]# date

[root@GlusterFS-slave ~]# yum install -y ntpdate
[root@GlusterFS-slave ~]# ntpdate ntp1.aliyun.com
[root@GlusterFS-slave ~]# date
1)安装依赖(在GlusterFS-master和GlusterFS-slave两台机器上都要操作)

[root@GlusterFS-master ~]# yum install -y flex bison openssl openssl-devel acl libacl libacl-devel sqlite-devel \
libxml2-devel python-devel make cmake gcc gcc-c++ autoconf automake libtool unzip zip

2)查看集群状态:安装userspace-rcu-master和userspace-rcu-master(在GlusterFS-master和GlusterFS-slave两台机器上都要操作)

1)下载glusterfs-3.6.9.tar.gz和userspace-rcu-master.zip
百度云盘下载地址:https://pan.baidu.com/s/1DyKxt0TnO3aNx59mVfJCZA
提取密码:ywq8

将这两个安装包放到/usr/local/src目录下
[root@GlusterFS-master ~]# cd /usr/local/src/
[root@GlusterFS-master src]# ll
total 6444
-rw-r--r--. 1 root root 6106554 Feb 29 2016 glusterfs-3.6.9.tar.gz
-rw-r--r--. 1 root root 490091 Apr 8 09:58 userspace-rcu-master.zip

2)安装userspace-rcu-master
[root@GlusterFS-master src]# unzip /usr/local/src/userspace-rcu-master.zip -d /usr/local/
[root@GlusterFS-master src]# cd /usr/local/userspace-rcu-master/
[root@GlusterFS-master userspace-rcu-master]# ./bootstrap
[root@GlusterFS-master userspace-rcu-master]# ./configure
[root@GlusterFS-master userspace-rcu-master]# make && make install
[root@GlusterFS-master userspace-rcu-master]# ldconfig

3)安装userspace-rcu-master
[root@GlusterFS-master userspace-rcu-master]# tar -zxvf /usr/local/src/glusterfs-3.6.9.tar.gz -C /usr/local/
[root@GlusterFS-master userspace-rcu-master]# cd /usr/local/glusterfs-3.6.9/
[root@GlusterFS-master glusterfs-3.6.9]# ./configure --prefix=/usr/local/glusterfs
[root@GlusterFS-master glusterfs-3.6.9]# make && make install

添加环境变量
[root@GlusterFS-master glusterfs-3.6.9]# vim /etc/profile //在文件最底部添加如下内容
......
export GLUSTERFS_HOME=/usr/local/glusterfs
export PATH=$PATH:$GLUSTERFS_HOME/sbin

[root@GlusterFS-master glusterfs-3.6.9]# source /etc/profile

4)启动glusterfs
[root@GlusterFS-master ~]# /usr/local/glusterfs/sbin/glusterd
[root@GlusterFS-master ~]# ps -ef|grep glusterd
root 852 1 0 10:14 ? 00:00:00 /usr/local/glusterfs/sbin/glusterd
root 984 26217 0 10:14 pts/1 00:00:00 grep --color=auto glusterd
[root@GlusterFS-master ~]# lsof -i:24007
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
glusterd 852 root 9u IPv4 123605 0t0 TCP *:24007 (LISTEN)

3)建立GlusterFS分布式存储集群(这里选择在GlusterFS-master上操作。其实在任意一个节点上操作都可以)

1)执行以下命令,将192.168.10.212(可以使用ip地址,也可以使用节点的主机名)节点加入到集群,有多少个节点需要加入集群,就执行多少个下面的命令:
[root@GlusterFS-master ~]# gluster peer probe 192.168.10.212
peer probe: success.

2)查看集群状态:
[root@GlusterFS-master ~]# gluster peer status
Number of Peers: 1
Hostname: 192.168.10.212
Uuid: f8e69297-4690-488e-b765-c1c404810d6a
State: Peer in Cluster (Connected)

3)查看 volume 信息(由于还没有创建volume所以显示的是暂无信息):
[root@GlusterFS-master ~]# gluster volume info
No volumes present

4)创建数据存储目录(在GlusterFS-master和GlusterFS-slave节点上都要操作)
[root@GlusterFS-master ~]# mkdir -p /opt/gluster/data

5)创建复制卷 models,指定刚刚创建的目录(replica 2表明存储2个备份,即有多少个节点就存储多少个备份;后面指定服务器的存储目录)
[root@GlusterFS-master ~]# gluster volume create models replica 2 192.168.10.239:/opt/gluster/data 192.168.10.212:/opt/gluster/data force

6)再次查看 volume 信息
[root@GlusterFS-master ~]# gluster volume info

Volume Name: models
Type: Replicate
Volume ID: f1945b0b-67d6-4202-9198-639244ab0a6a
Status: Created
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: 192.168.10.239:/opt/gluster/data
Brick2: 192.168.10.212:/opt/gluster/data

7)启动 models
[root@GlusterFS-master ~]# gluster volume start models

8)gluster 性能调优
a)首先开启指定volume的配额
[root@GlusterFS-master ~]# gluster volume quota models enable

b)限制 models 总目录最大使用 5GB 空间(5GB并非绝对,需要根据实际硬盘大小配置)
[root@GlusterFS-master ~]# gluster volume quota models limit-usage / 5GB

c)设置 cache 大小(128MB并非绝对,需要根据实际硬盘大小配置)
[root@GlusterFS-master ~]# gluster volume set models performance.cache-size 128MB

d)开启异步,后台操作
[root@GlusterFS-master ~]# gluster volume set models performance.flush-behind on

e)设置 io 线程 32
[root@GlusterFS-master ~]# gluster volume set models performance.io-thread-count 32

f)设置 回写 (写数据时间,先写入缓存内,再写入硬盘)
[root@GlusterFS-master ~]# gluster volume set models performance.write-behind on

g)查看调优之后的volume信息
[root@GlusterFS-master ~]# gluster volume info

Volume Name: models
Type: Replicate
Volume ID: f1945b0b-67d6-4202-9198-639244ab0a6a
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: 192.168.10.239:/opt/gluster/data
Brick2: 192.168.10.212:/opt/gluster/data
Options Reconfigured:
performance.write-behind: on
performance.io-thread-count: 32
performance.flush-behind: on
performance.cache-size: 128MB
features.quota: on
4)部署客户端并挂载GlusterFS文件系统的bricks(存储单元)(在Client机器上操作)

到目前为止,GlusterFS分布式存储集群的大部分工作已经做完了,接下来就是挂载一个目录,然后通过对这个挂载目录操作,
实现数据同步至文件系统。然后写文件测试下:

1)安装gluster-client
[root@Client ~]# yum install -y glusterfs glusterfs-fuse

2)建立挂载点目录
[root@Client ~]# mkdir -p /opt/gfsmount

3)挂载GlusterFS
[root@Client ~]# mount -t glusterfs 192.168.10.239:models /opt/gfsmount/

4)检查挂载情况
[root@Client ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 38G 4.3G 33G 12% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 8.6M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/vda1 1014M 143M 872M 15% /boot
/dev/mapper/centos-home 19G 33M 19G 1% /home
tmpfs 380M 0 380M 0% /run/user/0
overlay 38G 4.3G 33G 12% /var/lib/docker/overlay2/9904ac8cbcba967de3262dc0d5e230c64ad3c1c53b588048e263767d36df8c1a/merged
shm 64M 0 64M 0% /var/lib/docker/containers/222ec7f21b2495591613e0d1061e4405cd57f99ffaf41dbba1a98c350cd70f60/mounts/shm
192.168.10.239:models 38G 3.9G 34G 11% /opt/gfsmount

5)测试。分别创建30M、300M的两个大文件,发现速度很快。
[root@Client ~]# time dd if=/dev/zero of=/opt/gfsmount/kevin bs=30M count=1
1+0 records in
1+0 records out
31457280 bytes (31 MB) copied, 0.140109 s, 225 MB/s

real 0m0.152s
user 0m0.001s
sys 0m0.036s

[root@Client ~]# time dd if=/dev/zero of=/opt/gfsmount/grace bs=300M count=1
1+0 records in
1+0 records out
314572800 bytes (315 MB) copied, 1.07577 s, 292 MB/s

real 0m1.106s
user 0m0.001s
sys 0m0.351s

[root@Client ~]# cd /opt/gfsmount/
[root@Client gfsmount]# du -sh *
300M grace
30M kevin
[root@Client gfsmount]# mkdir test
[root@Client gfsmount]# ll
total 337924
-rw-r--r--. 1 root root 314572800 Apr 7 22:41 grace
-rw-r--r--. 1 root root 31457280 Apr 7 22:41 kevin
drwxr-xr-x. 2 root root 4096 Apr 7 22:43 test

6)查看集群存储情况(在GlusterFS-master和GlusterFS-slave节点上操作)
[root@GlusterFS-master ~]# cd /opt/gluster/data/
[root@GlusterFS-master data]# ll
total 337920
-rw-r--r--. 2 root root 314572800 Apr 8 10:41 grace
-rw-r--r--. 2 root root 31457280 Apr 8 10:41 kevin
drwxr-xr-x. 2 root root 6 Apr 8 10:43 test

[root@GlusterFS-slave ~]# cd /opt/gluster/data/
[root@GlusterFS-slave data]# ll
total 337920
-rw-r--r--. 2 root root 314572800 Apr 7 22:41 grace
-rw-r--r--. 2 root root 31457280 Apr 7 22:41 kevin
drwxr-xr-x. 2 root root 6 Apr 7 22:43 test
备注:查看得知gluster服务器的每个节点上都有备份,符合上面步骤,即:创建复制卷 models,指定刚刚创建的目录(replica 2表明存储2个备份)

5)GlusterFS相关命令

1)查看GlusterFS中所有的volume
[root@GlusterFS-master ~]# gluster volume list
models

2)启动磁盘。比如启动名字为 models 的磁盘
[root@GlusterFS-master ~]# gluster volume start models

3)停止磁盘。比如停止名字为 models 的磁盘
[root@GlusterFS-master ~]# gluster volume stop models

4)删除磁盘。比如删除名字为 models 的磁盘
[root@GlusterFS-master ~]# gluster volume delete models

5)验证GlusterFS集群。可以使用下面三个命令
[root@GlusterFS-master ~]# gluster peer status
Number of Peers: 1

Hostname: 192.168.10.212
Uuid: f8e69297-4690-488e-b765-c1c404810d6a
State: Peer in Cluster (Connected)

[root@GlusterFS-master ~]# gluster pool list
UUID Hostname State
f8e69297-4690-488e-b765-c1c404810d6a 192.168.10.212 Connected
5dfd40e2-096b-40b5-bee3-003b57a39007 localhost Connected

[root@GlusterFS-master ~]# gluster volume status
Status of volume: models
Gluster process Port Online Pid
------------------------------------------------------------------------------
Brick 192.168.10.239:/opt/gluster/data 49152 Y 1055
Brick 192.168.10.212:/opt/gluster/data 49152 Y 32586
NFS Server on localhost N/A N N/A
Self-heal Daemon on localhost N/A Y 1074
Quota Daemon on localhost N/A Y 1108
NFS Server on 192.168.10.212 N/A N N/A
Self-heal Daemon on 192.168.10.212 N/A Y 32605
Quota Daemon on 192.168.10.212 N/A Y 32614

Task Status of Volume models
------------------------------------------------------------------------------
There are no active volume tasks

6)将节点移出GlusterFS集群,可以批量移除。如下将glusterfs3和glusterfs4两个节点移除集群。
[root@GlusterFS-master ~]# gluster peer detach glusterfs3 glusterfs4

7)卷扩容(由于副本数设置为2,至少要添加2(4、6、8..)台机器)
比如添加glusterfs3、glusterfs4两个节点,并将这两个节点的卷(即)合并,合并后的卷名称为glusterfs_data。
[root@GlusterFS-master ~]# gluster peer probe glusterfs3
[root@GlusterFS-master ~]# gluster peer probe glusterfs4
[root@GlusterFS-master ~]# gluster volume add-brick glusterfs_data glusterfs3:/opt/gluster/data glusterfs4:/opt/gluster/data force

8)重新均衡卷(glusterfs_data为卷名)
[root@GlusterFS-master ~]# gluster volume rebalance glusterfs_data start
[root@GlusterFS-master ~]# gluster volume rebalance glusterfs_data status
[root@GlusterFS-master ~]# gluster volume rebalance glusterfs_data stop

均衡卷的前提是至少有两个brick存储单元(即至少3个节点集群)。
上面的例子中,models卷中只有一个brick存储单元,故不能进行均衡卷操作:
[root@GlusterFS-master ~]# gluster volume list
models
[root@GlusterFS-master ~]# gluster volume rebalance models start
volume rebalance: models: failed: Volume models is not a distribute volume or contains only 1 brick.
Not performing rebalance
[root@GlusterFS-master ~]#

9)收缩卷(收缩卷前gluster需要先移动数据到其他位置)(gv0为卷名)
[root@GlusterFS-master ~]# gluster volume remove-brick gv0 glusterfs3:/data/brick1/gv0 glusterfs4:/data/brick1/gv0 start //开始迁移
[root@GlusterFS-master ~]# gluster volume remove-brick gv0 glusterfs3:/data/brick1/gv0 glusterfs4:/data/brick1/gv0 status //查看迁移状态
[root@GlusterFS-master ~]# gluster volume remove-brick gv0 glusterfs3:/data/brick1/gv0 glusterfs4:/data/brick1/gv0 commit //迁移完成后提交

10)迁移卷

#将glusterfs3的数据迁移到glusterfs5,先将glusterfs5加入集群
[root@GlusterFS-master ~]# gluster peer probe glusterfs5

#开始迁移
[root@GlusterFS-master ~]# gluster volume replace-brick gv0 glusterfs3:/data/brick1/gv0 glusterfs5:/data/brick1/gv0 start

#查看迁移状态
[root@GlusterFS-master ~]# gluster volume replace-brick gv0 glusterfs3:/data/brick1/gv0 glusterfs5:/data/brick1/gv0 status

#数据迁移完毕后提交
[root@GlusterFS-master ~]# gluster volume replace-brick gv0 glusterfs3:/data/brick1/gv0 glusterfs5:/data/brick1/gv0 commit

#如果机器agent31.kisops.org出现故障已经不能运行,执行强制提交
[root@GlusterFS-master ~]# gluster volume replace-brick gv0 glusterfs3:/data/brick1/gv0 glusterfs5:/data/brick1/gv0 commit -force

#同步整个卷
[root@GlusterFS-master ~]# gluster volume heal gfs full

11)授权访问。如下授权192.168网段的客户机能访问此glusterfs存储卷。
[root@GlusterFS-master ~]# gluster volume set gfs auth.allow 192.168.*
6)总结几点

如上操作后,GlusterFS的分布式存储集群环境已经搭建完成。这里总结几点如下:
1)如果Glusterfs节点机器重启,那么重启后:
a)glusterFS服务需要启动
b)磁盘models(即存储卷)需要启动
c)目录/opt/gfsmount/需要重新挂载
d)挂载完目录/opt/gfsmount/需要重新进入

2)注意:
两个分区挂到同一个分区,第一个挂的那个不是被覆盖,而是被暂时隐藏。比如:
先挂载的"mount /dev/sda1 /opt/gfsmount/",接着又挂载的"mount /dev/sda2 /opt/gfsmount/",
那么/dev/sda1内的就暂时被隐藏,只要"umount /dev/sda2",把第二个分区卸载了,
在"cd /opt/gfsmount/"就可以看到挂的第一个分区的内容了。

Centos7下GlusterFS分布式存储集群环境部署记录的更多相关文章

  1. kafka 基础知识梳理及集群环境部署记录

    一.kafka基础介绍 Kafka是最初由Linkedin公司开发,是一个分布式.支持分区的(partition).多副本的(replica),基于zookeeper协调的分布式消息系统,它的最大的特 ...

  2. Centos7下ELK+Redis日志分析平台的集群环境部署记录

    之前的文档介绍了ELK架构的基础知识,日志集中分析系统的实施方案:- ELK+Redis- ELK+Filebeat - ELK+Filebeat+Redis- ELK+Filebeat+Kafka+ ...

  3. ProxySQL Cluster 高可用集群环境部署记录

    ProxySQL在早期版本若需要做高可用,需要搭建两个实例,进行冗余.但两个ProxySQL实例之间的数据并不能共通,在主实例上配置后,仍需要在备用节点上进行配置,对管理来说非常不方便.但是Proxy ...

  4. Mongodb副本集+分片集群环境部署记录

    前面详细介绍了mongodb的副本集和分片的原理,这里就不赘述了.下面记录Mongodb副本集+分片集群环境部署过程: MongoDB Sharding Cluster,需要三种角色: Shard S ...

  5. Centos7.5基于MySQL5.7的 InnoDB Cluster 多节点高可用集群环境部署记录

    一.   MySQL InnoDB Cluster 介绍MySQL的高可用架构无论是社区还是官方,一直在技术上进行探索,这么多年提出了多种解决方案,比如MMM, MHA, NDB Cluster, G ...

  6. GlusterFS分布式存储集群-1. 部署

    参考文档: Quick Start Guide:http://gluster.readthedocs.io/en/latest/Quick-Start-Guide/Quickstart/ Instal ...

  7. GlusterFS分布式存储集群部署记录-相关补充

    接着上一篇Centos7下GlusterFS分布式存储集群环境部署记录文档,继续做一些补充记录,希望能加深对GlusterFS存储操作的理解和熟悉度. ======================== ...

  8. MySQL+MGR 单主模式和多主模式的集群环境 - 部署手册 (Centos7.5)

    MySQL Group Replication(简称MGR)是MySQL官方于2016年12月推出的一个全新的高可用与高扩展的解决方案.MGR是MySQL官方在5.7.17版本引进的一个数据库高可用与 ...

  9. centos6.5环境下zookeeper-3.4.6集群环境部署及单机部署详解

    centos6.5环境下Zookeeper-3.4.6集群环境部署 [系统]Centos 6.5 集群部署 [软件]准备好jdk环境,此次我们的环境是open_jdk1.8.0_101 zookeep ...

随机推荐

  1. C#自定义控件属性显示在属性面板中操作

    private Color controleColor; [Browsable(true)] [Description("控件颜色"), Category("自定义&qu ...

  2. Cordova开发环境的搭建

    Cordova开发环境的搭建 原文地址:http://imziv.com/blog/article/read.htm?id=66 Cordova为目前做混合式开发中比较受欢迎的一个解决方案了,并且拥有 ...

  3. java 格式化日期(DateFormat)

    import java.text.DateFormat; import java.util.Date; /** * 格式化时间类 DateFormat.FULL = 0 * DateFormat.DE ...

  4. iOS-UI控件精讲之UILabel

    UILabel(标签)应该是iOS中最基本的一个控件了,也是使用频率最高的,经常用来展示一段不可编辑的文本. UILabel继承于UIView,下面是一些常用的属性,包含继承于UIView的属性. 1 ...

  5. PHP代码批量加密

    <?php error_reporting(E_ALL); ini_set('display_errors','1'); //批量加密码当前目录 $dirnow = getcwd(); $dir ...

  6. &period;net C&num; 利用Session防重复点击防重复提交

    <body>    <form id="form1" runat="server">    <div>        &lt ...

  7. 性能测试十四:Xshell链接linux虚拟机

    一.先装一个linux虚拟机 VBox+centos1.先下载Linux镜像文件的ovf或者OVA文件2.打开vbox,点击菜单栏“管理”-“导入虚拟电脑3.选择解压路径中的ovf或者OVA文件,点击 ...

  8. 通过wui登陆 sap 页面对数据进行高级 搜索

    1: 登陆QGL系统. 在 T-CODE搜索框输入wui 会跳到搜索的web页面,进行搜索. 或者浏览器输入: https://ldciqgl.wdf.sap.corp:44300/sap(bD1lb ...

  9. SparkSession

    在2.0版本之前,使用Spark必须先创建SparkConf和SparkContext catalog:目录 Spark2.0中引入了SparkSession的概念,SparkConf.SparkCo ...

  10. ZOJ3113&lowbar;John

    这个题目是一个典型的Anti_Sg.我也不知道为什么这么叫,呵呵,反正大家都这么叫,而且我也是听别人说,看别人的日志自己才知道的. 题目的意思是给你不同颜色的石子,每次可以去一种颜色的石子若干个(至少 ...