Ceph的數(shù)據(jù)分布是由CRUSH Map解決定的,而CRUSH算法是偽HASH的,所以在一定時間內(nèi),數(shù)據(jù)會存在傾斜,這就需要我們用腳本來進(jìn)行定期的reweight:

專注于為中小企業(yè)提供成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)堯都免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
#authorjesse.js.lyu@gmail.com
#reweight for ceph osds
import hashlib
import commands
import threading
import sys
from time import ctime,sleep
import urllib2
import json
def doReweight(osdMaxUtilId, osdTargetReweight):
print 'ceph osd reweight ' + str(osdMaxUtilId) + ' ' + str(osdTargetReweight)
(status,output) = commands.getstatusoutput('ceph osd reweight '+ str(osdMaxUtilId) +' ' + str(osdTargetReweight))
print status,output
def canOSDReweight():
#
canDoReweight = False
pgStateIsOk = False
osdUtilDiffEnough = False
#determine pg status
(status,output) = commands.getstatusoutput('ceph -s --format=json-pretty')
pgMapJson = json.loads(output)
#print pgMapJson['pgmap']['pgs_by_state']
numPGS = pgMapJson['pgmap']['num_pgs']
for pgState in pgMapJson['pgmap']['pgs_by_state']:
if pgState['state_name'] == 'active+clean' and pgState['count'] == numPGS:
pgStateIsOk = True
if pgStateIsOk == False:
print "pg is reweighting or can't do reweight right now...."
exit
#determine OSD util diff
(status,output) = commands.getstatusoutput('ceph osd df --format=json-pretty')
#print status,output
osdMaxUtil=0
osdMaxUtilId=-1
osdMaxReweight=1
osdMinUtil=100
osdMinUtilId=-1
osdReweightStep=0.01
if status == 0:
osdDictJson = json.loads(output)
for node in osdDictJson['nodes']:
if node['utilization'] > osdMaxUtil:
osdMaxUtilId = node['id']
osdMaxUtil = node['utilization']
osdMaxReweight = node['reweight']
if node['utilization'] < osdMinUtil:
osdMinUtilId = node['id']
osdMinUtil = node['utilization']
osdTargetReweight = osdMaxReweight - osdReweightStep
osdUtilDiff = (osdMaxUtil - osdMinUtil)/osdMinUtil*100
if osdUtilDiff > 10:
osdUtilDiffEnough = True
print "Max and Min OSD's utilization diff is " + str(osdUtilDiff)
else:
print "Max and Min OSD's utilization diff is " + str(osdUtilDiff) + ",less then 10%, give up..."
exit
if pgStateIsOk == True and osdUtilDiffEnough == True and osdTargetReweight > 0:
print "================ doing reweight ==============="
print osdMaxUtilId,osdMaxUtil,osdMaxReweight
print osdMinUtilId,osdMinUtil
doReweight(osdMaxUtilId, osdTargetReweight)
def invokeOSDReweight():
while True:
sleep(30)
canOSDReweight()
if __name__ == '__main__':
invokeOSDReweight()
名稱欄目:Ceph自動reweight腳本
轉(zhuǎn)載源于:http://www.chinadenli.net/article26/igpejg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣、網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、虛擬主機(jī)、Google、微信公眾號
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)