4.3. 为守护进程设置 CRUSH 位置


在进入扩展模式之前,您需要通过将 CRUSH 位置设置为 Red Hat Ceph Storage 集群中的守护进程来准备集群。有两种方法可以做到这一点:

  • 通过服务配置文件引导集群,其中位置作为部署的一部分添加到主机中。
  • 在部署集群后,通过 ceph osd crush add-bucketceph osd crush move 命令手动设置位置。

方法 1:引导集群

先决条件

  • 对节点的根级别访问权限。

流程

  1. 如果要引导新存储集群,您可以创建服务配置 .yaml 文件,该文件将节点添加到 Red Hat Ceph Storage 集群,并为应该运行该服务设置特定的标签:

    示例

    service_type: host
    addr: host01
    hostname: host01
    location:
      root: default
      datacenter: DC1
    labels:
      - osd
      - mon
      - mgr
    ---
    service_type: host
    addr: host02
    hostname: host02
    location:
      datacenter: DC1
    labels:
      - osd
      - mon
    ---
    service_type: host
    addr: host03
    hostname: host03
    location:
      datacenter: DC1
    labels:
      - osd
      - mds
      - rgw
    ---
    service_type: host
    addr: host04
    hostname: host04
    location:
      root: default
      datacenter: DC2
    labels:
      - osd
      - mon
      - mgr
    ---
    service_type: host
    addr: host05
    hostname: host05
    location:
      datacenter: DC2
    labels:
      - osd
      - mon
    ---
    service_type: host
    addr: host06
    hostname: host06
    location:
      datacenter: DC2
    labels:
      - osd
      - mds
      - rgw
    ---
    service_type: host
    addr: host07
    hostname: host07
    labels:
      - mon
    ---
    service_type: mon
    placement:
      label: "mon"
    ---
    service_id: cephfs
    placement:
      label: "mds"
    ---
    service_type: mgr
    service_name: mgr
    placement:
      label: "mgr"
    ---
    service_type: osd
    service_id: all-available-devices
    service_name: osd.all-available-devices
    placement:
      label: "osd"
    spec:
      data_devices:
        all: true
    ---
    service_type: rgw
    service_id: objectgw
    service_name: rgw.objectgw
    placement:
      count: 2
      label: "rgw"
    spec:
      rgw_frontend_port: 8080
    Copy to Clipboard Toggle word wrap

  2. 使用 --apply-spec 选项引导存储集群:

    语法

    cephadm bootstrap --apply-spec CONFIGURATION_FILE_NAME --mon-ip MONITOR_IP_ADDRESS --ssh-private-key PRIVATE_KEY --ssh-public-key PUBLIC_KEY --registry-url REGISTRY_URL --registry-username USER_NAME --registry-password PASSWORD
    Copy to Clipboard Toggle word wrap

    示例

    [root@host01 ~]# cephadm bootstrap --apply-spec initial-config.yaml --mon-ip 10.10.128.68 --ssh-private-key /home/ceph/.ssh/id_rsa --ssh-public-key /home/ceph/.ssh/id_rsa.pub --registry-url registry.redhat.io --registry-username myuser1 --registry-password mypassword1
    Copy to Clipboard Toggle word wrap

    重要

    您可以在 cephadm bootstrap 命令中使用不同的命令选项。但是,始终包含 use -apply-spec 选项以使用服务配置文件并配置主机位置。

方法 2:在部署后设置位置

先决条件

  • 对节点的根级别访问权限。

