從GitHub上Clone Ceph項目,我是基於(ceph version 12.2.11 luminous 版本)的代碼來分析的
一、前言:
有很多場景,你需要在指定的 OSD 設備上創建 Ceph Pool。因爲Ceph集羣中允許使用混合類型的磁盤,比如一部分磁盤是NVME SSD,一部分是SATA HDD。如果針對某些業務需要高速磁盤SSD,而某些業務 HDD 就可以滿足部署,在創建資源池 Pool 的時候可以指定它創建在某些OSD 設備上。例如,Ceph 進階系列(三):談談 Ceph Cache Tier 的配置 、原理 和 源碼分析 裏的 Cache Pool。
二、如何讓某個 pool使用特定的OSD設備:
1. 在指定的 OSD 設備上創建 Pool 的方法概敘:
- 修改Ceph集羣的 crush map (可以導出crush map文件修改,然後導入生效)裏的 rule section,該rule 選擇哪個bucket路徑 (實際上就是最終選擇哪個osd device,root->host->osd device)
- 通過設定Pool的crush_ruleset 來指定該 Pool 使用crush map裏的哪個rule(命令:ceph osd pool set <poolname> crush_ruleset 4)
2. 純手工步驟分解(7步):
如下圖的Ceph集羣,osd.0和osd.1的物理介質爲 SSD, 而osd.2和osd.3的物理介質爲 HDD
~/tmp$ ceph osd tree
ID CLASS WEIGHT TYPE NAME STATUS REWEIGHT PRI-AFF
-1 0.06798 root default
-3 0.02899 host ubuntu
0 ssd 0.00999 osd.0 up 1.00000 1.00000
1 ssd 0.01900 osd.1 up 1.00000 1.00000
-5 0.03899 host ubuntu-sebre
2 hdd 0.01900 osd.2 up 1.00000 1.00000
3 hdd 0.01900 osd.3 up 1.00000 1.00000
1 從Ceph集羣裏導出crush map
命令:ceph osd getcrushmap -o {compiled-crushmap-filename}
~$ ceph osd getcrushmap -o ./tmp/crushmap.ori
2 反編譯crush map
命令:crushtool -d {compiled-crushmap-filename} -o {decompiled-crushmap-filename}
~/tmp$ crushtool -d crushmap.ori -o decrushmap.ori
3 修改crush map的#rules
我們可以看到導出來的crush map 如下,其中bucket host ubuntu包含了兩個osd devices(osd.0和osd.1),而host ubuntu-sebre包含了另兩個osd devices(osd.2和osd.3)。關於crush map的語法,可以參考:《ceph設計原理與實現》和 《ceph源碼分析》
# begin crush map
tunable choose_local_tries 0
tunable choose_local_fallback_tries 0
tunable choose_total_tries 50
tunable chooseleaf_descend_once 1
tunable chooseleaf_vary_r 1
tunable chooseleaf_stable 1
tunable straw_calc_version 1
tunable allowed_bucket_algs 54
# devices
device 0 osd.0 class ssd
device 1 osd.1 class ssd
device 2 osd.2 class hdd
device 3 osd.3 class hdd
# types
type 0 osd
type 1 host
type 2 chassis
type 3 rack
type 4 row
type 5 pdu
type 6 pod
type 7 room
type 8 datacenter
type 9 region
type 10 root
# buckets
host ubuntu {
id -3 # do not change unnecessarily
id -4 class ssd # do not change unnecessarily
# weight 0.029
alg straw2
hash 0 # rjenkins1
item osd.0 weight 0.010
item osd.1 weight 0.019
}
host ubuntu-sebre {
id -5 # do not change unnecessarily
id -6 class ssd # do not change unnecessarily
# weight 0.039
alg straw2
hash 0 # rjenkins1
item osd.2 weight 0.019
item osd.3 weight 0.019
}
root default {
id -1 # do not change unnecessarily
id -2 class ssd # do not change unnecessarily
# weight 0.068
alg straw2
hash 0 # rjenkins1
item ubuntu weight 0.029
item ubuntu-sebre weight 0.039
}
# rules
rule replicated_rule {
id 0
type replicated
min_size 1
max_size 10
step take default
step chooseleaf firstn 0 type host
step emit
}
所以我們可以在rules部分添加如下兩個rule 規則:rule ssd使用SSD的兩個OSD設備,而rule hdd可以使用HDD的兩個OSD設備
rule ssd{
id 1
type replicated
min_size 1
max_size 10
step take ubuntu
step chooseleaf firstn 0 type osd
step emit
}
rule hdd{
id 2
type replicated
min_size 1
max_size 10
step take ubuntu-sebre
step chooseleaf firstn 0 type osd
step emit
}
4 編譯crush map
命令:crushtool -c {decompiled-crushmap-filename} -o {compiled-crushmap-filename}
[root@ceph-admin getcrushmap]# crushtool -c decrushmap.new -o crushmap.new
5 導入自定義的 crush map 到Ceph 集羣
命令:ceph osd setcrushmap -i {compiled-crushmap-filename}
~/tmp$ ceph osd setcrushmap -i ./crushmap.new
10
查看導入後的crush map
$ ceph osd crush rule ls
replicated_rule
ssd
hdd
6 創建資源池pool
~/tmp$ ceph osd pool create ssd_pool 8 8
pool 'ssd_pool' created
~/tmp$ ceph osd pool create hdd_pool 8 8
pool 'hdd_pool' created
//查看剛創建好的Pool
~/tmp$ ceph osd dump|grep pool
pool 18 'ssd_pool' replicated size 3 min_size 2 crush_rule 0 object_hash rjenkins pg_num 8 pgp_num 8 last_change 196 flags hashpspool stripe_width 0
pool 19 'hdd_pool' replicated size 3 min_size 2 crush_rule 0 object_hash rjenkins pg_num 8 pgp_num 8 last_change 199 flags hashpspool stripe_width 0
注意:剛剛創建的兩個資源池ssd_pool 和stat_pool 的 crush_ruleset 都是0,下面需要修改。
7 修改資源池pool的存儲規則
# luminus 版本設置pool規則的語法:ceph osd pool set <pool name> crush_rule <rule name>
~/tmp$ ceph osd pool set ssd_pool crush_rule ssd
set pool 18 crush_rule to ssd
~/tmp$ ceph osd pool set hdd_pool crush_rule hdd
set pool 19 crush_rule to hdd
查看修改後,ssd_pool 和 hdd_pool的配置,如下,兩個pool已經變更爲對應的rule
~/tmp$ ceph osd dump|grep pool
pool 18 'ssd_pool' replicated size 3 min_size 2 crush_rule 1 object_hash rjenkins pg_num 8 pgp_num 8 last_change 203 flags hashpspool stripe_width 0
pool 19 'hdd_pool' replicated size 3 min_size 2 crush_rule 2 object_hash rjenkins pg_num 8 pgp_num 8 last_change 206 flags hashpspool stripe_width 0
設置pool的rule,更早版本的命令格式是:ceph osd pool set ssd_pool crush_ruleset 1
到此,這個Ceph集羣的OSD 使用規則就已經建立好了。sdd_pool 使用SSD OSD 類型的設備,而hdd_pool則使用HDD OSD 類型的設備。
三、測試Crush Map的rule 規則:
可以使用crushtool 來測試crush map 裏的各個 rule,命令格式爲:crushtool -i <compiled-crushmap-filename> --test --min-x <num> --max-x <num> --num-rep <num> --ruleset <num> --show_mappings
參數說明:
-i compiled-crushmap-filename:指定要操作的crushmap 文件,可以爲編譯好的/或者導出來的 crush map 文件
--test:該操作爲測試模式
--min-x: 該操作起始號
--max-x:該操作結束號
--num-rep: 副本數
--ruleset: 使用哪個rule
--show_mappings: 顯示使用的OSD 設備列表
如下,mapping顯示[0,1] 和 [1,0],說明 ruleset 1只使用了osd.0 和 osd.1
$ crushtool -i crushmap --test --min-x 3 --max-x 10 --num-rep 2 --ruleset 1 --show_mappings
CRUSH rule 1 x 3 [0,1]
CRUSH rule 1 x 4 [1,0]
CRUSH rule 1 x 5 [0,1]
CRUSH rule 1 x 6 [1,0]
CRUSH rule 1 x 7 [1,0]
CRUSH rule 1 x 8 [1,0]
CRUSH rule 1 x 9 [1,0]
CRUSH rule 1 x 10 [0,1]
後續:
而luminous版本的新特性因爲有磁盤智能分組功能,用戶只需要用命令創建一個新的rule就可以了,而不必手動編輯crush map文件)。請參考 Ceph 進階系列(二):如何讓某個 pool使用特定的OSD設備 (2 of 2,luminous新特性)
參考:
《ceph設計原理與實現》和 《ceph源碼分析》