Linux常用服务部署实战三(万字长文):分布式存储-GlusterFS

今天给大家介绍一本小册,Linux常用服务器部署实战。

Linux常用服务器部署是作为一名运维工程师必须掌握的高级技能,这本小册讲解了学习常用服务器服务部署。

我们来看一下这本小册的目录:

本小册介绍了一些Linux常服务的搭建和部署,是运维工程师必备技能。

本文内容转载自 【码小课】,码小课是一个在线小册学习,在线PDF书籍学习平台,感兴趣的同学可以搜索码小课。

本篇文章为大家分享第一小节内容:

分布式存储-GlusterFS

我们知道NAS是远程通过网络共享目录, SAN是远程通过网络共享块设备。那么分布式存储你可以看作拥有多台存储服务器连接起来的存储输出端。把这多台存储服务器的存储合起来做成一个整体再通过网络进行远程共享,共享的方式有目录(文件存储),块设备(块存储),对象网关或者说一个程序接口(对象存储)。

常见的分布式存储开源软件有:GlusterFS,Ceph,HDFS,MooseFS,FastDFS等。

分布式存储一般都有以下几个优点:

  1. 扩容方便,轻松达到PB级别或以上
  2. 提升读写性能或数据高可用
  3. 避免单个节点故障导致整个架构问题
  4. 价格相对便宜,大量的廉价设备就可以组成,比光纤SAN这种便宜很多

二、GlusterFS介绍

glusterfs是一个免费,开源的分布式文件系统(它属于文件存储类型)。主要由 Z RESEARCH 公司负责开发。GlusterFS 具有强大的横向扩展能力,通过扩展能够支持数PB存储容量和处理数千客户端。GlusterFS 可以将物理分布的存储资源聚集在一起,使用单一全局命名空间来管理数据,可为各种不同的数据负载提供优异的性能。

GlusterFS 主要由存储服务器(Brick Server)、客户端以及 NFS/Samba 存储网关组成。在GlusterFS 架构中没有元数据服务器组件,这是其最大的设计这点,对于提升整个系统的性能、可靠性和稳定性都有着决定性的意义。

GlusterFS 支持 TCP/IP 和 高速网络互联。客户端可通过原生 GlusterFS 协议访问数据,其他没有运行 GlusterFS 客户端的终端可通过 NFS/CIFS 标准协议通过存储网关访问数据。存储服务器主要提供基本的数据存储功能,客户端弥补了没有元数据服务器的问题,承担了更多的功能,包括数据卷管理、I/O 调度、文件定位、数据缓存等功能,利用 FUSE(File system in User Space)模块将 GlusterFS 挂载到本地文件系统之上,来访问系统数据。

三、raid级别回顾

raid级别有很多种,下面主要介绍常用的几种:

raid0 读写性能佳,坏了其中一块,数据挂掉,可靠性低(stripe条带化),磁盘利用率100%

raid1 镜像备份(mirror),同一份数据完整的保存在多个磁盘上,写的性能不佳,可靠性高,读的性能还行,磁盘利用率50%


raid10 先做raid 1 再做raid 0

raid5 由多块磁盘做raid 5,磁盘利用率为n-1/n, 其中一块放校验数据,允许坏一块盘,数据可以利用校验值来恢复

raid6 在raid5的基础上再加一块校验盘,进一步提高数据可靠性

 
  1. 注意:生产环境中最常用的为raid5和raid10

GlusterFS名词解释

  • Brick: 最基本的存储单元,表示为trusted storage pool中输出的目录,供客户端挂载用,一般表示方式为“主机名:目录名”
  • Volume: 一个卷。在逻辑上由N个bricks组成.
  • FUSE: Unix-like OS上的可动态加载的模块,允许用户不用修改内核即可创建自己的文件系统。

四、GlusterFS卷类型

基本卷

distribute volume分布式卷 默认:

说明:根据hash算法,将文件随机存储在一个的brick上,文件不能拆分。此时volume的容量是所有brick的和;方便扩展空间,但无冗余保护;由于使用本地文件系统进行存储(brick server 的本地文件系统),存取效率不高;受限于本地文件系统对单文件容量的限制,支持超大型文件系统有问题。

stripe volume 条带卷:

说明:每个文件被分片数据块,然后以round robin的方式将每个chunk存储到1个brick,相当于raid0;比如,对于一个文件,奇数行存储在第一个brick上,偶数行存储在第二个brick。单一超大容量文件可被分片,不受brick server本地文件系统的限制;分布式读写性能较高,但分片随机读写可能会导致硬盘iops较高;无冗余,1个server节点故障会导致所有数据丢失。

replica volume 复制卷(类似Raid 1):

说明:每个文件同步复制镜像到多个brick,相当于文件级raid1,一个是存储一个是备份;读性能提升,写性能下降;提升数据可靠性,但磁盘利用率低;如果两台存储服务器不同,就会出现木桶效应

复合卷

distribute replica volume 分布式复制卷:

说明:是分布式卷与复制卷的组合,兼具两者的功能,若干brick组成1个复制卷,另外若干brick组成其他复制卷;单个文件在复制卷内数据保持副本,不同文件在不同复制卷之间进行哈希分布

distribute stripe volume分布式条带卷:

说明:分布式卷与条带卷的组合,兼具两者的功能,若干brick组成1个条带卷,另外若干brick组成其他条带卷;单个文件在条带卷内数据以条带的形式存储,不同文件在不同条带卷之间进行哈希分布;

striped replicated volume条带镜像卷:

说明:条带与复制卷的组合,兼具两者的功能,若干brick组成1个复制卷,另外若干brick组成其他复制卷;单个文件以条带的形式存储在2个或多个复制集(replicated sets ),复制集内文件分片以副本的形式保存;

distribute stripe replica volume 混合卷: 三种基本卷的复合卷,分布式卷,条带与复制卷的组合,兼具三者的功能

dispersed volume: 分散式(冗余式),例如,数据保存在10个brick中,每个brick有1T,10个brick中有3个是作为冗余brick,作为数据校验,不做存储。此时volume只有7T,volume中允许有3个brick损坏

五、glusterfs集群

目前为止stripe(条带)类型已经用的越来越少,我们以一个案例说明distribute(分布式),replica(复制),distribute replica(分布式复制),dispersed(冗余)四种常用的类型如何使用

学习案例

案例需求: 部署一个glusterfs存储集群

集群部署: 案例步骤

  1. 部署集群
  2. 创建卷并启动
  3. 客户端连接挂载
实验拓扑图

计算机名称IP地址角色
manage01192.168.98.200client
node1192.168.98.201storage_node
node2192.168.98.202storage_node
node3192.168.98.203storage_node
node4192.168.98.204storage_node
node5192.168.98.205storage_node
实验环境
  • CentOS8系统
  • 关闭防火墙
  • 关闭selinux
  • 网络连通
  • 时间同步
实验步骤

时间同步

 
  1. [root@manage01 ~]# vim /etc/chrony.conf
  2. server 192.168.98.200 iburst
  3. driftfile /var/lib/chrony/drift
  4. makestep 1.0 3
  5. rtcsync
  6. allow 192.168.98.0/24
  7. local stratum 10
  8. leapsectz right/UTC
  9. logdir /var/log/chrony
  10. bindaddress 192.168.98.200
  11. [root@manage01 ~]# systemctl restart chrony
  12. server 192.168.98.200 iburst
  13. [root@node1 ~]# systemctl restart chronyd.service

gluster集群部署

1、安装软件[ 安装软件、启动服务]

2、部署集群

存储端设置

a、所有存储机器,设置Yum源,安装gluster

 
  1. #官方源地址https://download.gluster.org/pub/gluster/glusterfs/LATEST/CentOS/glusterfs-rhel8.repo
  2. [root@node2 ~]#vim /etc/yum.repos.d/glusterfs.repo
  3. # Place this file in your /etc/yum.repos.d/ directory
  4. [glusterfs-rhel8]
  5. name=GlusterFS is a clustered file-system capable of scaling to several petabytes.
  6. baseurl=https://download.gluster.org/pub/gluster/glusterfs/7/LATEST/RHEL/el-$releasever/$basearch/
  7. enabled=1
  8. skip_if_unavailable=1
  9. gpgcheck=1
  10. gpgkey=https://download.gluster.org/pub/gluster/glusterfs/7/rsa.pub
  11. [glusterfs-noarch-rhel8]
  12. name=GlusterFS is a clustered file-system capable of scaling to several petabytes.
  13. baseurl=https://download.gluster.org/pub/gluster/glusterfs/7/LATEST/RHEL/el-$releasever/noarch
  14. enabled=1
  15. skip_if_unavailable=1
  16. gpgcheck=1
  17. gpgkey=https://download.gluster.org/pub/gluster/glusterfs/7/rsa.pub
  18. [glusterfs-source-rhel8]
  19. name=GlusterFS is a clustered file-system capable of scaling to several petabytes. - Source
  20. baseurl=https://download.gluster.org/pub/gluster/glusterfs/7/LATEST/RHEL/el-$releasever/SRPMS
  21. enabled=0
  22. skip_if_unavailable=1
  23. gpgcheck=1
  24. gpgkey=https://download.gluster.org/pub/gluster/glusterfs/7/rsa.pub
  25. [root@node1 yum.repos.d]# vim /etc/yum.repos.d/CentOS-PowerTools.repo
  26. [PowerTools]
  27. name=CentOS-$releasever - PowerTools
  28. mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=PowerTools&infra=$infra
  29. #baseurl=http://mirror.centos.org/$contentdir/$releasever/PowerTools/$basearch/os/
  30. gpgcheck=1
  31. enabled=1
  32. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