流程

  1. 添加两个存储桶,将非tiebreaker 监视器的位置设置为 CRUSH map,将 bucket 类型指定为 datacenter

    语法

    ceph osd crush add-bucket BUCKET_NAME BUCKET_TYPE
    Copy to Clipboard Toggle word wrap

    示例

    [ceph: root@host01 /]# ceph osd crush add-bucket DC1 datacenter
    [ceph: root@host01 /]# ceph osd crush add-bucket DC2 datacenter
    Copy to Clipboard Toggle word wrap

  2. 将存储桶移到 root=default 下:

    语法

    ceph osd crush move BUCKET_NAME root=default
    Copy to Clipboard Toggle word wrap

    示例

    [ceph: root@host01 /]# ceph osd crush move DC1 root=default
    [ceph: root@host01 /]# ceph osd crush move DC2 root=default
    Copy to Clipboard Toggle word wrap

  3. 根据所需的 CRUSH 放置移动 OSD 主机:

    语法

    ceph osd crush move HOST datacenter=DATACENTER
    Copy to Clipboard Toggle word wrap

    示例

    [ceph: root@host01 /]# ceph osd crush move host01 datacenter=DC1
    Copy to Clipboard Toggle word wrap

4.3.1. 进入扩展模式

新的扩展模式旨在处理两个站点。在 2 个站点集群中,组件可用性中断的风险较低。

先决条件

  • 对节点的根级别访问权限。
  • CRUSH 位置设置为主机。

