CEPH RGW集羣和bucket的zone group 不一致致使的404異常解決 及 使用radosgw-admin metadata 命令設置bucket metadata 的方法

 

問題現象: 最近在研究zonegroup的配置操做,發如今配置zonegroup後修改了default zone,致使訪問對象報404錯誤。python

問題緣由:git

rgw 日誌 報異常’request for data in a different zonegroup ’github

 

rgw源碼:json

https://github.com/ceph/ceph/blob/d346b1b83597644b4ce58bae4bc14629f69ef667/src/rgw/rgw_op.cc工具

 

結論: bucket的zonegroup字段和集羣新的id不一致。spa

 

 

解決方案: 使集羣和bucket的zone group 一致。3d

1.  舊的zonegroup還存在的狀況下,設置default zone group 爲舊的 default。 日誌

2.  的zonegroup 刪除的狀況, 設置 dubbucket的zonegroup字段爲新的zonegroup id。 能夠使用以下工具批量設置bucket metadata ;注意要重啓rgw 服務進程code

主要配置命令:對象

radosgw-admin metadata get bucket:qtest3
radosgw-admin metadata get bucket.instance:qtest3:3d240698-79c4-4af0-abab-6b83b340a538.33547209.1 > conf.json
radosgw-admin metadata put bucket.instance:qtest3:3d240698-79c4-4af0-abab-6b83b340a538.33547209.1 < conf.json

 

 

cat set_bucket_meta.py 
#!/usr/bin/env python

import rados
import os
import json
import copy
import subprocess
import sys

ceph_rgw_pool = ".rgw"

def change_bucket_zonegroup(bucket, zgp):
        print("radosgw-admin metadata get bucket:" + bucket)
    me = os.popen("radosgw-admin metadata get bucket:" + bucket)
    meta = json.loads(me.read())
    id = meta['data']['bucket']['bucket_id']
        print("radosgw-admin metadata get bucket.instance:" + bucket + ":" + id)
    mei = os.popen("radosgw-admin metadata get bucket.instance:" + bucket + ":" + id)
    imeta = json.loads(mei.read())
    newmeta = copy.copy(imeta)
    newmeta['data']['bucket_info']['zonegroup'] = zgp
    stdin = json.dumps(newmeta)
        print("radosgw-admin metadata put bucket.instance:" + bucket + ":" + id)
    process = subprocess.Popen(['radosgw-admin', 'metadata', 'put', "bucket.instance:" + bucket + ":" + id], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    process.stdin.write(stdin)
    process.stdin.close()
    process.wait()

def get_all_buckets():
    me = os.popen("radosgw-admin bucket list");
        return json.loads(me.read())
if __name__ == '__main__':
    if sys.argv[1] == 'all':
        for bk in get_all_buckets():
                        #print(bk)
            change_bucket_zonegroup(bk, sys.argv[2])
        #change_bucket_zonegroup('ivanwa','9affcd3e-c66c-48e4-b961-3a43a289268f')
    else:
        change_bucket_zonegroup(sys.argv[1],sys.argv[2])

#設置全部 bucket zone_group id
sudo python set_bucket_meta.py  all 833a4781-0da0-4810-8f0c-4e6e00b15a1e

#設置名爲test 的bucket zone_group id
sudo python set_bucket_meta.py  test 833a4781-0da0-4810-8f0c-4e6e00b15a1e

 參考:https://blog.widodh.nl/2013/11/changing-the-region-of-a-rgw-bucket/

相關文章
相關標籤/搜索