Ceph安裝步驟1完成之後,即可進行該步驟的操作。
本文中以對sas池進行操作爲例。
一、創建Ceph Pool 。
1. 計算每個池所需要的PG數目。
在創建池之前,首先需要計算PG數目(簡單來說,PG就是負責管理對象都存儲在哪些OSD上)。計算公式如下:
PG 數目= (OSD數目 x 100) / 副本數(如果是糾刪碼池,則除以k與m的和),計算的結果取大於這個值並且最接近的2的冪。(例如,如果計算得到PG數目爲600,則設置的Pool的PG數目應爲1024)。
如果在同樣的一些OSD上要創建多個池,則每個池的PG數目需要再除以池的數量。
2.創建Pool。
2.1 創建池的命令如下:
ceph osd pool create <pool> <pgnumber> <pgpnumber>
其中pgpnumber=pgnumber,pgnumber即爲上一步得到的PG數目。
此命令創建的池爲副本池,並且默認爲三副本池。
2.2 如果想要修改副本數量,比如將三副本改爲二副本,則使用以下命令(Ceph要求副本數或k+m的和必須小於等於OSD數目):
ceph osd pool set sas size 2
2.3 如果想要查看某一個池的副本數量,則使用以下命令:
ceph osd pool get sas size
2.4 如果想要創建一個糾刪碼池,則使用以下命令:
首先創建一個糾刪碼規則,設置K、M值(此處創建一個名爲abc的規則,k=2,m=1),糾刪碼規則可同時創建多個,
ceph osd erasure-code-profile set abc k=2 m=1 runleset-failure-domain=host
然後創建糾刪碼池:
ceph osd pool create sas 256 256 erasure abc
二、刪除池。
在創建池後,由於種種原因,可能需要將池刪掉,刪除池使用以下命令:
ceph osd pool delete sas sas --yes-i-really-really-mean-it
三、配置Crush Map。
通過配置Crush Map,使得Pool知道自己可以使用哪些OSD。
首先,通過以下命令創建Crush Map :
ceph osd getcrushmap -o raw_map
crushtool -d raw_map -o decode_map
創建完成後,打開Crush Map, Crush Map中包含以下幾部分內容:
1. 生成Crush Map時,自動生成的三部分:
(1)tunable
# 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
(2) device
# devices
device 0 osd.0 class hdd
device 1 osd.1 class hdd
device 2 osd.2 class ssd
device 3 osd.3 class hdd
device 4 osd.4 class hdd
device 5 osd.5 class ssd
device 6 osd.6 class hdd
device 7 osd.7 class hdd
device 8 osd.8 class ssd
(3) type
# 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
2. 需要手動編輯的部分
(1)host
# buckets
host ceph-admin {
id -1 # do not change unnecessarily
id -2 class hdd # do not change unnecessarily
id -3 class ssd # do not change unnecessarily
# weight 0.038
alg straw2
hash 0 # rjenkins1
item osd.0 weight 0.019
item osd.1 weight 0.019
}
其中,
ceph-admin爲配置的主機名,每一臺主機都需要配置這個部分。
id 爲負整數,只需要保證每個id都不同即可。
id -2 class hdd 和id -3 class ssd 表明該host節點包含ssd和hdd兩種硬盤。
alg straw2和hash 0與數據平衡分配有關。
item osd.0 weight 0.019 表明該host節點包含osd.0這一磁盤,並且磁盤容量爲0.019T。
(2)root
root sas {
id -9 # do not change unnecessarily
id -1 class hdd # do not change unnecessarily
id -23 class ssd # do not change unnecessarily
# weight 0.114
alg straw2
hash 0 # rjenkins1
item ceph-admin weight 0.038
item ceph-1 weight 0.038
item ceph-2 weight 0.038
}
root需要包含需要建池的所管理的所有host節點,並且表明節點總容量大小。
(3)rule
# rules
rule sas {
id 1
type [replicated | erasure ]
min_size <min-size>
max_size <max-size>
step set_chooseleaf_tries 5
step set_choose_tries 100
step take sas
step choose indep 0 type osd
step emit
}
至此,Crush Map配置完成,然後,通過以下命令使Crush Map的配置生效。
crushtool -c decode_map -o crush_map
ceph osd setcrushmap -i crush_map
ceph osd pool set sas crush_rule sas
至此,Ceph Pool配置完成。