流程

  1. 设置每个 monitor 的位置,与 CRUSH map 匹配:

    语法

    ceph mon set_location HOST datacenter=DATACENTER
    Copy to Clipboard Toggle word wrap

    示例

    [ceph: root@host01 /]# ceph mon set_location host01 datacenter=DC1
    [ceph: root@host01 /]# ceph mon set_location host02 datacenter=DC1
    [ceph: root@host01 /]# ceph mon set_location host04 datacenter=DC2
    [ceph: root@host01 /]# ceph mon set_location host05 datacenter=DC2
    [ceph: root@host01 /]# ceph mon set_location host07 datacenter=DC3
    Copy to Clipboard Toggle word wrap

  2. 生成 CRUSH 规则,它将两个副本放在每个数据中心上:

    语法

    ceph osd getcrushmap > COMPILED_CRUSHMAP_FILENAME
    crushtool -d COMPILED_CRUSHMAP_FILENAME -o DECOMPILED_CRUSHMAP_FILENAME
    Copy to Clipboard Toggle word wrap

    示例

    [ceph: root@host01 /]# ceph osd getcrushmap > crush.map.bin
    [ceph: root@host01 /]# crushtool -d crush.map.bin -o crush.map.txt
    Copy to Clipboard Toggle word wrap

    1. 编辑 decompiled CRUSH map 文件以添加新规则:

      示例

      rule stretch_rule {
              id 1 
      1
      
              type replicated
              min_size 1
              max_size 10
              step take DC1 
      2
      
              step chooseleaf firstn 2 type host
              step emit
              step take DC2 
      3
      
              step chooseleaf firstn 2 type host
              step emit
      }
      Copy to Clipboard Toggle word wrap

      1
      规则 ID 必须是唯一的。在本例中,只有一个带有 id 0 的规则,因此使用 id 1,但您可能需要根据现有规则的数量使用不同的规则 ID。
      2 3
      在本例中,有两个数据中心存储桶,名为 DC1DC2
      注意

      此规则使集群对数据中心 DC1 具有 read-affinity。因此,所有读取或写入都通过放置在 DC1 中的 Ceph OSD 进行。

      如果这不是理想的要求,并在区间平均分配读取或写入,CRUSH 规则如下:

      示例

      rule stretch_rule {
      id 1
      type replicated
      min_size 1
      max_size 10
      step take default
      step choose firstn 0 type datacenter
      step chooseleaf firstn 2 type host
      step emit
      }
      Copy to Clipboard Toggle word wrap

      在此规则中,数据中心会随机选择,并自动选择。

      如需有关 firstnindep 选项的更多信息,请参阅 CRUSH 规则

  3. 注入 CRUSH map,使规则可供集群使用:

    语法

    crushtool -c DECOMPILED_CRUSHMAP_FILENAME -o COMPILED_CRUSHMAP_FILENAME
    ceph osd setcrushmap -i COMPILED_CRUSHMAP_FILENAME
    Copy to Clipboard Toggle word wrap

    示例

    [ceph: root@host01 /]# crushtool -c crush.map.txt -o crush2.map.bin
    [ceph: root@host01 /]# ceph osd setcrushmap -i crush2.map.bin
    Copy to Clipboard Toggle word wrap

  4. 如果您没有以连接模式运行 monitor,请将选择策略设置为 connectivity

    示例

    [ceph: root@host01 /]# ceph mon set election_strategy connectivity
    Copy to Clipboard Toggle word wrap

  5. 通过将 tiebreaker 监控的位置设置为在数据中心间分割,进入扩展模式:

    语法

    ceph mon set_location HOST datacenter=DATACENTER
    ceph mon enable_stretch_mode HOST stretch_rule datacenter
    Copy to Clipboard Toggle word wrap

    示例

    [ceph: root@host01 /]# ceph mon set_location host07 datacenter=DC3
    [ceph: root@host01 /]# ceph mon enable_stretch_mode host07 stretch_rule datacenter
    Copy to Clipboard Toggle word wrap

    在本例中,监控器 mon.host07 是 tiebreaker。

    重要

    tiebreaker monitor 的位置应该与您之前设置非tiebreaker 监视器的数据中心不同。在上例中,它是数据中心 DC3

    重要

    当您尝试进入扩展模式时,不要将此数据中心添加到 CRUSH map 中,因为它会产生以下错误:

    Error EINVAL: there are 3 datacenters in the cluster but stretch mode currently only works with 2!
    Copy to Clipboard Toggle word wrap
    注意

    如果要编写用于部署 Ceph 的工具,您可以在引导监控器时使用 new -set-crush-location 选项,而不是运行 ceph mon set_location 命令。此选项只接受单个 bucket=location 对,如 ceph-mon --set-crush-location 'datacenter=DC1',它必须与运行 enable_stretch_mode 命令时指定的 bucket 类型匹配。

  6. 验证扩展模式是否已成功启用:

    示例

    [ceph: root@host01 /]# ceph osd dump
    
    epoch 361
    fsid 1234ab78-1234-11ed-b1b1-de456ef0a89d
    created 2023-01-16T05:47:28.482717+0000
    modified 2023-01-17T17:36:50.066183+0000
    flags sortbitwise,recovery_deletes,purged_snapdirs,pglog_hardlimit
    crush_version 31
    full_ratio 0.95
    backfillfull_ratio 0.92
    nearfull_ratio 0.85
    require_min_compat_client luminous
    min_compat_client luminous
    require_osd_release quincy
    stretch_mode_enabled true
    stretch_bucket_count 2
    degraded_stretch_mode 0
    recovering_stretch_mode 0
    stretch_mode_bucket 8
    Copy to Clipboard Toggle word wrap

    stretch_mode_enabled 应设为 true。您还可以查看扩展存储桶的数量、扩展模式存储桶以及扩展模式是否降级或恢复。

  7. 验证监控器是否在适当的位置:

    示例

    [ceph: root@host01 /]# ceph mon dump
    
    epoch 19
    fsid 1234ab78-1234-11ed-b1b1-de456ef0a89d
    last_changed 2023-01-17T04:12:05.709475+0000
    created 2023-01-16T05:47:25.631684+0000
    min_mon_release 16 (pacific)
    election_strategy: 3
    stretch_mode_enabled 1
    tiebreaker_mon host07
    disallowed_leaders host07
    0: [v2:132.224.169.63:3300/0,v1:132.224.169.63:6789/0] mon.host07; crush_location {datacenter=DC3}
    1: [v2:220.141.179.34:3300/0,v1:220.141.179.34:6789/0] mon.host04; crush_location {datacenter=DC2}
    2: [v2:40.90.220.224:3300/0,v1:40.90.220.224:6789/0] mon.host01; crush_location {datacenter=DC1}
    3: [v2:60.140.141.144:3300/0,v1:60.140.141.144:6789/0] mon.host02; crush_location {datacenter=DC1}
    4: [v2:186.184.61.92:3300/0,v1:186.184.61.92:6789/0] mon.host05; crush_location {datacenter=DC2}
    dumped monmap epoch 19
    Copy to Clipboard Toggle word wrap

    您还可以看到哪个 monitor 是 tiebreaker,以及 monitor 选择策略。

