Ceph - balanced PG

Ceph - balanced PG

Daily work, we often find that PG is not balanced, and the cluster as long as there is a state full OSD is reached first, the entire cluster can not write, so in order to improve the utilization of clustered storage space as much as possible, we want PG distributed as evenly as possible on the OSD.

PG appears unbalanced most common background:

  • Just install the deployment is completed Ceph cluster

  • Cluster expansion or any other case, the operation of the disk plus the number of OSD changes

In order to save time daily work for PG equilibrium problem, I wrote a python script:

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()

 


This script is only available in luminous and above versions

ps: because I awk more vegetables, so this part of the script gets PGS can not achieve accurate application. You can modify the script as appropriate according to their own situation. What suits you is the best.


What opinions and suggestions, you can leave a message, please correct me.

I feel well written, with a can, you can point a recommendation concerned about her.

Guess you like

Origin www.cnblogs.com/shu-sheng/p/12149807.html