Skip to content

Commit

Permalink
RAID,LVM,GlusterFS
Browse files Browse the repository at this point in the history
  • Loading branch information
huataihuang committed Aug 3, 2023
1 parent fab4bce commit cfe7629
Show file tree
Hide file tree
Showing 21 changed files with 353 additions and 2 deletions.
Binary file added source/_static/linux/storage/lvm/mdadm-lvm.webp
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@ GlusterFS底层需要采用操作系统提供的文件系统,有以下推荐

- 直接使用 :ref:`xfs`
- 结合 :ref:`linux_lvm` 使用 :ref:`xfs`

- 对多磁盘采用 :ref:`mdadm` 组建 :ref:`linux_software_raid` ,然后在软RAID之上构建 :ref:`linux_lvm`
- 或者采用 ref:`lvmraid` 实现 :ref:`linux_software_raid`

- 采用 :ref:`zfs` 同时兼具卷管理和文件系统功能

待续...
为何需要卷管理
================

现代服务器的存储规模惊人, :ref:`nvme` 释放了服务器端的存储能力,可以高密度部署大量的存储磁盘,这也为 GlusterFS 带来的维护挑战:

- Gluster是基于服务器来实现文件分布的: 对于一个服务器上多块磁盘,虽然可以通过指定 ``brick`` 顺序来构建 :ref:`distributed_replicated_glusterfs_volume` ( :ref:`deploy_centos7_gluster11` 中使用了每个服务器12块磁盘 ),但是如果一个分布式多副本GlusterFS卷在一个服务器上有过个 ``brick`` 会导致难以扩展也难以收缩:

- 文件副本是按照 ``brick`` 的顺序来分布的, :ref:`add_centos7_gluster11_server` 的多块 ``brick`` 会 **堆积** 在 ``Bricks`` 最后,意味着文件hash之后,有可能多个副本落在同一台服务器上带来容灾隐患
- 如果某个服务器宕机,删除服务器也存在相似问题,如果服务器数量减少,执行 ``gluster volume rebalance`` 以及后续文件副本的分布都可能落在同一个物理服务器

- 从GlusterFS的精简的hash设计来看,最理想的状态是: 每个GlusterFS Volume在每个服务器上只有一个 ``brick`` ,以确保文件副本hash能够分布到不同的服务器上获得高可用

- 随着存储技术发展,单台服务器的 :ref:`nvme` 数量突飞猛进,如果不使用 :ref:`linux_lvm` 将大量的磁盘整合成存储池,就会面对需要人工来规划和管理 GlusterFS volume 和磁盘的对应关系
- 如果GlusterFS volume卷数量有限,甚至不及服务器上的磁盘数量,那么直接使用 :ref:`xfs` 就会导致要么不能充分使用存储磁盘,要么就是限制了GlusterFS的伸缩性(见上文分析)

实践
=======

- :ref:`deploy_centos7_gluster11_lvm_mdadm_raid6`
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Gluster存储最佳实践的思考
参考
=====

- `Gluster Storage for Oracle Linux: Best Practices and Sizing Guideline <https://www.oracle.com/a/ocom/docs/linux/gluster-storage-linux-best-practices.pdf>`_
- `Gluster Storage for Oracle Linux: Best Practices and Sizing Guideline <https://www.oracle.com/a/ocom/docs/linux/gluster-storage-linux-best-practices.pdf>`_ Oracle Linux提供的这个最佳实践撰写得比较清晰
5 changes: 5 additions & 0 deletions source/gluster/deploy/centos/add_centos7_gluster11_server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ CentOS 7上部署的Gluster 11 集群添加服务器

我将在 :ref:`best_practices_for_gluster` 详细探讨我的实践方案以及总结改进

- 通常我们还需要做一次 ``volume rebalance`` :

.. literalinclude:: add_centos7_gluster11_server/gluster_volume_rebalance
:caption: 执行 ``gluster volume reblance`` 将brick上的文件重新hash均衡

参考
======

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 对名为 backup GlusterFS卷进行数据平衡分布
gluster volume reblance backup startup
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
.. _deploy_centos7_gluster11_lvm_mdadm_raid6:

========================================
在软RAID6+LVM上CentOS 7 部署Gluster 11
========================================

.. note::

根据 :ref:`deploy_centos7_gluster11` 迭代改进部署方案

准备工作
===========

- :ref:`build_glusterfs_11_for_centos_7`
- :ref:`gluster11_rpm_createrepo`

安装和启动服务
===============

- 安装方法同 :ref:`deploy_centos7_gluster6` :

.. literalinclude:: deploy_centos7_gluster11/yum_install_glusterfs-server
:caption: 在CentOS上安装GlusterFS

输出显示将安装如下软件包:

.. literalinclude:: deploy_centos7_gluster11/yum_install_glusterfs-server_output
:caption: 在CentOS上安装GlusterFS输出信息

- 启动GlusterFS管理服务:

.. literalinclude:: deploy_centos7_gluster11/systemctl_enable_glusterd
:caption: 启动和激活GlusterFS管理服务

- 检查 ``glusterd`` 服务状态:

.. literalinclude:: deploy_centos7_gluster11/systemctl_status_glusterd
:caption: 检查GlusterFS管理服务

输出显示服务运行正常:

.. literalinclude:: deploy_centos7_gluster11/systemctl_status_glusterd_output
:caption: 检查GlusterFS管理服务显示运行正常

- 在所有需要的CentOS 7.2服务器节点都安装好上述 ``gluster-server`` 软件包( 使用 :ref:`pssh` ):

.. literalinclude:: deploy_centos7_gluster11/pssh_install_glusterfs-server
:caption: 使用 :ref:`pssh` 批量安装 glusterfs-server

如果简单ssh执行通过如下方式完成:

.. literalinclude:: deploy_centos7_gluster11/ssh_install_glusterfs-server
:caption: 简单使用 :ref:`ssh` 顺序循环安装 glusterfs-server

配置服务
==========

- CentOS 7 默认启用了防火墙(视具体部署),确保服务器打开正确通讯端口:

.. literalinclude:: deploy_centos7_gluster11/centos7_open_ports_glusterfs
:caption: 为GlusterFS打开CentOS防火墙端口

.. note::

- 在采用分布式卷的配置时,需要确保 ``brick`` 数量是 ``replica`` 数量的整数倍。举例,配置 ``replica 3`` ,则对应 ``bricks`` 必须是 ``3`` / ``6`` / ``9`` 依次类推
- 部署案例中,采用了 ``6`` 台服务器,每个服务器 ``12`` 块NVME磁盘: ``12*6`` (3的整数倍)

- 配置gluster配对 **只需要在一台服务器上执行一次** :

.. literalinclude:: deploy_centos7_gluster11/gluster_peer_probe
:language: bash
:caption: 在 **一台** 服务器上 **执行一次** ``gluster peer probe``

- 完成后检查 ``gluster peer`` 状态:

.. literalinclude:: deploy_centos7_gluster11/gluster_peer_status
:caption: 在 **一台** 服务器上执行 ``gluster peer status`` 检查peer是否创建并连接成功

.. literalinclude:: deploy_centos7_gluster11/gluster_peer_status_output
:caption: ``gluster peer status`` 输出显示 ``peer`` 是 ``Connected`` 状态则表明构建成功
:emphasize-lines: 5

创建GlusterFS卷
==================

- 创建一个简单的脚本 ``create_gluster`` ,方便构建 ``replica 3`` 的分布式卷:

.. literalinclude:: deploy_centos7_gluster11/create_gluster
:language: bash
:caption: ``create_gluster`` 脚本,传递卷名作为参数就可以创建 ``replica 3`` 的分布式卷

.. note::

当 ``brick`` 数量是 ``replica`` 的整数倍(2倍或更多倍)时, :ref:`distributed_replicated_glusterfs_volume` 自动创建,能够同时获得高可用和高性能。但是对 ``brick`` 的排列有要求: 先 ``replica`` 后 ``distribute`` 。

所以为了能将数据分布到不同服务器上,我这里采用了特定的排列顺序: ``A:0,B:0,C:0,A:1,B:1,C:1,A:2,B2,C2...`` 以便让 ``replicas 3`` 能够精确分布到不同服务器上。

这种部署方式有利有弊: :ref:`best_practices_for_gluster` 我会详细探讨

- 将脚本加上执行权限::

chmod 755 create_gluster

- 创建卷,举例是 ``backup`` :

.. literalinclude:: deploy_centos7_gluster11/create_gluster_backup_vol
:language: bash
:caption: ``create_gluster`` 脚本创建 ``backup`` 三副本分布式卷

- 如果创建卷错误,通过以下方式删除:

.. literalinclude:: deploy_centos7_gluster11/delete_gluster_backup_vol
:language: bash
:caption: 删除 ``backup`` 卷

.. note::

这里在执行 ``gluster volume`` 的 ``stop`` 和 ``delete`` 命令时,都添加了参数 ``--mode=script`` 是为了避免交互,方便脚本命令执行。日常运维则可以不用这个参数,方便交互确认。

- 完成后检查卷状态:

.. literalinclude:: deploy_centos7_gluster11/gluster_volume_status
:language: bash
:caption: 检查 ``backup`` 卷状态

挂载gluster卷
====================

- 在客户端服务器只需要安装 ``gluster-fuse`` 软件包:

.. literalinclude:: deploy_centos7_gluster11/install_gluster-fuse
:caption: 安装GlusterFS客户端 ``gluster-fuse``

