前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Centos7下GlusterFS分布式存储集群环境部署记录

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

作者头像
洗尽了浮华
发布2018-04-18 17:33:29
1.8K0
发布2018-04-18 17:33:29
举报
文章被收录于专栏:散尽浮华

之前已经简单地对GlusterFS分布式文件系统做了介绍,下面就该环境部署做一记录:

0)环境准备

代码语言:javascript
复制
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两台机器上都要操作)

代码语言:javascript
复制
[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两台机器上都要操作)

代码语言:javascript
复制
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上操作。其实在任意一个节点上操作都可以)

代码语言:javascript
复制
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机器上操作)

代码语言:javascript
复制
到目前为止,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相关命令

代码语言:javascript
复制
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)总结几点

代码语言:javascript
复制
如上操作后,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/"就可以看到挂的第一个分区的内容了。
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-04-08 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
对象存储
对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档