2.3. CRUSH 中的 Ceph OSD

具有 OSD 的 CRUSH 层次结构后,将 OSD 添加到 CRUSH 层次结构中。您也可以从现有的层次结构中移动或删除 OSD。Ceph CLI 用法具有以下值:

id
描述
OSD 的数字 ID。
类型
整数
必填
示例
0
name
描述
OSD 的全名。
类型
字符串
必填
示例
osd.0
weight
描述
OSD 的 CRUSH 权重。
类型
必填
示例
2.0
root
描述
OSD 所在的层次结构或树的根 bucket 的名称。
类型
键值对.
必填
示例
root=defaultroot=replicated_rule
bucket-type
描述
个或多个 name-value 对,其中 name 是 bucket 类型,值是 bucket 的名称。您可以在 CRUSH 层次结构中为 OSD 指定 CRUSH 位置。
类型
健值对。
必填
示例
datacenter=dc1 room=room1 row=foo rack=bar host=foo-bar-1

2.3.1. 查看 CRUSH 中的 OSD

ceph osd crush tree 命令在树 视图中打印 CRUSH bucket 和项。使用此命令来确定特定 bucket 中的 OSD 列表。它将打印类似于 ceph osd 树 的输出。

要返回更多详细信息,请执行以下操作:

# ceph osd crush tree -f json-pretty

该命令返回类似如下的输出:

[
    {
        "id": -2,
        "name": "ssd",
        "type": "root",
        "type_id": 10,
        "items": [
            {
                "id": -6,
                "name": "dell-per630-11-ssd",
                "type": "host",
                "type_id": 1,
                "items": [
                    {
                        "id": 6,
                        "name": "osd.6",
                        "type": "osd",
                        "type_id": 0,
                        "crush_weight": 0.099991,
                        "depth": 2
                    }
                ]
            },
            {
                "id": -7,
                "name": "dell-per630-12-ssd",
                "type": "host",
                "type_id": 1,
                "items": [
                    {
                        "id": 7,
                        "name": "osd.7",
                        "type": "osd",
                        "type_id": 0,
                        "crush_weight": 0.099991,
                        "depth": 2
                    }
                ]
            },
            {
                "id": -8,
                "name": "dell-per630-13-ssd",
                "type": "host",
                "type_id": 1,
                "items": [
                    {
                        "id": 8,
                        "name": "osd.8",
                        "type": "osd",
                        "type_id": 0,
                        "crush_weight": 0.099991,
                        "depth": 2
                    }
                ]
            }
        ]
    },
    {
        "id": -1,
        "name": "default",
        "type": "root",
        "type_id": 10,
        "items": [
            {
                "id": -3,
                "name": "dell-per630-11",
                "type": "host",
                "type_id": 1,
                "items": [
                    {
                        "id": 0,
                        "name": "osd.0",
                        "type": "osd",
                        "type_id": 0,
                        "crush_weight": 0.449997,
                        "depth": 2
                    },
                    {
                        "id": 3,
                        "name": "osd.3",
                        "type": "osd",
                        "type_id": 0,
                        "crush_weight": 0.289993,
                        "depth": 2
                    }
                ]
            },
            {
                "id": -4,
                "name": "dell-per630-12",
                "type": "host",
                "type_id": 1,
                "items": [
                    {
                        "id": 1,
                        "name": "osd.1",
                        "type": "osd",
                        "type_id": 0,
                        "crush_weight": 0.449997,
                        "depth": 2
                    },
                    {
                        "id": 4,
                        "name": "osd.4",
                        "type": "osd",
                        "type_id": 0,
                        "crush_weight": 0.289993,
                        "depth": 2
                    }
                ]
            },
            {
                "id": -5,
                "name": "dell-per630-13",
                "type": "host",
                "type_id": 1,
                "items": [
                    {
                        "id": 2,
                        "name": "osd.2",
                        "type": "osd",
                        "type_id": 0,
                        "crush_weight": 0.449997,
                        "depth": 2
                    },
                    {
                        "id": 5,
                        "name": "osd.5",
                        "type": "osd",
                        "type_id": 0,
                        "crush_weight": 0.289993,
                        "depth": 2
                    }
                ]
            }
        ]
    }
]
注意

在 RHCS 3 和更高版本中,OSD 对象也将具有 device_class 属性。

2.3.2. 将 OSD 添加到 CRUSH

将 OSD 添加到 CRUSH 层次结构中是最后一步,然后您启动 OSD( 在 中进行渲染),Ceph 将 PG 分配到 OSD。

注意

在 RHCS 3 中,您可能还会添加一个设备类。

您必须先准备 OSD,然后才能将它添加到 CRUSH 层次结构中。部署实用程序(如 Ansible 自动化应用)为您执行这一步。如需了解更多详细信息,请参阅添加/删除 OSD。

CRUSH 层次结构是概念性的,因此 ceph osd crush add 命令允许您在您希望的任何位置添加 OSD 到 CRUSH 层次结构。您指定的位置 应反映 其实际位置。如果至少指定了一个 bucket,命令会将 OSD 放置到您指定的最具体的 bucket 中,它会 将 bucket 移到您指定的任何其他 bucket 的下方。

将 OSD 添加到 CRUSH 层次结构中:

ceph osd crush add {id-or-name} {weight}  [{bucket-type}={bucket-name} ...]
重要

如果您仅指定根 bucket,命令会将 OSD 直接附加到 root。但是,CRUSH 规则预期 OSD 在主机或机箱内,主机或机箱 应当 位于反映集群拓扑的其他 bucket 中。

以下示例在层次结构中添加 osd.0

ceph osd crush add osd.0 1.0 root=default datacenter=dc1 room=room1 row=foo rack=bar host=foo-bar-1
注意

您还可以使用 ceph osd crush set 或 ceph osd crush create-or-move 将 OSD 添加到 CRUSH 层次结构。

2.3.3. 在 CRUSH 层次结构中移动 OSD

如果部署实用程序(如 Ansible 自动化应用在更优的 CRUSH 位置添加了 OSD 到 CRUSH map),或者集群拓扑发生变化,则可以移动 CRUSH 层次结构中的 OSD 以反映其实际位置。

重要

在 CRUSH 层次结构中移动 OSD 意味着 Ceph 将重新计算将哪些 PG 分配到 OSD,可能会产生大量数据重新分发。

在 CRUSH 层次结构中移动 OSD:

ceph osd crush set {id-or-name} {weight} root={pool-name}  [{bucket-type}={bucket-name} ...]
注意

您还可以使用 ceph osd crush create-or-move 在 CRUSH 层次结构中移动 OSD。

2.3.4. 从 CRUSH 层次结构中删除 OSD

在您要从集群中删除 OSD 时,从 CRUSH 层次结构中删除 OSD 是第一步。当您从 CRUSH map 移除 OSD 时,CRUSH 会重新计算哪些 OSD 获取 PG,并相应地重新平衡数据。如需了解更多详细信息,请参阅添加/删除 OSD。

要从正在运行的集群的 CRUSH map 移除 OSD,请执行以下操作:

ceph osd crush remove {name}