手机版
你好,游客 登录 注册
背景:
阅读新闻

CentOS 7.5下部署GlusterFS分布式存储集群环境

[日期:2019-05-17] 来源:Linux社区  作者:Linux [字体: ]
最小化安装的CentOS 7.5
内存大于1GB
关闭selinux,防火墙端口放行(port:24007,111)(测试建议关闭firewalld)

一、环境部署

所有软件包离线安装,原因是yum安装的不能很好的控制版,用到的软件包统一放到/gfs目录,包已整理好

------------------------------------------分割线------------------------------------------

Matlab R2017b的Linux版下载地址可从以下信息的得到下载:

点击这个http://www.linuxidc.com/Linux/2013-12/93755.htm 链接关注 Linux公社官方微信,关注后回复数字158712。即可得到网友的分享密码。

如果取消关注Linux公社公众号,即使再次关注,也将无法提供本服务!

链接: https://pan.baidu.com/s/1eSSX46yaGBUoEmCqjeAeqw 密码:获得见上面的方法,地址失效请在下面留言。

------------------------------------------分割线------------------------------------------

  • 测试用的磁盘分配以及服务器架构图

  • basic代表服务器本来使用的磁盘,基础上再添加上图相应的磁盘,由于是测试用,为方便直观理解,磁盘大小就是后面的数字:如sdb3,该磁盘大小为3GB。
  • 卷的分布方案

卷名称卷类型空间大小/GB 存储块
dis-volume 分布式卷 12 node1(/sde6),node2(/sde6)
stripe-volume 条带卷 10 node1(/sdd5),node2(/sdd5)
rep-volume 复制卷 5 node3(/sdd5),node4(/sdd5)
dis-stripe 分布式条带卷 12 node1(/sdb3),node2(/sdb3),node3(/sdb3),node4(/sdb3)
dis-rep 分布式复制卷 8 node1(/sdc4),node2(/sdc4),node3(sdc4),node4(sdc4)
  • 全部主机修改主机名
  • 全部主机配置hosts文件,一样的
  • 全部node主机创建挂载文件夹,依实际挂载点创建
  • 全部主机创建/gfs文件夹,将所需软件包放入

    mkdir /{gfs,sdb3,sdc4,sdd5} cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.64.11 node1
192.168.64.12 node2
192.168.64.13 node3
192.168.64.14 node4
192.168.64.15 client
  • 完毕之后进行ping测试
  • 通过传输方式将软件包上传到/gfs文件(里面有一个repo文件夹也要上传)
  • 以上一切完成之后,全部node主机执行以下脚本
vim install.sh
#!/bin/bash
for i in $(fdisk -l | grep -wo "/dev/sd[b-z]" | sort)
do
dd if=/dev/zero of=$i bs=1024 count=1024
fdisk $i << EOF
n
p



w
EOF
#空行很重要不要删除
partprobe $i 
#//不重启系统识别分区
mkfs.ext4 ${i}1 
#//格式化分区
done

mkdir /b3 /c4 /d5 /e6 
fdisk -l | grep -w "/dev/sd[b-z]" | sed -r 's/.*(\/d.{8}).*/\1/g' | sed -r 's/(.*)(.{3}):(.*)/mount \1\21 \/\2\3/' | bash
fdisk -l | grep -w "/dev/sd[b-z]" | sed -r 's/.*(\/d.{8}).*/\1/g' | sed -r 's/(.*)(.{3}):(.*)/\1\21 \/\2\3 xfs default 0 0/' >> /etc/fstab
#-w 只显示全字符合的列。
iptables -F
systemctl stop firewalld
setenforce 0

cat << EOF >> /etc/yum.repos.d/gfs.repo 
[gfs]
name=gfs
baseurl=file:///gfs
gpgcheck=0
enabled=1
EOF

yum clean all && yum makecache
yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma
systemctl start glusterd
systemctl enable glusterd
EOF

sh install.sh //执行脚本 netstat -lnpt //查看gluster服务端口是否开启
脚本简单理解

  • 再node1上执行如下命令构建gluster集群
