Ceph —— 均衡PG

Ceph —— 均衡PG

平常工做中,咱们经常会发现PG不均衡,而集群中只要有一个OSD先达到full的状态,则整个集群都没法写入数据,因此为了尽量的提升集群存储空间的利用率,咱们都但愿PG尽量的均匀分布在OSD上。python

出现PG不均衡最多见的背景状况:ui

  • 刚刚安装部署Ceph集群完毕spa

  • 集群扩容或是其余状况,进行了加盘的操做,OSD数量发生变化code

为了节省平常工做的时间,针对PG均衡问题,写了个python脚本:blog

version : ceph_luminous (12.2.2)文档

 1 #!/usr/bin/python
 2 
 3 import os
 4 
 5 
 6 def Ceph_balance():
 7     # Gets the PG number for each OSD
 8     PGS = os.popen(""" ceph osd df | awk '{print $10}' | egrep -v "^$|PGS" """).readlines()
 9     # Get the max difference of PG number
10     MAX_DIFFERENT_PG = max(map(eval, PGS)) - min(map(eval, PGS))
11     # Get pool list
12     lspools = os.popen('ceph osd lspools').read().split(',')[:-1]
13     POOL_LIST = map(lambda x: x[2:], lspools)
14     # To allow use of the feature, you must tell the cluster that it only needs to support luminous (and newer) clients with: 
15     os.system('ceph osd set-require-min-compat-client luminous')
16     if MAX_DIFFERENT_PG >= 1:
17         # Grab the latest copy of your osdmap
18         os.system('ceph osd getmap -o /tmp/osd.map')
19         for i in POOL_LIST:
20             # Run the optimizer
21             os.system('osdmaptool /tmp/osd.map --upmap /tmp/%sout.txt --upmap-pool %s' % (i, i))
22         for i in POOL_LIST:
23             # Apply the changes to the cluster
24             os.system('source /tmp/%sout.txt' % i)
25     # clean up txt file
26     for i in POOL_LIST:
27         os.system('rm -f /tmp/%sout.txt' % i)
28     os.system('rm -f /tmp/osd.map')
29     print("Ceph balance has been successful !")
30 
31 
32 if __name__ == '__main__':
33     Ceph_balance()

 


此脚本只适用于luminous及以上的版本部署

ps:因本人awk比较菜,因此这个脚本获取PGS部分没法达到准确应用。你们能够根据本身的状况酌情修改脚本。适合本身的才是最好的。get


参考文档:Ceph官方文档地址it

有何意见建议,能够留言,欢迎指正。io

以为写的不错,用着还能够的,能够点个推荐关注啥的。

相关文章
相关标签/搜索