搜索

5.4. 使用 Ceph Manager 负载均衡器模块

download PDF

balancer 是 Ceph Manager(ceph-mgr)的一个模块,用于优化 OSD 之间放置组(PG)放置,从而实现平衡的分发(可自动或监管方式)。

目前无法禁用 balancer 模块。它只能关闭自定义配置。

模式

目前支持的负载均衡器模式有两种:

  • CRUSH -compat :CRUSH compat 模式使用 Ceph Luminous 中引入的兼容 weight-set 功能来管理 CRUSH 层次结构中设备的备用权重集合。普通权重应保持设置为设备的大小,以反映您要存储在设备上的数据数量。然后,负载均衡器会优化 weight-set 值,以较小的增量调整它们,以实现与目标分布匹配的发行版。由于 PG 放置是一种伪随机进程,因此放置有自然变化;通过优化权重,平衡平衡器的作用是自然变化。

    这个模式与旧的客户端完全向后兼容。当 OSDMap 和 CRUSH map 与旧客户端共享时,平衡器会将优化的 weightsff 显示为实际权重。

    此模式的主要限制是,如果层次结构的子树共享任何 OSD,则均衡器无法处理具有不同放置规则的多个 CRUSH 层次结构。由于此配置使得在共享 OSD 上管理空间利用率比较困难,因此通常不建议这样做。因此,这个限制通常不是问题。

  • upmap: 从 Luminous 开始,OSDMap 可以存储各个 OSD 的显式映射,如普通的 CRUSH 放置计算例外。这些 upmap 条目提供对 PG 映射的精细控制。此 CRUSH 模式将优化各个 PG 的放置,以实现均衡的分发。在大多数情况下,此分布为"完美",每个 OSD +/-1 PG 上相等的 PG 数量,因为它们可能无法均匀划分。

    重要

    要允许使用这个功能,您必须使用以下命令告知集群只需要支持 luminous 或更新的客户端:

    [ceph: root@host01 /]# ceph osd set-require-min-compat-client luminous

    如果任何 pre-luminous 客户端或守护进程连接到 monitor,则此命令会失败。

    由于一个已知问题,内核 CephFS 客户端会将自身报告为 jewel 客户端。要临时解决这个问题,请使用 --yes-i-really-mean-it 标志:

    [ceph: root@host01 /]# ceph osd set-require-min-compat-client luminous --yes-i-really-mean-it

    您可以检查哪些客户端版本被用于:

    [ceph: root@host01 /]# ceph features

5.4.1. 使用容量平衡 Red Hat Ceph 集群

使用容量平衡 Red Hat Ceph 存储集群。

先决条件

  • 一个正在运行的 Red Hat Ceph Storage 集群。

流程

  1. 检查是否启用了 balancer 模块:

    示例

    [ceph: root@host01 /]# ceph mgr module enable balancer

  2. 打开 balancer 模块:

    示例

    [ceph: root@host01 /]# ceph balancer on

  3. 要更改模式,请使用以下命令:默认模式是 upmap

    示例

    [ceph: root@host01 /]# ceph balancer mode crush-compat

    示例

    [ceph: root@host01 /]# ceph balancer mode upmap

  4. 检查负载均衡器的当前状态。

    示例

    [ceph: root@host01 /]# ceph balancer status

自动平衡

默认情况下,在打开 balancer 模块时会使用自动平衡:

示例

[ceph: root@host01 /]# ceph balancer on

您可以使用以下方法再次关闭负载均衡器:

示例

[ceph: root@host01 /]# ceph balancer off

这使用 crush-compat 模式,与旧的客户端向后兼容,并随着时间的推移对数据分布进行小更改,以确保 OSD 平等地使用。

节流

如果集群已降级,则没有对 PG 分发的调整,例如,如果 OSD 失败,系统尚未修复自身。

当集群处于健康状态时,负载均衡器会节流到其更改,使得 PG 百分比被错误或需要移动,默认低于 5%。可以使用 target_max_misplaced_ratio 设置调整这个百分比。例如,将阈值增加到 7%:

示例

[ceph: root@host01 /]# ceph config-key set mgr target_max_misplaced_ratio .07

对于自动平衡:

  • 在自动负载均衡器运行之间将休眠的秒数:

示例

[ceph: root@host01 /]# ceph config set mgr mgr/balancer/sleep_interval 60

  • 将一天的时间设置为以 HHMM 格式开始自动平衡:

