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

以爲寫的不錯,用着還能夠的,能夠點個推薦關注啥的。

相關文章
相關標籤/搜索