Ceph 数据重均衡的几种方法
在集群刚建好的时候,对pool进行调整,调整的方法就是对osd进行reweight,通过多次的reweight,指定的pool在osd上能大致得到比较好的均衡效果,但是后续仍会遇到osd上数据不均衡的情况。
常规操作
当ceph集群出现 osd full的告警时,一般情况下我们先通过ceph osd df查看osd的利用率及权重等信息。
如果我们看到看到有不均衡的数据后,一般会将利用率高osd的权重调低,等待完成数据均衡后重新调回正常权重。
ceph osd reweight 1 0.8
如果调完权重peering后发现recovery卡住或者直接提高osd写入阈值的情况下,会调整osd full ratio的阈值保持能够写入
ceph tell mon.* injectargs "--mon-osd-full-ratio 0.96" //默认0.95
ceph tell osd.* injectargs "--mon-osd-full-ratio 0.96"
ceph osd unpause
方法一:Upmap 操作
从12.2.x版本开始,ceph官方推出osdmaptool工具,这个工具允许我们对指定的osdmap进行运算,再使用ceph osd pg-upmap-items命令可实现单个pg级别的手动迁移,也就意味我们可以指定pg可以分布在哪些pg上,这点人为改变pg分布在一定程度上可以说是违背了crush算法的本意
upmap introduction:
Starting in Luminous v12.2.z there is a new pg-upmap exception table in the OSDMap that allows the cluster to explicitly map specific PGs to specific OSDs. This allows the cluster to fine-tune the data distribution to, in most cases, perfectly distributed PGs across OSDs. The key caveat to this new mechanism is that it requires that all clients understand the new pg-upmap structure in the OSDMap.
Starting in Luminous v12.2.z there is a new pg-upmap exception table in the OSDMap that allows the cluster to explicitly map specific PGs to specific OSDs. This allows the cluster to fine-tune the data distribution to, in most cases, perfectly distributed PGs across OSDs. The key caveat to this new mechanism is that it requires that all clients understand the new pg-upmap structure in the OSDMap.
upmap可以人为的指定pg分布,但是,需要客户端能够识别新的pg-upmap的结构,因为跟使用crush算法直接计算得出pg分布不同,人为修改了pg的位置后,就不能单单通过算法的到移动后的pg的位置了,必须提出新的结构
下边是实践,根据要求,使用upmap的前提条件有两个,第一是ceph版本必须是12.2.x及后续版本,第二是ceph的client特性至少要支持到luminous,才能保证client能够解读pg-upmap的新结构
首先,我们先导出集群的osdmap
ceph osd getmap -o osdmap
可以查看哦算得上pg的分布情况:
[root@~]$ osdmaptool --test-map-pgs --pool 5 ./osdmap
osdmaptool: osdmap file './thisosdmap'
pool 5 pg_num 1024
#osd count first primary c wt wt
osd.0 95 36 36 5.45749 1
osd.1 108 37 37 5.45749 1
osd.2 114 34 34 5.45749 1
osd.3 95 25 25 5.45749 1
......
in 30
avg 102 stddev 10.6927 (0.10483x) (expected 9.9492 0.0975412x))
min osd.6 83
max osd.18 118
size 0 0
size 1 0
size 2 0
size 3 1024
导出的信息可知,我们最大的osd pg是有较大差值的,然后需要对这个pool进行一轮pg迁移的计算,但首先这个unmap只对ceph 12.2.x及后续版本,我们就用下面的命令指定client的最低版本要求