b、安装glusterfs软件包,并启动服务

 
  1. [root@node2 ~]# dnf install glusterfs-server
  2. [root@node2 ~]# systemctl enable glusterd
  3. [root@node2 ~]# systemctl start glusterd

glusterfs集群组成

brick端:manager/node

client端:挂载存储业务机器

 
  1. [root@node2 ~]# gluster peer help
  2. #将node节点加入集群
  3. [root@node2 ~]# gluster peer probe node1
  4. peer probe: success.
  5. #从集群中删除node
  6. [root@node2 ~]# gluster peer detach node4
  7. All clients mounted through the peer which is getting detached need to be remounted using one of the other active peers in the trusted storage pool to ensure client gets notification on any changes done on the gluster configuration and if the same has been done do you want to proceed? (y/n) y
  8. peer detach: success
  9. #查看集群信息
  10. [root@node2 ~]# gluster peer status
  11. [root@node2 ~]# gluster pool list
  12. [root@node2 ~]# gluster peer status
  13. Number of Peers: 2
  14. Hostname: node1
  15. Uuid: 809111f4-8a0e-40fb-af53-d2d8a56cd41e
  16. State: Peer in Cluster (Connected)
  17. Hostname: 192.168.98.203
  18. Uuid: 7396a19d-a2a7-4b27-86d3-12c89ac4df39
  19. State: Peer in Cluster (Connected)
  20. 或者
  21. [root@node2 ~]# gluster pool list
  22. UUID Hostname State
  23. 809111f4-8a0e-40fb-af53-d2d8a56cd41e node1 Connected
  24. 7396a19d-a2a7-4b27-86d3-12c89ac4df39 192.168.98.203 Connected
  25. 0ace00a1-0612-4395-ac9b-f1516207ead1 localhost Connected

c、所有storage服务器建立连接,成为一个集群

 
  1. 4个storage服务器建立连接不用两两连接,只需要找其中1个,连接另外3个各一次就OK了
  2. ##集群管理
  3. #将node节点加入集群
  4. [root@node2 ~]# gluster peer probe node1
  5. peer probe: success.
  6. [root@node2 ~]# gluster peer probe node4
  7. peer probe: success.
  8. [root@node2 ~]# gluster peer probe node3 --这里使用ip,主机名,主机名别名都可以
  9. 然后在所有存储上都可以使用下面命令来验证检查
  10. [root@node2 ~]# gluster peer status
  11. Number of Peers: 3
  12. Hostname: node1
  13. Uuid: 809111f4-8a0e-40fb-af53-d2d8a56cd41e
  14. State: Peer in Cluster (Connected)
  15. Hostname: 192.168.98.203
  16. Uuid: 7396a19d-a2a7-4b27-86d3-12c89ac4df39
  17. State: Peer in Cluster (Connected)
  18. Hostname: node4
  19. Uuid: b2ea8b19-658c-40ec-84b4-6568c627eefd
  20. State: Peer in Cluster (Connected)

注意:

如果这一步建立连接有问题(一般问题会出现在网络连接,防火墙,selinux,主机名绑定等);

如果想重做这一步,可以使用gluster peer detach xxxxx [force] 来断开连接,重新做

存储收集

必须是一个文件夹

1)一块磁盘[分区 格式化 挂载到节点上的指定目录]

  1. 一个磁盘文件[分区 格式化 挂载到节点上的指定目录]

3)分区上的一个文件夹

