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

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

165次阅读
没有评论

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