- 修改 ``/etc/fstab`` 添加如下内容:

.. literalinclude:: deploy_centos7_gluster11/gluster_fuse_fstab
:caption: GlusterFS客户端的 ``/etc/fstab``

- 挂载存储卷:

.. literalinclude:: deploy_centos7_gluster11/mount_gluster
:caption: 挂载GlusterFS卷
1 change: 1 addition & 0 deletions source/gluster/deploy/centos/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ CentOS平台GlusterFS部署
download_gluster_rpm_createrepo.rst
gluster11_rpm_createrepo.rst
deploy_centos7_gluster11.rst
deploy_centos7_gluster11_lvm_mdadm_raid6.rst
add_centos7_gluster11_server.rst

.. only:: subproject and html
Expand Down
1 change: 1 addition & 0 deletions source/linux/storage/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Linux存储
spdk/index
filesystem/index
lvm/index
software_raid/index
zfs/index
btrfs/index
stratis/index
Expand Down
2 changes: 2 additions & 0 deletions source/linux/storage/lvm/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ Linux LVM逻辑卷管理
:maxdepth: 1

lvm_infra.rst
lvmraid_vs_mdadm.rst
deploy_lvm.rst
lvmraid.rst
striped_lvm.rst
lvmcache.rst
lvmthin.rst
Expand Down
12 changes: 12 additions & 0 deletions source/linux/storage/lvm/lvm_infra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
LVM架构
================

.. note::

我在早期LVM卷学习的基础上,结合现代LVM卷管理的改进以及相关文档,修订本文

逻辑卷LVM
===========

Expand All @@ -23,6 +27,14 @@ LVM是基于Linux kernel的逻辑卷管理,通过将多个磁盘或类似的
- 精简卷(Thin volumes): LVM的精简模式配置,可以创建大于实际硬件容量的逻辑卷 - 这个功能在虚拟化 ``存储超买`` 上有很大用途,可以快速创建极大的卷并在逻辑上分配超过物理存储的容量,随着业务发展可以逐步扩容
- 缓存卷(Cache volumes) :ref:`lvmcache` : 缓存逻辑卷使用更快的块设备(如SSD)组成小型逻辑卷,通过将热点数据存储在快速的缓存卷来提高较慢的大容量存储(如机械硬盘)的性能

.. note::

LVM已经支持多种RAID模式,通过 :ref:`lvmraid` 实现了和 :ref:`mdadm` 相似的 :ref:`linux_software_raid` , :ref:`lvmraid_vs_mdadm`

.. note::

在 AMD, Intel, ARM 和 IBM Power Systems服务器中,引导装载程序(boot loader)不能读取LVM卷,所以必须将 ``/boot`` 分区创在在标准的非LVM磁盘分区。

LVM架构
=========

Expand Down
13 changes: 13 additions & 0 deletions source/linux/storage/lvm/lvmraid.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. _lvmraid:

=========================
LVM RAID( ``lvmraid`` )
=========================

参考
=========

- `Configure RAID Logical Volumes on Oracle Linux <https://docs.oracle.com/en/learn/ol-lvmraid/>`_
- `Create RAID with LVM <https://blog.programster.org/create-raid-with-lvm>`_
- `Raid1 with LVM from scratch <https://wiki.gentoo.org/wiki/Raid1_with_LVM_from_scratch>`_
- `How to Create a RAID 5 System With LVM Tool and Recover Data After Failures <https://hetmanrecovery.com/recovery_news/how-to-create-software-raid-5-with-lvm.htm>`_
58 changes: 58 additions & 0 deletions source/linux/storage/lvm/lvmraid_vs_mdadm.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.. _lvmraid_vs_mdadm:

====================
lvmraid vs. mdadm
====================

我在改进 :ref:`gluster_underlay_filesystem` ,对原有 :ref:`deploy_centos7_gluster11` 改进为 LVM on Software RAID,以实现清晰的GlusterFS ``brick`` ,支持GlusterFS的Scale out。

这里有一个 :ref:`linux_software_raid` 方案的选择问题: 究竟应该直接选择 :ref:`lvmraid` 来完成一个软件层包含RAID+LVM ,还是采用 :ref:`mdadm` 构建稳定的 :ref:`linux_software_raid` 再在其上构建LVM ?

一句话概括
=============

- :ref:`lvmraid` 是近年来逐渐在 :ref:`linux_lvm` 完善的新功能(特别是RAID5/6),RAID功能没有 ``mdadm`` 这样经历过长期的生产验证,并且也有反馈性能较差。
- :ref:`arch_linux` 社区文档同时提供了 :ref:`lvmraid` 以及 `archlinux: LVM on software RAID <https://wiki.archlinux.org/title/LVM_on_software_RAID>`_ 文档,采用 :ref:`mdadm` 实现软RAID方案更为常见