d、所有storage服务器准备存储目录

 
  1. [root@node2 ~]# mkdir /opt/data{1..5}

e、创建存储卷,创建存储卷(在任意一个storage服务器上做)

 
  1. glusterfs支持多种卷
  2. Distribut卷 分布卷
  3. Replica卷 复制卷
  4. Disperse卷 冗余卷
  5. 注意:从6.0版本开始之前和Striped卷相关的卷类型就全部废弃了。
  6. https://docs.gluster.org/en/latest/Administrator%20Guide/Setting%20Up%20Volumes/

Replica卷

文件同步复制到多个brick上,文件级RAID 1,具有容错能力,写性能下降,读性能提升。缺点是磁盘利用率低。

 
  1. #创建一个replica卷(raid1) 数据会在每个brick上存储一份
  2. #复制卷类似raid1 所有一般会选择两台来完成,文件保存两份,如果希望保存多个机器,可以用多台机器,这里用两台。
  3. [root@node2 ~]# gluster volume create gv1-replica replica 2 node{1..2}:/opt/data force
  4. volume create: gv1-replica: success: please start the volume to access data
  5. replica 代表创建的是镜像卷 2 代表2个台机器 由于使用的是根分区 所以要加上强制 force
  6. #查看卷创建情况
  7. [root@node2 ~]# gluster volume info gv1-replica
  8. Volume Name: gv1-replica
  9. Type: Replicate
  10. Volume ID: f93a83dc-9ed6-43fe-99e4-5346d5d1d702
  11. Status: Created
  12. Snapshot Count: 0
  13. Number of Bricks: 1 x 2 = 2
  14. Transport-type: tcp
  15. Bricks:
  16. Brick1: node1:/opt/data
  17. Brick2: node2:/opt/data
  18. Options Reconfigured:
  19. transport.address-family: inet
  20. nfs.disable: on
  21. performance.client-io-threads: off

Distribut卷—数据随机存储在某个brick

文件通过hash算法分布到所有brick server上,这种卷是glusterfs的基础和最大特点。优点是容量大,缺点是没冗余。

 
  1. #如果不指定创建卷的类型,则默认是Distribute卷,可以是多个机器。
  2. #分布卷数据随机存储在某个brick,一般是应用在不需要冗余的环境。
  3. [root@node2 ~]# gluster volume create gv2-distribute node{1..3}:/opt/data2 force
  4. volume create: gv2-distribute: success: please start the volume to access data
  5. #查看卷
  6. [root@node2 ~]# gluster volume info gv2-distribute
  7. Volume Name: gv2-distribute
  8. Type: Distribute
  9. Volume ID: 079a2f5c-23ac-43f8-9f54-f6a454a53706
  10. Status: Created
  11. Snapshot Count: 0
  12. Number of Bricks: 3
  13. Transport-type: tcp
  14. Bricks:
  15. Brick1: node1:/opt/data2
  16. Brick2: node2:/opt/data2
  17. Brick3: node3:/opt/data2
  18. Options Reconfigured:
  19. transport.address-family: inet
  20. nfs.disable: on

Disperse 卷( 冗余卷)

disperse卷是v3.6版本后发布的一种卷模式,类似于raid5/6,分布式分散卷 disperse必须大于2,大于4才可以有一块redundancy盘 大于5块可有redundancy盘两块

文件分片存储在各个硬盘上,但有部分硬盘用于冗余用途,数量可以指定。比如一共10块硬盘,2块盘用于冗余,那么就可以承受同时损坏两块硬盘,总容量是8块盘。

优点是在冗余和性能之间取得平衡

 
  1. #创建卷(raid5 raid6)
  2. #建议不少于4个机器
  3. [root@node2 ~]# gluster volume create gv3-disperse disperse 4 node{1..4}:/opt/data3 force
  4. There isn't an optimal redundancy value for this configuration. Do you want to create the volume with redundancy 1 ? (y/n) y 指定一个磁盘为校验磁盘
  5. volume create: gv3-disperse: success: please start the volume to access data
  6. #查看卷信息
  7. [root@node2 ~]# gluster volume info gv3-disperse
  8. Volume Name: gv3-disperse
  9. Type: Disperse
  10. Volume ID: 754523b3-7e8e-4133-bb77-60c2247711d9
  11. Status: Created
  12. Snapshot Count: 0
  13. Number of Bricks: 1 x (3 + 1) = 4
  14. Transport-type: tcp
  15. Bricks:
  16. Brick1: node1:/opt/data3
  17. Brick2: node2:/opt/data3
  18. Brick3: node3:/opt/data3
  19. Brick4: node4:/opt/data3
  20. Options Reconfigured:
  21. transport.address-family: inet
  22. nfs.disable: on

distribute replica 分布复制卷

 
  1. #创建分布复制卷,机器为偶数
  2. #每两个分布卷组成一个复制卷,创建两个复制卷
  3. [root@node2 ~]# gluster volume create gv2-distribute-replica replica 2 node{1..4}:/opt/data4 force
  4. volume create: gv2-distribute-replica: success: please start the volume to access data
  5. #查看磁盘信息
  6. [root@node2 ~]# gluster volume info gv2-distribute-replica
  7. Volume Name: gv2-distribute-replica
  8. Type: Distributed-Replicate
  9. Volume ID: 90d70fef-54a9-4555-98ad-0d1a342f6763
  10. Status: Created
  11. Snapshot Count: 0
  12. Number of Bricks: 2 x 2 = 4
  13. Transport-type: tcp
  14. Bricks:
  15. Brick1: node1:/opt/data4
  16. Brick2: node2:/opt/data4
  17. Brick3: node3:/opt/data4
  18. Brick4: node4:/opt/data4
  19. Options Reconfigured:
  20. transport.address-family: inet
  21. nfs.disable: on
  22. performance.client-io-threads: off

f、启动卷

gluster volume star 卷名称

 
  1. #查看卷
  2. [root@node2 ~]# gluster volume list
  3. gv1-replica
  4. gv2-distribute
  5. gv2-distribute-replica
  6. gv3-disperse
  7. #启动卷
  8. [root@node2 ~]# gluster volume start gv1-replica
  9. volume start: gv1-replica: success
  10. [root@node2 ~]# gluster volume start gv2-distribute
  11. volume start: gv2-distribute: success
  12. [root@node2 ~]# gluster volume start gv2-distribute-replica
  13. volume start: gv2-distribute-replica: success
  14. [root@node2 ~]# gluster volume start gv3-disperse
  15. volume start: gv3-disperse: success

存储卷管理-卷的增删改查

 
  1. #
  2. [root@node2 ~]# gluster volume help 打印帮助信息
  3. #卷的创建 gluster volume create
  4. [root@node2 ~]# gluster volume create <NEW-VOLNAME> [stripe <COUNT>] [replica <COUNT> [arbiter <COUNT>]] [disperse [<COUNT>]] [disperse-data <COUNT>] [redundancy <COUNT>] [transport <tcp|rdma|tcp,rdma>] <NEW-BRICK>... [force]
  5. <NEW-VOLNAME> 卷名
  6. [stripe <COUNT>] [replica <COUNT> [arbiter <COUNT>]] [disperse [<COUNT>]] [disperse-data <COUNT>] 卷类型
  7. stripe 条带
  8. replica 复制
  9. 什么都不加 默认分布
  10. disperse 冗余
  11. redundancy 校验磁盘
  12. transport 传输方式 tcp rdma内存
  13. force 强制,如果存储在根分区
  14. #卷删除
  15. [root@node2 ~]# gluster volume delete <VOLNAME>
  16. #卷查看
  17. [root@node2 ~]# gluster volume list #卷列表
  18. [root@node2 ~]# gluster volume info [<VOLNAME> | all] #卷详细信息
  19. [root@node2 ~]# gluster volume status [<VOLNAME> | all] #卷启动或关闭的状态信息
  20. #扩容卷
  21. [root@node2 ~]# gluster volume add-brick <VOLNAME> [<stripe|replica> <COUNT> [arbiter <COUNT>]] <NEW-BRICK> ... [force]
  22. #缩减卷
  23. [root@node2 ~]# gluster volume remove-brick
  24. #卷启动
  25. [root@node2 ~]# gluster volume start <VOLNAME>
  26. #卷关闭
  27. [root@node2 ~]# gluster volume stop <VOLNAME>
  28. #卷替换
  29. [root@node2 ~]# gluster volume replace-brick

客户端设置挂载分布式卷

客户端安装软件

 
  1. [root@manage01 ~]# dnf install glusterfs glusterfs-fuse -y
  2. #客户端在安装软件的时候注意版本,如果服务端与客户端使用的版本不一致,会导致挂载失败

客户端挂载,验证上述卷数据存储方式

 
  1. #建立挂载点并挂载
  2. [root@manage01 ~]# mkdir /opt/gluster_disk{1..4}
  3. [root@manage01 ~]# mount -t glusterfs node1:/gv1-replica /opt/gluster_disk1/
  4. [root@manage01 ~]# mount -t glusterfs node1:/gv2-distribute /opt/gluster_disk2
  5. [root@manage01 ~]# mount -t glusterfs node1:/gv2-distribute-replica /opt/gluster_disk3
  6. [root@manage01 ~]# mount -t glusterfs node1:/gv3-disperse /opt/gluster_disk4
  7. #查看挂载
  8. [root@manage01 ~]# mount |grep "gluster"
  9. node1:/gv1-replica on /opt/gluster_disk1 type fuse.glusterfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other,max_read=131072)
  10. node1:/gv2-distribute on /opt/gluster_disk2 type fuse.glusterfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other,max_read=131072)
  11. node1:/gv2-distribute-replica on /opt/gluster_disk3 type fuse.glusterfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other,max_read=131072)
  12. node1:/gv3-disperse on /opt/gluster_disk4 type fuse.glusterfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other,max_read=131072)
  13. #分别存储数据
  14. [root@manage01 ~]# dd if=/dev/zero of=/opt/gluster_disk1/file bs=1M count=100
  15. 记录了100+0 的读入
  16. 记录了100+0 的写出
  17. 104857600字节(105 MB)已复制,1.281 秒,81.9 MB/秒
  18. [root@manage01 ~]# dd if=/dev/zero of=/opt/gluster_disk2/file bs=1M count=100
  19. 记录了100+0 的读入
  20. 记录了100+0 的写出
  21. 104857600字节(105 MB)已复制,0.974837 秒,108 MB/秒
  22. [root@manage01 ~]# dd if=/dev/zero of=/opt/gluster_disk3/file bs=1M count=100
  23. 记录了100+0 的读入
  24. 记录了100+0 的写出
  25. 104857600字节(105 MB)已复制,1.53898 秒,68.1 MB/秒
  26. [root@manage01 ~]# dd if=/dev/zero of=/opt/gluster_disk4/file bs=1M count=100
  27. 记录了100+0 的读入
  28. 记录了100+0 的写出
  29. 104857600字节(105 MB)已复制,1.80071 秒,58.2 MB/秒
  30. #验证
  31. #复制卷 数据每个节点都存储了一份
  32. [root@node1 ~]# ls /opt/data -lh
  33. 总用量 100M
  34. -rw-r--r-- 2 root root 100M 7月 7 08:51 file
  35. [root@node2 ~]# ls /opt/data -lh
  36. 总用量 100M
  37. -rw-r--r-- 2 root root 100M 7月 7 08:51 file
  38. #分布卷 数据存在了node1
  39. [root@node1 ~]# ls /opt/data2 -lh
  40. 总用量 100M
  41. -rw-r--r-- 2 root root 100M 7月 7 08:51 file
  42. [root@node2 ~]# ls /opt/data2 -lh
  43. 总用量 0
  44. [root@node3 ~]# ls /opt/data2 -lh
  45. 总用量 0
  46. #冗余卷 发现数据平均分布在每个存储节点
  47. [root@node1 ~]# ls /opt/data3 -lh
  48. 总用量 34M
  49. -rw-r--r-- 2 root root 34M 7月 7 08:52 file
  50. [root@node2 ~]# ls /opt/data3 -lh
  51. 总用量 34M
  52. -rw-r--r-- 2 root root 34M 7月 7 08:52 file
  53. [root@node3 ~]# ls /opt/data3 -lh
  54. 总用量 34M
  55. -rw-r--r-- 2 root root 34M 7月 7 08:52 file
  56. [root@node4 ~]# ls /opt/data3/ -lh
  57. 总用量 34M
  58. -rw-r--r-- 2 root root 34M 7月 7 08:52 file
  59. #分布复制卷 发现数据存在了node3 node4 这对复制卷上,
  60. [root@node1 ~]# ls /opt/data4 -lh
  61. 总用量 0
  62. [root@node2 ~]# ls /opt/data4 -lh
  63. 总用量 0
  64. [root@node3 ~]# ls /opt/data4 -lh
  65. 总用量 100M
  66. -rw-r--r-- 2 root root 100M 7月 7 08:51 file
  67. [root@node4 ~]# ls /opt/data4/ -lh
  68. 总用量 100M
  69. -rw-r--r-- 2 root root 100M 7月 7 08:51 file

删除卷

  1. 删除卷中数据
  2. 客户端卸载
  3. 在任意一个节点执行删除
  4. 验证删除

实践练习

删除卷中数据

 
  1. [root@manage01 ~]# rm -rf /opt/gluster_disk1/*

客户端卸载

 
  1. [root@manage01 ~]# umount /opt/gluster_disk1/

卷删除

 
  1. #3.在任意一个节点删除
  2. [root@node1 ~]# gluster volume stop gv1-replica
  3. [root@node1 ~]# gluster volume delete gv1-replica
  4. Deleting volume will erase all information about the volume. Do you want to continue? (y/n) y
  5. volume delete: gv1-replica: failed: Volume vg0 does not exist

验证删除

 
  1. [root@node1 ~]# gluster volume info gv1-replica
  2. Volume gv1-replica does not exist

在线裁减与在线扩容

在线裁减要看是哪一种模式的卷,比如stripe模式就不允许在线裁减。下面我以distributed卷来做裁减与扩容

在线扩容

 
  1. #查看卷
  2. [root@node2 ~]# gluster volume info gv2-distribute
  3. Volume Name: gv2-distribute
  4. Type: Distribute
  5. Volume ID: 079a2f5c-23ac-43f8-9f54-f6a454a53706
  6. Status: Started
  7. Snapshot Count: 0
  8. Number of Bricks: 3
  9. Transport-type: tcp
  10. Bricks:
  11. Brick1: node1:/opt/data2
  12. Brick2: node2:/opt/data2
  13. Brick3: node3:/opt/data2
  14. Options Reconfigured:
  15. transport.address-family: inet
  16. nfs.disable: on
  17. #扩容
  18. [root@node2 ~]# gluster volume add-brick gv2-distribute node4:/opt/data2 force
  19. volume add-brick: success
  20. #验证
  21. [root@node2 ~]# gluster volume info gv2-distribute
  22. Volume Name: gv2-distribute
  23. Type: Distribute
  24. Volume ID: 079a2f5c-23ac-43f8-9f54-f6a454a53706
  25. Status: Started
  26. Snapshot Count: 0
  27. Number of Bricks: 4
  28. Transport-type: tcp
  29. Bricks:
  30. Brick1: node1:/opt/data2
  31. Brick2: node2:/opt/data2
  32. Brick3: node3:/opt/data2
  33. Brick4: node4:/opt/data2
  34. Options Reconfigured:
  35. transport.address-family: inet
  36. nfs.disable: on

在线裁减(注意要remove没有数据的brick)

 
  1. #裁剪卷.
  2. [root@node2 ~]# gluster volume remove-brick gv2-distribute node4:/opt/data2 force
  3. Remove-brick force will not migrate files from the removed bricks, so they will no longer be available on the volume.
  4. Do you want to continue? (y/n) y
  5. volume remove-brick commit force: success
  6. #查看验证
  7. [root@node2 ~]# gluster volume info gv2-distribute
  8. Volume Name: gv2-distribute
  9. Type: Distribute
  10. Volume ID: 079a2f5c-23ac-43f8-9f54-f6a454a53706
  11. Status: Started
  12. Snapshot Count: 0
  13. Number of Bricks: 3
  14. Transport-type: tcp
  15. Bricks:
  16. Brick1: node1:/opt/data2
  17. Brick2: node2:/opt/data2
  18. Brick3: node3:/opt/data2
  19. Options Reconfigured:
  20. performance.client-io-threads: on
  21. transport.address-family: inet
  22. nfs.disable: on
  23. 关于裁剪卷,线上几乎不会裁剪,基本上都是扩容,而且裁剪只能裁剪没有数据的,否则可能数据丢失。所以,有些卷是不支持裁剪的。

在线替换卷

 
  1. [root@node2 ~]# gluster volume list
  2. gv1-replica
  3. gv2-distribute
  4. gv2-distribute-replica
  5. gv3-disperse
  6. [root@node2 ~]# gluster volume info gv1-replica
  7. #查看源信息
  8. Volume Name: gv1-replica
  9. Type: Replicate
  10. Volume ID: f93a83dc-9ed6-43fe-99e4-5346d5d1d702
  11. Status: Started
  12. Snapshot Count: 0
  13. Number of Bricks: 1 x 2 = 2
  14. Transport-type: tcp
  15. Bricks:
  16. Brick1: node1:/opt/data
  17. Brick2: node2:/opt/data
  18. Options Reconfigured:
  19. transport.address-family: inet
  20. nfs.disable: on
  21. performance.client-io-threads: off
  22. #卷替换
  23. [root@node2 ~]# gluster volume replace-brick gv1-replica node2:/opt/data node4:/opt/data commit force
  24. volume replace-brick: success: replace-brick commit force operation successful
  25. #验证替换
  26. [root@node2 ~]# gluster volume info gv1-replica
  27. Volume Name: gv1-replica
  28. Type: Replicate
  29. Volume ID: f93a83dc-9ed6-43fe-99e4-5346d5d1d702
  30. Status: Started
  31. Snapshot Count: 0
  32. Number of Bricks: 1 x 2 = 2
  33. Transport-type: tcp
  34. Bricks:
  35. Brick1: node1:/opt/data
  36. Brick2: node4:/opt/data
  37. Options Reconfigured:
  38. transport.address-family: inet
  39. nfs.disable: on
  40. performance.client-io-threads: off

拓展:4个存储想扩容为5个存储怎么做?

 
  1. 答案: 第5个存储服务器安装服务器软件包,启动服务,然后gluster peer probe storage5加入集群
  2. #加入集群
  3. [root@node2 ~]# gluster peer probe node5
  4. peer probe: success.
  5. [root@node2 ~]# gluster peer status
  6. Number of Peers: 4
  7. Hostname: node1
  8. Uuid: 809111f4-8a0e-40fb-af53-d2d8a56cd41e
  9. State: Peer in Cluster (Connected)
  10. Hostname: 192.168.98.203
  11. Uuid: 7396a19d-a2a7-4b27-86d3-12c89ac4df39
  12. State: Peer in Cluster (Connected)
  13. Hostname: node4
  14. Uuid: b2ea8b19-658c-40ec-84b4-6568c627eefd
  15. State: Peer in Cluster (Connected)
  16. Hostname: node5
  17. Uuid: 82f424cb-1c7d-4057-8f40-f236015f8940
  18. State: Peer in Cluster (Connected)
  • 20
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MySQL多数据源是指在一个应用程序中同时使用多个不同的MySQL数据库来存储和管理数据的技术。它可以帮助开发人员更灵活地处理各种数据库操作,提高程序的性能和可扩展性。下面是一个完整的MySQL多数据源教程。 一、设置数据库连接信息 1. 在应用程序的配置件中,创建多个数据库连接的配置项。例如,可以为每个数据源创建一个配置项,分别命名为db1、db2等。 2. 在配置项中,设置每个数据源的连接信息,包括数据库地址、用户名、密码等。 二、创建数据源管理器 1. 创建一个数据源管理器类,用于管理多个数据源。该类需要实现数据源的动态切换和获取。 2. 使用Java的线程安全的数据结构,如ConcurrentHashMap来存储数据源信息。将配置件中的数据库连接信息加载到数据结构中。 3. 实现方法来切换不同的数据源,通过传入数据源的名称来切换到对应的数据库。 、实现数据源切换 1. 在应用程序中,根据业务需求选择需要使用的数据源。可以通过调用数据源管理器的方法来切换数据源。 2. 在DAO层的代码中,根据当前使用的数据源名称,选择对应的数据源进行数据库操作。 四、使用多数据源进行数据库操作 1. 在DAO层的代码中,区分不同的数据源,并将数据库操作的代码包装在对应的数据源中。 2. 在业务层的代码中,调用DAO层的方法来进行数据库操作。不同的数据源会自动切换。 五、处理事务 1. 如果需要在一个事务中操作多个数据源,可以使用分布式事务的方式来处理。 2. 可以使用开源的分布式事务框架,如Atomikos、Bitronix等来实现多数据源的事务管理。 六、监控和维护 1. 使用监控工具来监控多个数据源的使用情况,包括连接数、查询次数等。 2. 定期对数据库进行维护,包括索引优化、数据清理等工作,以保证数据库的性能和稳定性。 通过以上步骤,我们可以实现MySQL多数据源的配置和使用。使用多数据源可以更好地管理和处理不同的数据库操作,在提高程序性能和可扩展性的同时,也提供了更灵活的数据操作方式。同时,需要注意合理选择和配置数据源,以及监控和维护数据库,以保证系统的运行效率和数据的安全性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值