4.3.2. 为扩展模式配置 CRUSH map

使用此信息为扩展模式配置 CRUSH map。

先决条件

在开始前,请确保您有以下先决条件:

  • 对节点的根级别访问权限。
  • CRUSH 位置设置为主机。

流程

  1. 通过安装 ceph-base RPM 软件包来创建使用此 OSD crush 拓扑的 CRUSH 规则,以便使用 crushtool 命令。

    语法

    dnf -y install ceph-base
    Copy to Clipboard Toggle word wrap

  2. 从集群获取编译的 CRUSH map。

    语法

    ceph osd getcrushmap > /etc/ceph/crushmap.bin
    Copy to Clipboard Toggle word wrap

  3. 解译 CRUSH map,并将它转换为文本文件以对其进行编辑。

    语法

    crushtool -d /etc/ceph/crushmap.bin -o /etc/ceph/crushmap.txt
    Copy to Clipboard Toggle word wrap

  4. 通过编辑文件末尾的 /etc/ceph/crushmap.txt,将以下规则添加到 CRUSH map。此规则在数据中心中平均分配读取和写入。

    语法

    rule stretch_rule {
            id 1
            type replicated
            step take default
            step choose firstn 0 type datacenter
            step chooseleaf firstn 2 type host
            step emit
     }
    Copy to Clipboard Toggle word wrap

    1. (可选)使集群与数据中心 1 具有读/写关联性。

      语法

      rule stretch_rule {
               id 1
               type replicated
               step take DC1
               step chooseleaf firstn 2 type host
               step emit
               step take DC2
               step chooseleaf firstn 2 type host
               step emit
       }
      Copy to Clipboard Toggle word wrap

      The CRUSH rule declared contains the following information:
           Rule name
                Description: A unique name for identifying the rule.
                Value: stretch_rule
           id
                Description: A unique whole number for identifying the rule.
                Value: 1
           type
                Description: Describes a rule for either a storage drive replicated or erasure-coded.
                Value: replicated
           step take default
                Description: Takes the root bucket called default, and begins iterating down the tree.
           step take DC1
                Description: Takes the bucket called DC1, and begins iterating down the tree.
           step choose firstn 0 type datacenter
                Description: Selects the datacenter bucket, and goes into its subtrees.
           step chooseleaf firstn 2 type host
                Description: Selects the number of buckets of the given type. In this case, it is two different hosts located in the datacenter it entered at the previous level.
           step emit
                Description: Outputs the current value and empties the stack. Typically used at the end of a rule, but may also be used to pick from different trees in the same rule.
      Copy to Clipboard Toggle word wrap
  5. /etc/ceph/crushmap.txt 编译新的 CRUSH map,并将其转换为二进制文件 /etc/ceph/crushmap2.bin

    语法

    crushtool -c /path/to/crushmap.txt -o /path/to/crushmap2.bin
    Copy to Clipboard Toggle word wrap

    示例

    [ceph: root@host01 /]# crushtool -c /etc/ceph/crushmap.txt -o /etc/ceph/crushmap2.bin
    Copy to Clipboard Toggle word wrap

  6. 将新创建的 CRUSH map 重新注入集群。

    语法

    ceph osd setcrushmap -i /path/to/compiled_crushmap
    Copy to Clipboard Toggle word wrap

    示例

    [ceph: root@host01 /]# ceph osd setcrushmap -i /path/to/compiled_crushmap
    17
    Copy to Clipboard Toggle word wrap

    注意

    根据对 CRUSH 映射所做的更改,数字 17 是一个计数器,增加(18、19 等)。

验证

验证新创建的 stretch_rule 可供使用。

语法

ceph osd crush rule ls
Copy to Clipboard Toggle word wrap

示例

[ceph: root@host01 /]# ceph osd crush rule ls

replicated_rule
stretch_rule
Copy to Clipboard Toggle word wrap

