首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >CentOS 7.5下部署GlusterFS分布式存储集群环境

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

作者头像
星哥玩云
发布2022-07-27 20:23:04
发布2022-07-27 20:23:04
9360
举报
文章被收录于专栏:开源部署开源部署
最小化安装的CentOS 7.5
内存大于1GB
关闭selinux,防火墙端口放行(port:24007,111)(测试建议关闭firewalld)
一、环境部署
所有软件包离线安装,原因是yum安装的不能很好的控制版,用到的软件包统一放到/gfs目录,包已整理好
  • 测试用的磁盘分配以及服务器架构图
  • 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
代码语言:javascript
复制
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主机执行以下脚本
代码语言:javascript
复制
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集群
代码语言:javascript
复制
[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
  • 运行如下脚本
代码语言:javascript
复制
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
代码语言:javascript
复制
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目录查看,可以看到文件被分散开存放)
代码语言:javascript
复制
[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目录查看,清晰看到是以数据块为单位存储的)
代码语言:javascript
复制
[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目录,数据有备份)
代码语言:javascript
复制
[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目录,我日期没有调整,海涵)
代码语言:javascript
复制
[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目录,可看到文件没有被分片,但是是分布开来存放的)
代码语言:javascript
复制
[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节点。关机操作。
  • 客户端操作
代码语言:javascript
复制
[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
//分布式复制卷完全不受任何影响
//总而言之,了解各卷的特点,再细心观察以下文件分布的具体位置,才能尽可能保证数据可靠性
五、维护命令
代码语言:javascript
复制
[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
//删除卷
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 最小化安装的CentOS 7.5
  • 内存大于1GB
  • 关闭selinux,防火墙端口放行(port:24007,111)(测试建议关闭firewalld)
  • 一、环境部署
    • 所有软件包离线安装,原因是yum安装的不能很好的控制版,用到的软件包统一放到/gfs目录,包已整理好
  • 二、创建卷
    • 1.创建分布式卷(扩大磁盘空间,读写速度快,没有容错能力)
    • 2.创建条带卷(以数据块为单位存储,没有容错性)
    • 3.创建复制卷(磁盘空间为总空间一半,具备容错性,读快,写慢)
    • 4.创建分布式条带卷(加大容量,读取快,没有容错性)
    • 5.创建分布式复制卷(扩展空间,总空间的一半,且具有容错能力)
  • 三、部署Gluster客户端
    • 1.安装客户端软件
  • 四、测试
    • 破坏测试
  • 五、维护命令
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档