-1 0 root default
-3 94.53119 host node1
0 hdd 5.37108 osd.0 up 1.00000 1.00000
1 hdd 5.37108 osd.1 up 1.00000 1.00000
2 hdd 5.37108 osd.2 up 1.00000 1.00000
3 hdd 5.37108 osd.3 up 1.00000 1.00000
4 hdd 1.75781 osd.4 up 1.00000 1.00000
5 hdd 7.12891 osd.5 up 1.00000 1.00000
6 hdd 7.12891 osd.6 up 1.00000 1.00000
7 hdd 7.12891 osd.7 up 1.00000 1.00000
8 hdd 7.12891 osd.8 up 1.00000 1.00000
9 hdd 7.12891 osd.9 up 1.00000 1.00000
10 hdd 7.12891 osd.10 up 1.00000 1.00000
11 hdd 7.12891 osd.11 up 1.00000 1.00000
12 hdd 7.12891 osd.12 up 1.00000 1.00000
13 hdd 7.12891 osd.13 up 1.00000 1.00000
14 hdd 7.12891 osd.14 up 1.00000 1.00000
建立根和crush 規則
-
取出兩個osd 并重新指定osd的根,友善檢視
ceph osd crush add osd.0 5.37108 host=test_rep_pool_1 root=test_rep
ceph osd crush add osd.1 5.37108 host=test_rep_pool_2 root=test_rep
ID CLASS WEIGHT TYPE NAME STATUS REWEIGHT PRI-AFF
-16 10.74216 root test_rep
-15 5.37108 host test_rep_pool_1
0 hdd 5.37108 osd.0 up 1.00000 1.00000
-19 5.37108 host test_rep_pool_2
1 hdd 5.37108 osd.1 up 1.00000 1.00000
建立crush規則并指定根
ceph osd crush rule create-simple test_rep_rule test_rep host firstn
該指令中 test_rep_rule
為要建立的crush rule的名稱, test_rep
為該rule指定的根名稱,即上一步建立的root命稱 test_rep
建立資源池
-
建立資源池并指定根
建立名稱為ceph osd pool create test_rep_pool 128 128 test_rep_rule
的資源池,pg數目為128,pgp數目為128,指定的crush規則為test_rep_pool
test_rep_rule
-
檢視建立後的資源池詳細資訊
ceph osd pool ls detail
pool 2 'test_rep_pool' replicated size 3 min_size 2 crush_rule 2 object_hash rjenkins pg_num 128 pgp_num 128 last_change 98 flags hashpspool stripe_width 0
- 檢視該存儲池使用的crush 規則資訊
[root@node1 ~]# ceph osd crush rule dump test_rep_rule
`{
"rule_id": 2, #目前規則的編号
"rule_name": "test_rep_rule", #目前規則名稱
"ruleset": 2, #目前規則所屬的規則集,
"type": 1, #一個字元串值,指定存儲池類型是副本還是糾删嗎,1 則為副本,3則為糾删碼
"min_size": 1,#如果存儲池副本數小于該值,則crush不會為該存儲池使用該規則
"max_size": 10,#如果存儲池副本數大于該值,則crush不會為該存儲池使用該規則,即副本池目前支援的最大副本數為10副本,再大就會報異常
"steps": [
{
"op": "take",
"item": -16,
"item_name": "test_rep"
},
{
"op": "chooseleaf_firstn",
"num": 0,
"type": "host"
},
{
"op": "emit"
}
]
}
修改crush規則
-
從目前節點的mon擷取CURSH map(如果在叢集中,可以在任何一個節點擷取)
該指令會在目前目錄下生成一個名叫ceph osd getcrushmap -o crush_map_file
的檔案,名稱可以自己去更改crush_map_file
[root@node1 ~]# ceph osd getcrushmap -o crush_map_test
41
[root@node1 ~]# ll crush_map_test
-rw-r--r-- 1 root root 2337 May 4 15:45 crush_map_test
crushtool
工具反編譯以上檔案,使其成為我們能夠閱讀的格式
crushtool -d crush_map_test -o crush_map_test_decompiel
[root@node1 ~]# crushtool -d crush_map_test -o crush_map_test_decompiel
[root@node1 ~]# ll crush_map_*
-rw-r--r-- 1 root root 2337 May 4 15:45 crush_map_test
-rw-r--r-- 1 root root 3658 May 4 15:48 crush_map_test_decompiel
- 對
檔案進行編輯修改crush_map_test_decompiel
#可以看到在begin crush map和end crush map之間有很對crush map相關的資訊,我們隻修改部分我們自己的資訊
#begin crush map
...
rule test_rep_rule {
id 2
type replicated
min_size 1
max_size 5 #修改該max_size 為5
step take test_rep
step chooseleaf firstn 0 type host
step emit
}
-
修改完成後需要重新編譯修改後的crush map檔案為新的檔案
crushtool -c crush_map_test_decompiel -o crush_new_map
- 将修改後的
crush_new_map
注入到原ceph叢集中
ceph osd setcrushmap -i crush_new_map
- 重新檢視修改後的crush規則
[root@node1 ~]# ceph osd crush rule dump test_rep_rule
{
"rule_id": 2,
"rule_name": "test_rep_rule",
"ruleset": 2,
"type": 1,
"min_size": 1,
"max_size": 5, #最大的副本數已經變為5
"steps": [
{
"op": "take",
"item": -16,
"item_name": "test_rep"
},
{
"op": "chooseleaf_firstn",
"num": 0,
"type": "host"
},
{
"op": "emit"
}
]
}