4.3.2.1. 进入扩展模式

扩展模式旨在处理两个站点。对于带有 2 个站点集群的组件可用性中断,存在更小的风险。

先决条件

在开始前,请确保您有以下先决条件:

  • 对节点的根级别访问权限。
  • CRUSH 位置设置为主机。
  • 配置为包含扩展规则的 CRUSH map。
  • 集群中没有纠删代码池。
  • 两个站点的权重是相同的。

流程

  1. 检查监视器所使用的当前选择策略。

    语法

    ceph mon dump | grep election_strategy
    Copy to Clipboard Toggle word wrap

    注意

    默认情况下,Ceph 集群 election_strategy 设置为 1

    示例

    [ceph: root@host01 /]# ceph mon dump | grep election_strategy
    
    dumped monmap epoch 9
    election_strategy: 1
    Copy to Clipboard Toggle word wrap

  2. 将选择策略更改为 连接

    语法

    ceph mon set election_strategy connectivity
    Copy to Clipboard Toggle word wrap

    有关配置选择策略的更多信息,请参阅配置监控选择策略

  3. 使用 ceph mon dump 命令,验证选择策略是否已更新为 3

    示例

    [ceph: root@host01 /]# ceph mon dump | grep election_strategy
    
    dumped monmap epoch 22
    election_strategy: 3
    Copy to Clipboard Toggle word wrap

  4. 设置 tiebreaker 监视器的位置,使其划分到数据中心。

    语法

    ceph mon set_location TIEBREAKER_HOST datacenter=DC3
    Copy to Clipboard Toggle word wrap

    示例

    [ceph: root@host01 /]# ceph mon set_location host07 datacenter=DC3
    Copy to Clipboard Toggle word wrap

  5. 验证 tiebreaker 监控器是否如预期设置。

    语法

    ceph mon dump
    Copy to Clipboard Toggle word wrap

    示例

    [ceph: root@host01 /]# ceph mon dump
    
    epoch 8
    
    fsid 4158287e-169e-11f0-b1ad-fa163e98b991
    
    last_changed 2025-04-11T07:14:48.652801+0000
    
    created 2025-04-11T06:29:24.974553+0000
    
    min_mon_release 19 (squid)
    
    election_strategy: 3
    
    0: [v2:10.0.57.33:3300/0,v1:10.0.57.33:6789/0] mon.host07; crush_location {datacenter=DC3}
    
    1: [v2:10.0.58.200:3300/0,v1:10.0.58.200:6789/0] mon.host05; crush_location {datacenter=DC2}
    
    2: [v2:10.0.58.47:3300/0,v1:10.0.58.47:6789/0] mon.host02; crush_location {datacenter=DC1}
    
    3: [v2:10.0.58.104:3300/0,v1:10.0.58.104:6789/0] mon.host04; crush_location {datacenter=DC2}
    
    4: [v2:10.0.58.38:3300/0,v1:10.0.58.38:6789/0] mon.host01; crush_location {datacenter=DC1}
    
    dumped monmap epoch 8
    0
    Copy to Clipboard Toggle word wrap

  6. 进入扩展模式。

    语法

    ceph mon enable_stretch_mode TIEBREAKER_HOST STRETCH_RULE STRETCH_BUCKET
    Copy to Clipboard Toggle word wrap

    在以下示例中:

    • tiebreaker 节点设置为 host07。
    • 扩展规则为 stretch_rule,如 中创建的。
    • 扩展存储桶被设置为数据中心。
[ceph: root@host01 /]# ceph mon enable_stretch_mode host07 stretch_rule datacenter
Copy to Clipboard Toggle word wrap

验证

通过继续 CROSREF 来验证扩展模式是否已正确实现。

4.3.2.2. 验证扩展模式

使用此信息来验证扩展模式是否使用实施的 CRUSH 规则正确创建。

