阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

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

465次阅读
没有评论

共计 8888 个字符,预计需要花费 23 分钟才能阅读完成。

最小化安装的 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 密码:获得见上面的方法,地址失效请在下面留言。

—————————————— 分割线 ——————————————

  • 测试用的磁盘分配以及服务器架构图
    CentOS 7.5 下部署 GlusterFS 分布式存储集群环境

  • 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
// 删除卷

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计8888字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中

星哥玩云

星哥玩云
星哥玩云
分享互联网知识
用户数
4
文章数
19351
评论数
4
阅读量
7993141
文章搜索
热门文章
星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛 NAS-6:抖音视频同步工具,视频下载自动下载保存 前言 各位玩 NAS 的朋友好,我是星哥!...
星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛 NAS-3:安装飞牛 NAS 后的很有必要的操作 前言 如果你已经有了飞牛 NAS 系统,之前...
我把用了20年的360安全卫士卸载了

我把用了20年的360安全卫士卸载了

我把用了 20 年的 360 安全卫士卸载了 是的,正如标题你看到的。 原因 偷摸安装自家的软件 莫名其妙安装...
再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见 zabbix!轻量级自建服务器监控神器在 Linux 的完整部署指南 在日常运维中,服务器监控是绕不开的...
飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛 NAS 中安装 Navidrome 音乐文件中文标签乱码问题解决、安装 FntermX 终端 问题背景 ...
阿里云CDN
阿里云CDN-提高用户访问的响应速度和成功率
随机文章
让微信公众号成为 AI 智能体:从内容沉淀到智能问答的一次升级

让微信公众号成为 AI 智能体:从内容沉淀到智能问答的一次升级

让微信公众号成为 AI 智能体:从内容沉淀到智能问答的一次升级 大家好,我是星哥,之前写了一篇文章 自己手撸一...
三大开源投屏神器横评:QtScrcpy、scrcpy、escrcpy 谁才是跨平台控制 Android 的最优解?

三大开源投屏神器横评:QtScrcpy、scrcpy、escrcpy 谁才是跨平台控制 Android 的最优解?

  三大开源投屏神器横评:QtScrcpy、scrcpy、escrcpy 谁才是跨平台控制 Andr...
安装Black群晖DSM7.2系统安装教程(在Vmware虚拟机中、实体机均可)!

安装Black群晖DSM7.2系统安装教程(在Vmware虚拟机中、实体机均可)!

安装 Black 群晖 DSM7.2 系统安装教程(在 Vmware 虚拟机中、实体机均可)! 前言 大家好,...
恶意团伙利用 PHP-FPM 未授权访问漏洞发起大规模攻击

恶意团伙利用 PHP-FPM 未授权访问漏洞发起大规模攻击

恶意团伙利用 PHP-FPM 未授权访问漏洞发起大规模攻击 PHP-FPM(FastCGl Process M...
星哥带你玩飞牛NAS-5:飞牛NAS中的Docker功能介绍

星哥带你玩飞牛NAS-5:飞牛NAS中的Docker功能介绍

星哥带你玩飞牛 NAS-5:飞牛 NAS 中的 Docker 功能介绍 大家好,我是星哥,今天给大家带来如何在...

免费图片视频管理工具让灵感库告别混乱

一言一句话
-「
手气不错
Prometheus:监控系统的部署与指标收集

Prometheus:监控系统的部署与指标收集

Prometheus:监控系统的部署与指标收集 在云原生体系中,Prometheus 已成为最主流的监控与报警...
三大开源投屏神器横评:QtScrcpy、scrcpy、escrcpy 谁才是跨平台控制 Android 的最优解?

三大开源投屏神器横评:QtScrcpy、scrcpy、escrcpy 谁才是跨平台控制 Android 的最优解?

  三大开源投屏神器横评:QtScrcpy、scrcpy、escrcpy 谁才是跨平台控制 Andr...
支付宝、淘宝、闲鱼又双叕崩了,Cloudflare也瘫了连监控都挂,根因藏在哪?

支付宝、淘宝、闲鱼又双叕崩了,Cloudflare也瘫了连监控都挂,根因藏在哪?

支付宝、淘宝、闲鱼又双叕崩了,Cloudflare 也瘫了连监控都挂,根因藏在哪? 最近两天的互联网堪称“故障...
零成本上线!用 Hugging Face免费服务器+Docker 快速部署HertzBeat 监控平台

零成本上线!用 Hugging Face免费服务器+Docker 快速部署HertzBeat 监控平台

零成本上线!用 Hugging Face 免费服务器 +Docker 快速部署 HertzBeat 监控平台 ...
300元就能买到的”小钢炮”?惠普7L四盘位小主机解析

300元就能买到的”小钢炮”?惠普7L四盘位小主机解析

  300 元就能买到的 ” 小钢炮 ”?惠普 7L 四盘位小主机解析 最近...