[root@node1 ~]# gluster peer probe node2
peer probe: success. 
[root@node1 ~]# gluster peer probe node3
peer probe: success. 
[root@node1 ~]# gluster peer probe node4
peer probe: success. 

[root@node1 ~]# gluster peer status //在每个节点上执行查看集群状态;正常时为(Connected)

二、创建卷

1.创建分布式卷(扩大磁盘空间,读写速度快,没有容错能力)

[root@node1 ~]# gluster volume create dis-volume node1:/sde6 node2:/sde6 force //dis-volume为卷名称,未指定创建卷类型,默认为分布式卷 volume create: dis-volume: success: please start the volume to access data [root@node1 ~]# gluster volume start dis-volume volume start: dis-volume: success [root@node1 ~]# gluster volume info dis-volume //查看该卷的相关信息

2.创建条带卷(以数据块为单位存储,没有容错性)

[root@node1 ~]# gluster volume create stripe-volume stripe 2 node1:/sdd5 node2:/sdd5 force [root@node1 ~]# gluster volume start stripe-volume volume start: stripe-volume: success //stripe表示卷类型条带卷,后面的数量表示条带数

3.创建复制卷(磁盘空间为总空间一半,具备容错性,读快,写慢)

[root@node1 ~]# gluster volume create rep-volume replica 2 node3:/sdd5 node4:/sdd5 force [root@node1 ~]# gluster volume start rep-volume volume start: rep-volume: success

4.创建分布式条带卷(加大容量,读取快,没有容错性)

[root@node1 ~]# gluster volume create dis-stripe stripe 2 node1:/sdb3 node2:/sdb3 node3:/sdb3 node4:/sdb3 force //指定类型为Distributed-Stripe,数值为2,而且后面跟了4个Brick Server,是2的2倍,所以创建的是分布式条带卷。 volume create: dis-stripe: success: please start the volume to access data [root@node1 ~]# gluster volume start dis-stripe volume start: dis-stripe: success

5.创建分布式复制卷(扩展空间,总空间的一半,且具有容错能力)

[root@node1 ~]# gluster volume create dis-rep replica 2 node1:/sdc4 node2:/sdc4 node3:/sdc4 node4:/sdc4/ force //指定类型为Distributed-Replicate,数值为2,而且后面跟了4个Brick Server,是2的2倍,所以创建的是分布式复制卷。 volume create: dis-rep: success: please start the volume to access data [root@node1 ~]# gluster volume start dis-rep volume start: dis-rep: success

三、部署Gluster客户端

1.安装客户端软件
  • 将软件包放至/gfs文件夹
  • 修改前面提到的hostname以及hosts
  • 运行如下脚本
vim in_cl.sh
#!/bin/bash

cat << EOF >> /etc/yum.repos.d/gfs.repo 
[gfs]
name=gfs
baseurl=file:///gfs
gpgcheck=0
enabled=1
EOF

yum clean all && yum makecache
yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma
systemctl start glusterd
systemctl enable glusterd

sh in_cl.sh netstat -lnpt | grep glu //可以看到服务已经启动
[root@client ~]# mkdir -pv /test/{dis,stripe,rep,dis_stripe,dis_rep} //创建挂载目录 [root@client ~]# mount -t glusterfs node1:dis-volume /test/dis [root@client ~]# mount -t glusterfs node1:stripe-volume /test/stripe/ [root@client ~]# mount -t glusterfs node1:rep-volume /test/rep/ [root@client ~]# mount -t glusterfs node1:dis-stripe /test/dis_stripe/ [root@client ~]# mount -t glusterfs node1:dis-rep /test/dis_rep/ //挂载glusterfs文件系统到本地客户端,所制定的node1节点只是为了获取配置信息,不代表只和他进行数据传输,会根据配置针对集群来进行数据的存放

  • 修改fstab文件实现永久挂载
  • 添加如下文件

    vim /etc/fstab

node1:dis-volume        /test/dis               glusterfs defaults,_netdev 0 0
node1:stripe-volume     /test/stripe            glusterfs defaults,_netdev 0 0
node1:rep-volume        /test/rep               glusterfs defaults,_netdev 0 0
node1:dis-rep           /test/dis_rep   glusterfs defaults,_netdev 0 0
node1:dis-stripe        /test/dis_stripe        glusterfs defaults,_netdev 0 0