流程

  1. 验证所有池正在使用 Ceph 集群中创建的 CRUSH 规则。在这些示例中,CRUSH 规则设置为 stretch_rule,具体根据 在为扩展模式 配置 CRUSH 映射 时创建的设置。

    语法

    for pool in $(rados lspools);do echo -n "Pool: ${pool}; ";ceph osd pool get ${pool} crush_rule;done
    Copy to Clipboard Toggle word wrap

    示例

    [ceph: root@host01 /]# for pool in $(rados lspools);do echo -n "Pool: ${pool}; ";ceph osd pool get ${pool} crush_rule;done
    Pool: device_health_metrics; crush_rule: stretch_rule
    Pool: cephfs.cephfs.meta; crush_rule: stretch_rule
    Pool: cephfs.cephfs.data; crush_rule: stretch_rule
    Pool: .rgw.root; crush_rule: stretch_rule
    Pool: default.rgw.log; crush_rule: stretch_rule
    Pool: default.rgw.control; crush_rule: stretch_rule
    Pool: default.rgw.meta; crush_rule: stretch_rule
    Pool: rbdpool; crush_rule: stretch_rule
    Copy to Clipboard Toggle word wrap

  2. 验证是否启用了扩展模式。确保 stretch_mode_enabled 设置为 true

    语法

    ceph osd dump
    Copy to Clipboard Toggle word wrap

    输出包括以下信息:

    stretch_mode_enabled
    如果启用了扩展模式,则设置为 true
    stretch_bucket_count
    使用 OSD 的数据中心数量。
    degraded_stretch_mode
    如果没有降级,则输出 0。如果扩展模式降级,这会输出 up 站点的数量。
    recovering_stretch_mode
    如果没有恢复,则输出 0。如果扩展模式正在恢复,则输出为 1
    stretch_mode_bucket

    为每个 CRUSH bucket 类型设置的唯一值。对于数据中心,这个值通常设置为 8

    示例

    "stretch_mode": {
                "stretch_mode_enabled": true,
                "stretch_bucket_count": 2,
                "degraded_stretch_mode": 0,
                "recovering_stretch_mode": 1,
                "stretch_mode_bucket": 8
    Copy to Clipboard Toggle word wrap

  3. 使用 ceph mon dump 来验证扩展模式是否使用 mon map。

    确保以下内容:

    • stretch_mode_enabled 设置为 1
    • 正确的 mon 主机被设置为 tiebreaker_mon
    • 将正确的 mon 主机设置为 disallowed_leaders

      语法

      ceph mon dump
      Copy to Clipboard Toggle word wrap

      示例

      [ceph: root@host01 /]# ceph mon dump
      epoch 16
      fsid ff19789c-f5c7-11ef-8e1c-fa163e4e1f7e
      last_changed 2025-02-28T12:12:51.089706+0000
      created 2025-02-28T11:34:59.325503+0000
      min_mon_release 19 (squid)
      election_strategy: 3
      stretch_mode_enabled 1
      tiebreaker_mon host07
      disallowed_leaders host07
      0: [v2:10.0.56.37:3300/0,v1:10.0.56.37:6789/0] mon.host01; crush_location {datacenter=DC1}
      1: [v2:10.0.59.188:3300/0,v1:10.0.59.188:6789/0] mon.host05; crush_location {datacenter=DC2}
      2: [v2:10.0.59.35:3300/0,v1:10.0.59.35:6789/0] mon.host02; crush_location {datacenter=DC1}
      3: [v2:10.0.56.189:3300/0,v1:10.0.56.189:6789/0] mon.host07; crush_location {datacenter=DC3}
      4: [v2:10.0.56.13:3300/0,v1:10.0.56.13:6789/0] mon.host04; crush_location {datacenter=DC2}
      dumped monmap epoch 16
      Copy to Clipboard Toggle word wrap

接下来要做什么

  1. 部署、配置和管理 Ceph 对象网关。有关更多信息,请参阅 Ceph 对象网关
  2. 管理、创建、配置和使用 Ceph 块设备。有关更多信息,请参阅 Ceph 块设备
  3. 创建、挂载和工作 Ceph 文件系统(CephFS)。有关更多信息,请参阅 Ceph 文件系统
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat