其他分享
首页 > 其他分享> > ceph Crush map

ceph Crush map

作者:互联网

 

 

Crush map

CRUSH map采用树状结构,最小叶子节点就是真实物理磁盘称为device,中间节点称为bucket,每个bucket可以是device集合,也可以是低一级的bucket集合,最上面还有一个root节点,代表集群的入口

    CRUSH hierarchy(层次结构):树型结构目录,决定故障域的范围(11个层级)
    CRUSH rule(规则):CRUSH rule决定如何从bucket中分配OSD,创建存储池可以指定rule

 

CRUSH hierarchy

生成环境可以考虑这样的层级:数据中心-----机架-----主机-------磁盘(root–rack–host–osd)

root:根节点,整个集群的入口

 

 

 

默认Crush hierarchy

 

 

 

编辑Crush map

 

命令行编辑

配置文件替换

 

 

配置文件替换

ceph osd getcrushmap -o map.file
#导出集群的map配置,默认是二进制
crushtool -d map.file -o map.txt
#二进制反编译成文本文件,进行编辑
crushtool -c map.txt -o map.new
#文本编译成二进制文件
ceph osd setcrushmap -i map.new
#设置crush map

 

 

配置解释

 

    id(集群唯一数值标识):device使用正整数,而root和bucket都是使用负数
    weight:pg的分配取决于weigh值,跟容量正相关,权重值1 = 1TB,0.5=500G

 

定义bucket中间节点

 

    class:用于磁盘类型分类
    alg:将pg map到osd时的算法,默认使用straw2
    hash:每个bucket都有一个hash算法,目前Ceph支持rjenkins1算法,设为0即使用该算法
    item:一个bucket包含的其他bucket或者叶子

 

格式

 

[bucket-type] [bucket-name] {
id [a unique negative numeric ID]
weight [the relative capacity/capability of the item(s)]
alg [the bucket type: uniform | list | tree | straw ]
hash [the hash type: 0 by default]
item [item-name] weight [weight]
}

 

例子:

 

rack rack-02 {

        id -13           # do not change unnecessarily
        alg straw2
        hash 0  # rjenkins1
        item ceph1 weight 0.098
        item ceph3 weight 0.098

}

root default {
        id -1           # do not change unnecessarily
        id -4 class hdd         # do not change unnecessarily
        alg straw2
        hash 0  # rjenkins1
        item rack-02 weight 0.196
}

 

定义CRUSH rule

配置格式

rule <rulename> {
        type [ replicated | erasure ]
        min_size <min-size>
        max_size <max-size>
        step take <bucket-type> 
        step [choose|chooseleaf] [firstn|indep] <N> <bucket-type>
        step emit
    }

rule replicated_rule {
        id 0
        type replicated
        min_size 1
        max_size 3
        step take default
        step chooseleaf firstn 0 type rack
        step emit
}

 

如图:

 

 

 

复杂场景的一个应用

 

step take ssd << --从ssd根节点出发
        step chooseleaf firstn 1 type osd << --从ssd整个系统中选择一个OSD作为主OSD
        step emit << --输出选择,清除栈空间
        step take hdd << --重新从hdd根节点出发
        step chooseleaf firstn -1 type osd << --从hdd中选择处剩下的需要的OSD
        step emit

 

举例配置故障域
root–rack–host–osd

rack rack-01 {  #定义机柜层级

        id -11           # do not change unnecessarily
        # weight 0.391
        alg straw2
        hash 0  # rjenkins1
        item ceph2 weight 0.098
        item ceph4 weight 0.098
}
rack rack-02 {  #定义机柜层级

        id -13           # do not change unnecessarily
        # weight 0.391
        alg straw2
        hash 0  # rjenkins1
        item ceph1 weight 0.098
        item ceph3 weight 0.098
}
root default {   #默认root入口,修改项目为机柜级别定义的
        id -1           # do not change unnecessarily
        id -4 class hdd         # do not change unnecessarily
        # weight 0.391
        alg straw2
        hash 0  # rjenkins1
        item rack-01 weight 0.196
        item rack-02 weight 0.196
}
# rules
rule replicated_rule {
        id 0
        type replicated
        min_size 1
        max_size 3
        step take default
        step chooseleaf firstn 0 type rack   #修改故障域级别,默认为host
        step emit
}

 

如图:

 

 

参考:https://blog.csdn.net/yangshihuz/article/details/116261974

 

标签:Crush,weight,map,bucket,id,ceph,item,rack
来源: https://www.cnblogs.com/zhongguiyao/p/15759201.html