四、测试

  • 生成测试文件(该文件虽没有数据,但是可以进行测试用途)

    [root@client ~]# for i in {1..5};do dd if=/dev/zero of=/root/demon$i.log bs=1M count=43;done [root@client ~]# cp demon* /test/dis && cp demon* /test/dis_rep/ && cp demon* /test/dis_stripe/ && cp demon* /test/rep/ && cp demon* /test/stripe/

  • 查看文件分布状态
  • 分布式卷(node1和node2的/sde6目录查看,可以看到文件被分散开存放)
[root@node1 ~]# ll -h /sde6/
总用量 130M
-rw-r--r--. 2 root root 43M 4月   2 21:32 demon1.log
-rw-r--r--. 2 root root 43M 4月   2 21:32 demon3.log
-rw-r--r--. 2 root root 43M 4月   2 21:32 demon4.log
drwx------. 2 root root 16K 4月   3 2019 lost+found
[root@node2 ~]# ll -h /sde6/
总用量 87M
-rw-r--r--. 2 root root 43M 4月   3 05:32 demon2.log
-rw-r--r--. 2 root root 43M 4月   3 05:32 demon5.log
drwx------. 2 root root 16K 4月   3 03:01 lost+found
  • 条带卷(node1和node2的/sdd5目录查看,清晰看到是以数据块为单位存储的)
[root@node1 ~]# ls -lh /sdd5/
总用量 108M
-rw-r--r--. 2 root root 22M 4月   2 21:31 demon1.log
-rw-r--r--. 2 root root 22M 4月   2 21:31 demon2.log
-rw-r--r--. 2 root root 22M 4月   2 21:31 demon3.log
-rw-r--r--. 2 root root 22M 4月   2 21:31 demon4.log
-rw-r--r--. 2 root root 22M 4月   2 21:31 demon5.log
[root@node2 ~]# ls -lh /sdd5/
总用量 108M
-rw-r--r--. 2 root root 22M 4月   3 05:31 demon1.log
-rw-r--r--. 2 root root 22M 4月   3 05:31 demon2.log
-rw-r--r--. 2 root root 22M 4月   3 05:31 demon3.log
-rw-r--r--. 2 root root 22M 4月   3 05:31 demon4.log
-rw-r--r--. 2 root root 22M 4月   3 05:31 demon5.log
  • 复制卷(node3和node4的/sdd5目录,数据有备份)
[root@node3 ~]# ls -lh /sdd5/
总用量 216M
-rw-r--r--. 2 root root 43M 4月   3 05:32 demon1.log
-rw-r--r--. 2 root root 43M 4月   3 05:32 demon2.log
-rw-r--r--. 2 root root 43M 4月   3 05:33 demon3.log
-rw-r--r--. 2 root root 43M 4月   3 05:33 demon4.log
-rw-r--r--. 2 root root 43M 4月   3 05:33 demon5.log
drwx------. 2 root root 16K 4月   3 03:03 lost+found
[root@node4 ~]# ls -lh /sdd5/
总用量 216M
-rw-r--r--. 2 root root 43M 4月   3 05:32 demon1.log
-rw-r--r--. 2 root root 43M 4月   3 05:32 demon2.log
-rw-r--r--. 2 root root 43M 4月   3 05:33 demon3.log
-rw-r--r--. 2 root root 43M 4月   3 05:33 demon4.log
-rw-r--r--. 2 root root 43M 4月   3 05:33 demon5.log
drwx------. 2 root root 16K 4月   3 02:55 lost+found
  • 分布式条带卷(节点1、2、3、4的/sdb3目录,我日期没有调整,海涵)