示例

[ceph: root@host01 /]# ceph config set mgr mgr/balancer/begin_time 0000

  • 将当天的时间设置为以 HHMM 格式完成自动平衡:

示例

[ceph: root@host01 /]# ceph config set mgr mgr/balancer/end_time 2359

  • 限制本周或更高版本的自动平衡。使用与 crontab 相同的约定,0 为 Sunday,1 为 Monday,以此类推:

示例

[ceph: root@host01 /]# ceph config set mgr mgr/balancer/begin_weekday 0

  • 限制本周或更早版本自动平衡。这使用与 crontab 相同的约定,0 为 Sunday,1 为 Monday,以此类推:

示例

[ceph: root@host01 /]# ceph config set mgr mgr/balancer/end_weekday 6

  • 定义自动平衡仅限于的池 ID。此默认值是一个空字符串,表示所有池都是 balanced。可以使用 ceph osd pool ls detail 命令获取数字池 ID:

示例

[ceph: root@host01 /]# ceph config set mgr mgr/balancer/pool_ids 1,2,3

监控的优化

balancer 操作分为几个不同的阶段:

  1. 构建 计划
  2. 评估数据分发的质量,针对当前的 PG 分发,或在执行一个计划(plan)后生成的 PG 分发。
  3. 执行计划

    • 评估和评分当前发行版:

      示例

      [ceph: root@host01 /]# ceph balancer eval

    • 评估单个池的发布:

      语法

      ceph balancer eval POOL_NAME

      示例

      [ceph: root@host01 /]# ceph balancer eval rbd

    • 查看更多评估详情:

      示例

      [ceph: root@host01 /]# ceph balancer eval-verbose ...

    • 使用当前配置模式生成计划:

      语法

      ceph balancer optimize PLAN_NAME

      使用自定义计划名称替换 PLAN_NAME

      示例

      [ceph: root@host01 /]# ceph balancer optimize rbd_123

    • 查看计划的内容:

      语法

      ceph balancer show PLAN_NAME

      示例

      [ceph: root@host01 /]# ceph balancer show rbd_123

    • 要丢弃旧计划:

      语法

      ceph balancer rm PLAN_NAME

      示例

      [ceph: root@host01 /]# ceph balancer rm rbd_123

    • 要查看当前记录的计划,请使用 status 命令:

      [ceph: root@host01 /]# ceph balancer status
    • 要计算执行计划后结果的分发质量:

      语法

      ceph balancer eval PLAN_NAME

      示例

      [ceph: root@host01 /]# ceph balancer eval rbd_123

    • 执行计划:

      语法

      ceph balancer execute PLAN_NAME

      示例

      [ceph: root@host01 /]# ceph balancer execute rbd_123

      注意

      只有预期会改进发布时才执行计划。执行后,计划将被丢弃。

5.4.2. 使用读取负载均衡器平衡 Red Hat Ceph 集群 [技术预览]

重要

read Balancer 只是一个技术预览功能,仅适用于 Red Hat Ceph Storage 7.0。红帽产品服务级别协议(SLA)不支持技术预览功能,且其功能可能并不完善,因此红帽不建议在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。如需了解更多详细信息,请参阅红帽技术预览功能的支持范围。

如果您有未平衡的主 OSD,您可以使用 osdmaptool 中内置的离线优化器进行更新。

红帽建议您在运行负载均衡器前运行容量负载均衡器以确保最佳结果。

按照流程中的步骤,使用读取负载均衡器平衡集群:

先决条件

  • 一个正在运行的和容量平衡的 Red Hat Ceph Storage 集群。
  • 红帽建议您运行容量负载均衡器,以便在运行读取负载均衡器前平衡每个 OSD 上的容量,以确保最佳结果。运行以下命令来平衡容量:

    1. 获取 osdmap 的最新副本。

      [ceph: root@host01 /]# ceph osd  getmap -o map
    2. 运行 upmap balancer。

      [ceph: root@host01 /]# ospmaptool map –upmap out.txt
    3. 文件 out.txt 包含所提议的解决方案。

      此流程中的命令是运行的常规 Ceph CLI 命令,以将更改应用到集群。

      如果 out.txt 文件中有任何建议,请运行以下命令。

      [ceph: root@host01 /]# source out.txt

      如需更多信息,请参阅使用容量平衡 IBM Ceph 集群

