mgr balancer模式探索及配置方法

一、简介

Mgr提供了很多有用的模块,可以通过ceph mgr module ls命令进行查询,其中enabled_modules表示已经使能的,而disabled_modules表示未使能的模块,使能一个模块可以使用ceph mgr module enable $module_name命令,本文主要介绍其中一个模块:balancer。

balancer模块用于平衡pg到osd的分布,从而平均osd的使用率。它支持两种模式:upmap和crush-compat,upmap会强制重新映射特定pg,而crush-compat通过改变crush weight来调整pg分布,最终实现数据均衡。
同时balancer支持手动触发pg平衡动作,或者以自动模式定期执行。

二、模式

upmap模式:

Upmap是Luminous版本新增功能,实现以pg单位重新映射特定的pg到特定的osd,实现方法是将更新的pg映射关系添加到osdmap中,以此实现对PG映射的细粒度控制,使用upmap模式的前提是集群中的所有服务以及客户端都要升级到Luminous版本,即对于客户端来说,要能够理解osdmap中的pg-upmap-items表。可以通过ceph features命令查看当前集群版本,同时要使用ceph osd set-require-min-compat-client luminous进行设置。

可以通过osdmaptool工具来生成优化结果,官方文档建议针对每个pool进行pg均衡,当对所有pool执行了优化后,实际上就达成了集群均衡,默认的误差允许范围是1%。

相关命令:

ceph osd getmap -o om  #获取osdmap
osdmaptool om --upmap out.txt [--upmap-pool <pool>] [--upmap-max <max-count>] [--upmap-deviation <max-deviation>]  #对指定pool生成优化结果

结果为多条可以执行的记录:

ceph osd rm-pg-upmap-items 37.fe5
ceph osd pg-upmap-items 37.0 7 4
ceph osd pg-upmap-items 37.4 1 3

执行这些命令时,就发生了pg的重新映射以及相应pg的数据迁移。
同时osdmap中也会同步增加相应的记录,用于显示标记pg映射关系。

ceph osd dump:
epoch 2116
fsid 8fc7c303-4db5-46ca-af1f-053c97ebcb88
created 2018-08-27 11:46:56.181084
...
pool 10 'default.rgw.intent-log' replicated size 3 min_size 1 crush_rule 2 object_hash rjenkins pg_num 32 pgp_num 32 last_change 1571 flags hashpspool stripe_width 0
...
ceph osd rm-pg-upmap-items 37.fe5
ceph osd pg-upmap-items 37.0 7 4
ceph osd pg-upmap-items 37.4 1 3

crush-compat模式:

Crush-compat模式在Luminous版本引入,实现原理是通过更改crush weigth来实现pg的均衡,这种模式兼容于较老的客户端。通过python实现的balancer计算得分(计算过程可以参考mgr调研文档),得出需要reweight的osd条目。

ceph osd crush weight-set reweight-compat 0 1.002479
ceph osd crush weight-set reweight-compat 1 0.998962
ceph osd crush weight-set reweight-compat 2 1.027126

执行命令的数据迁移过程,相应pg会处于active+remapped+backfill状态,pg重新映射且数据回填之中,内部osd之间数据的读写过程,并不会影响客户端的读写操作。

三、配置

  • 1、手动模式:
    #使能模块
    ceph mgr module enable balancer
    #查看状态
    ceph balancer status
    #计算当前集群得分
    ceph balancer eval
    #选择模式
    ceph balancer mode <upmap/crush-compat/none>
    #创建计划
    ceph balancer optimize <plan_name>
    #查看该计划执行后的集群得分
    ceph balancer eval <plan_name>
    #查看该计划要执行的动作
    ceph balancer show <plan_name>
    #执行计划
    ceph balancer execute <plan_name>
    #删除计划
    ceph balancer rm <plan_name>,或者全部清空ceph balancer reset

  • 2、自动执行:
    #开启自动执行模式
    ceph balancer on
    开启之后,系统默认每隔60s会计算一次集群得分,如果有更优分,则执行pg均衡动作。

  • 3、相关配置修改:
    #查看balancer相关配置项

ceph config-key dump
{
"mgr/balancer/active": "1",
 "mgr/balancer/mode": "crush-compat",
"mgr/balancer/sleep_interval": "100",
“mgr/balancer/begin_time”:”0000”,
“mgr/balancer/end _time”:”2400”,
}

参数解释:
mgr/balancer/active:自动周期执行
mgr/balancer/mode:模式
#当前时间在begin_time和end_time范围内才会执行,格式为小时/分钟,可以设定后在指定的时间段内才执行均衡动作;
mgr/balancer/begin_time,
mgr/balancer/end _time
mgr/balancer/sleep_interval,在配置的时间段执行的频率

#修改配置方法:
ceph config-key set
例如:
ceph config-key set “mgr/balancer/sleep_interval” “30”
修改后重启mgr生效。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值