[root@node1 ~]# ls -lh /sdb3/
总用量 65M
-rw-r--r--. 2 root root 22M 4月   2 21:32 demon1.log
-rw-r--r--. 2 root root 22M 4月   2 21:32 demon3.log
-rw-r--r--. 2 root root 22M 4月   2 21:32 demon4.log
drwx------. 2 root root 16K 4月   2 18:37 lost+found
[root@node2 ~]# ls -lh /sdb3/
总用量 65M
-rw-r--r--. 2 root root 22M 4月   3 05:32 demon1.log
-rw-r--r--. 2 root root 22M 4月   3 05:32 demon3.log
-rw-r--r--. 2 root root 22M 4月   3 05:32 demon4.log
drwx------. 2 root root 16K 4月   3 03:01 lost+found
[root@node3 ~]# ls -lh /sdb3/
总用量 44M
-rw-r--r--. 2 root root 22M 4月   3 05:32 demon2.log
-rw-r--r--. 2 root root 22M 4月   3 05:32 demon5.log
drwx------. 2 root root 16K 4月   3 03:03 lost+found
[root@node4 ~]# ls -lh /sdb3/
总用量 44M
-rw-r--r--. 2 root root 22M 4月   3 05:32 demon2.log
-rw-r--r--. 2 root root 22M 4月   3 05:32 demon5.log
drwx------. 2 root root 16K 4月   3 02:55 lost+found
  • 分布式复制卷(节点1、2、3、4的/sdc4目录,可看到文件没有被分片,但是是分布开来存放的)
[root@node1 ~]# ls -lh /sdc4/
总用量 130M
-rw-r--r--. 2 root root 43M 4月   2 21:32 demon1.log
-rw-r--r--. 2 root root 43M 4月   2 21:32 demon3.log
-rw-r--r--. 2 root root 43M 4月   2 21:32 demon4.log
drwx------. 2 root root 16K 4月   3 2019 lost+found
[root@node2 ~]# ls -lh /sdc4/
总用量 130M
-rw-r--r--. 2 root root 43M 4月   3 05:32 demon1.log
-rw-r--r--. 2 root root 43M 4月   3 05:32 demon3.log
-rw-r--r--. 2 root root 43M 4月   3 05:32 demon4.log
drwx------. 2 root root 16K 4月   3 03:01 lost+found
[root@node3 ~]# ls -lh /sdc4/
总用量 87M
-rw-r--r--. 2 root root 43M 4月   3 05:32 demon2.log
-rw-r--r--. 2 root root 43M 4月   3 05:32 demon5.log
drwx------. 2 root root 16K 4月   3 03:01 lost+found
[root@node4 ~]# ls -lh /sdc4/
总用量 87M
-rw-r--r--. 2 root root 43M 4月   3 05:32 demon2.log
-rw-r--r--. 2 root root 43M 4月   3 05:32 demon5.log
drwx------. 2 root root 16K 4月   3 03:01 lost+found
破坏测试
  • 直接点关闭node2节点。关机操作。
  • 客户端操作
[root@client ~]# ls /test/dis/
demon1.log  demon3.log  demon4.log  lost+found
//可以看到另外两个文件直接找不到了
[root@client ~]# ls /test/stripe/
[root@client ~]# 
//条带卷因为文件都是分散开放,所以都没有了
[root@client ~]# ls /test/dis_stripe/
demon2.log  demon5.log  lost+found
//分布式条带卷,因为是分布式存储node2宕机导致数据不完整不会显示,1,3,4号文件丢失
[root@client ~]# ls /test/dis_rep/
demon1.log  demon2.log  demon3.log  demon4.log  demon5.log  lost+found
//分布式复制卷完全不受任何影响
//总而言之,了解各卷的特点,再细心观察以下文件分布的具体位置,才能尽可能保证数据可靠性

五、维护命令

[root@node3 ~]# gluster volume list
dis-rep
dis-stripe
dis-volume
rep-volume
stripe-volume
//任何一个节点都可以查看集群列表
[root@node1 ~]# gluster volume info 
//查看所有卷的信息
[root@node1 ~]# gluster volume status       
//查看卷的状态
[root@node3 ~]# gluster volume stop dis-stripe
Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
volume stop: dis-stripe: success
//停止卷
[root@node3 ~]# gluster volume start dis-stripe
//启动卷
[root@node3 ~]# gluster volume delete dis-stripe
//删除卷

Linux公社的RSS地址https://www.linuxidc.com/rssFeed.aspx

本文永久更新链接地址https://www.linuxidc.com/Linux/2019-05/158712.htm

linux
相关资讯       GlusterFS 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款