流程

  1. 检查每个池的 read_balance_score:

    [ceph: root@host01 /]# ceph osd pool ls detail

    如果 read_balance_score 高于 1,则您的池具有未平衡的 Primary OSD。

    对于同构集群,最佳分数为 [Ceil{(PG/Number of OSDs)}/(PG/Number of OSDs)]/[ (PG/Number of OSDs 的数量)/(PG/Number of OSDs)]。例如,如果您有一个具有 32 个 PG 和 10 个 OSD 的池,则 (PG/Number of OSDs 的数量) = 32/10 = 3.2。因此,如果所有设备都相同,则最佳分数是 3.2 的静默值(PG/Number of OSDs 的数量)是 4/3.2 = 1.25。如果您在具有 64 个 PG 的同一系统中有另一个池,则最佳分数为 7/6.4 =1.09375

    输出示例:

    $ ceph osd pool ls detail
    pool 1 '.mgr' replicated size 3 min_size 1 crush_rule 0 object_hash rjenkins pg_num 1 pgp_num 1 autoscale_mode on last_change 17 flags hashpspool stripe_width 0 pg_num_max 32 pg_num_min 1 application mgr read_balance_score 3.00
    pool 2 'cephfs.a.meta' replicated size 3 min_size 1 crush_rule 0 object_hash rjenkins pg_num 16 pgp_num 16 autoscale_mode on last_change 55 lfor 0/0/25 flags hashpspool stripe_width 0 pg_autoscale_bias 4 pg_num_min 16 recovery_priority 5 application cephfs read_balance_score 1.50
    pool 3 'cephfs.a.data' replicated size 3 min_size 1 crush_rule 0 object_hash rjenkins pg_num 128 pgp_num 128 autoscale_mode on last_change 27 lfor 0/0/25 flags hashpspool,bulk stripe_width 0 application cephfs read_balance_score 1.31

  2. 获取 osdmap 的最新副本:

    [ceph: root@host01 /]# ceph osd getmap -o om

    输出示例:

    got osdmap epoch 56

  3. 运行 optimizer:

    文件 out.txt 包含所提议的解决方案。

    [ceph: root@host01 /]# osdmaptool om --read out.txt --read-pool _POOL_NAME_ [--vstart]

    输出示例:

    $ osdmaptool om --read out.txt --read-pool cephfs.a.meta
    ./bin/osdmaptool: osdmap file 'om'
    writing upmap command output to: out.txt
    ---------- BEFORE ------------
     osd.0 | primary affinity: 1 | number of prims: 4
     osd.1 | primary affinity: 1 | number of prims: 8
     osd.2 | primary affinity: 1 | number of prims: 4
    
    read_balance_score of 'cephfs.a.meta': 1.5
    
    ---------- AFTER ------------
     osd.0 | primary affinity: 1 | number of prims: 5
     osd.1 | primary affinity: 1 | number of prims: 6
     osd.2 | primary affinity: 1 | number of prims: 5
    
    read_balance_score of 'cephfs.a.meta': 1.13
    
    
    num changes: 2

  4. 文件 out.txt 包含所提议的解决方案。

    此流程中的命令是运行正常的 Ceph CLI 命令,以便对集群应用更改。如果您在 vstart 集群中工作,您可以传递 --vstart 参数,以便 CLI 命令使用 ./bin/ 前缀进行格式化。

    [ceph: root@host01 /]# source out.txt

    输出示例:

    $ cat out.txt
    ceph osd pg-upmap-primary 2.3 0
    ceph osd pg-upmap-primary 2.4 2
    
    $ source out.txt
    change primary for pg 2.3 to osd.0
    change primary for pg 2.4 to osd.2

    注意

    如果您第一次运行 ceph osd pg-upmap-primary 命令,您可能会收到如下警告:

    Error EPERM: min_compat_client luminous < reef, which is required for pg-upmap-primary. Try 'ceph osd set-require-min-compat-client reef' before using the new interface

    在本例中,运行推荐的命令 ceph osd set-require-min-compat-client reef,并调整集群的 min-compact-client。

注意

如果放置组(PG)数量添加到集群中或从集群中删除任何 OSD,则请考虑重新检查分数并重新运行负载均衡器,因为这些操作可能会显著影响对池的读取负载均衡器的影响。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.