.. note::

我在生产环境采用 :ref:`mdadm` 构建稳定的 :ref:`mdadm_raid6` ,然后在软RAID之上使用 :ref:`linux_lvm` 构建卷管理,最终部署 :ref:`deploy_centos7_gluster11_lvm_mdadm_raid6`

个人的实验室环境,我将模拟测试 :ref:`lvmraid` 进行对比和学习

LVM和mdadm差异
================

LVM和 :ref:`mdadm` 都是操作系统级别提供的存储管理软件:

- LVM是磁盘控制器和操作系统之间的抽象层: 将多个磁盘空间合并为一个卷,然后划分为多个逻辑磁盘
- LVM可以提供动态添加磁盘容量功能,但是LVM自身不提供任何数据冗余

- LVM使用DM (Device Mapper)驱动程序来实现RAID,
- LVM也支持绕过DM来创建RAID,但是通常性能较差
- 虽然LVM通过 :ref:`striped_lvm` 可以实现类似 ``RAID 0`` 的条代化性能优化(数据直接分发到多个磁盘),但是也带来了限制: 不得不使用正在使用磁盘数量的倍数来扩展磁盘,并且添加新磁盘组是,条代化不会同时在所有磁盘上进行,而是在每个磁盘组内部进行
- 不过 :ref:`lvmraid` 提供了统一的命令行接口,使用较为方便

- :ref:`mdadm` 主要就是提供冗余,直接和磁盘通信并且在物理层面上在磁盘之间分发数据

- 多个磁盘组成 :ref:`mdadm` RAID阵列在操作系统中显示为单独的磁盘驱动器
- 可以按照常规磁盘驱动器相同方式进行操作
- ``mdadm`` 在内核级别添加了RAID支持(而LVM是使用MD驱动程序来处理磁盘)
- :ref:`mdadm` 构建的软RAID具有最高的性能,因为它们没有任何其他驱动程序和实用程序形式的“中间人”来向驱动器发送命令
- 通常应该使用 ``mdadm`` 来构建软件RAID,更快,更可靠

结合LVM和mdadm
=================

.. figure:: ../../../_static/linux/storage/lvm/mdadm-lvm.webp

推荐方案是采用 ``LVM on software RAID`` :

- 物理磁盘首先通过 :ref:`mdadm` 构建出 :ref:`linux_software_raid`
- 在软RAID之上,采用 :ref:`linux_lvm` 实现逻辑卷的划分和调整,可以充分使用磁盘空间并实现quota

参考
=======

- `Comparison and difference between RAID lvm and mdadm <https://recoverhdd.com/blog/comparison-and-difference-between-raid-lvm-and-mdadm.html>`_
- `LVM vs mdadm software raid <https://www.reddit.com/r/linuxadmin/comments/fhoinz/lvm_vs_mdadm_software_raid/>`_
19 changes: 19 additions & 0 deletions source/linux/storage/software_raid/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.. _linux_software_raid:

=================================
Linux 软RAID
=================================

.. toctree::
:maxdepth: 1

linux_software_raid_arch.rst
mdadm.rst
mdadm_raid6.rst

.. only:: subproject and html

Indices
=======

* :ref:`genindex`
11 changes: 11 additions & 0 deletions source/linux/storage/software_raid/linux_software_raid_arch.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.. _linux_software_raid_arch:

=======================
Linux软RAID架构
=======================

参考
======

- `Red Hat Enterprise Linux 9 Docs > Managing storage devices > Chapter 18. Managing RAID <https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/managing_storage_devices/managing-raid_managing-storage-devices>`_
- `Red Hat Enterprise Linux 9 Docs > 管理存储设备 > 第18章 管理RAID <https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/9/html/managing_storage_devices/managing-raid_managing-storage-devices>`_ (中文版)
5 changes: 5 additions & 0 deletions source/linux/storage/software_raid/mdadm.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.. _mdadm:

========================
mdadm 软RAID构建
========================
9 changes: 9 additions & 0 deletions source/linux/storage/software_raid/mdadm_raid6.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.. _mdadm_raid6:

=====================
mdadm构建RAID6
=====================

参考
======

1 change: 1 addition & 0 deletions source/mysql/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ MySQL是使用最广泛的开源数据库,很多开源项目都会在后端使
:maxdepth: 1

installation/index
query/index
admin/index
troubleshoot/index
database_sharding.rst
Expand Down
17 changes: 17 additions & 0 deletions source/mysql/query/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.. _mysql_query:

=================================
MySQL 查询
=================================

.. toctree::
:maxdepth: 1

mysql_query_date_time.rst

.. only:: subproject and html

Indices
=======

* :ref:`genindex`

0 comments on commit cfe7629

Please sign in to comment.