pool是ceph存儲數據時的邏輯分區,它起到namespace的作用。其他分布式存儲系統,比如Mogilefs、Couchbase、Swift都有pool的概念,只是叫法不同。每個pool包含一定數量的PG,PG里的對象被映射到不同的OSD上,因此pool是分布到整個集群的。
除了隔離數據,我們也可以分別對不同的POOL設置不同的優化策略,比如副本數、數據清洗次數、數據塊及對象大小等。
查看POOL
查看pool有多種方式:
[root@mon1 ~]# rados lspools
rbd
testpool
testpool2
[root@mon1 ~]# ceph osd lspools 0 rbd,1 testpool,2 testpool2,
[root@mon1 ~]# ceph osd dump |grep pool pool 0 'rbd' replicated size 3 min_size 2 crush_ruleset 0 object_hash rjenkins pg_num 64 pgp_num 64 last_change 1 flags hashpspool stripe_width 0 pool 1 'testpool' replicated size 2 min_size 2 crush_ruleset 0 object_hash rjenkins pg_num 128 pgp_num 128 last_change 20 flags hashpspool stripe_width 0 pool 2 'testpool2' replicated size 2 min_size 2 crush_ruleset 0 object_hash rjenkins pg_num 128 pgp_num 128 last_change 22 flags hashpspool crash_replay_interval 45 stripe_width 0 [root@mon1 ~]#
毫無疑問ceph osd dump輸出的信息最詳盡,包括pool ID、副本數量、CRUSH規則集、PG和PGP數量等
創建POOL
通常在創建pool之前,需要覆蓋默認的pg_num
,官方推薦:
- 若少於5個OSD, 設置pg_num為128。
- 5~10個OSD,設置pg_num為512。
- 10~50個OSD,設置pg_num為4096。
- 超過50個OSD,可以參考pgcalc計算。
[root@mon1 ~]# ceph osd pool create pool1 64 pool 'pool1' created [root@mon1 ~]#
創建pool時要設置pg_num
調整POOL副本
[root@mon1 ~]# ceph osd pool set pool1 size 2 set pool 3 size to 2 [root@mon1 ~]#
刪除POOL
[root@mon1 ~]# ceph osd pool delete pool1 Error EPERM: WARNING: this will *PERMANENTLY DESTROY* all data stored in pool pool1. If you are *ABSOLUTELY CERTAIN* that is what you want, pass the pool name *twice*, followed by --yes-i-really-really-mean-it. [root@mon1 ~]# ceph osd pool delete pool1 pool1 --yes-i-really-really-mean-it pool 'pool1' removed
note:刪除pool時,pool名字要輸入兩次同時要加入--yes-i-really-really-mean-it參數
設置POOL配額
[root@mon1 ~]# ceph osd pool set-quota pool1 max_objects 100 #最大100個對象 set-quota max_objects = 100 for pool pool1 [root@mon1 ~]# ceph osd pool set-quota pool1 max_bytes $((10 * 1024 * 1024 * 1024)) #容量大小最大為10G set-quota max_bytes = 10737418240 for pool pool1
重命名POOL
[root@mon1 ~]# ceph osd pool rename pool1 pool2 pool 'pool1' renamed to 'pool2' [root@mon1 ~]#
查看POOL狀態信息
[root@mon1 ~]# rados df pool name KB objects clones degraded unfound rd rd KB wr wr KB pool2 0 0 0 0 0 0 0 0 0 rbd 0 0 0 0 0 0 0 0 0 testpool 0 0 0 0 0 0 0 0 0 testpool2 0 0 0 0 0 0 0 0 0 total used 118152 0 total avail 47033916 total space 47152068 [root@mon1 ~]#
創建快照
ceph支持對整個pool創建快照(和Openstack Cinder一致性組區別?),作用於這個pool的所有對象。但注意ceph有兩種pool模式:
- Pool Snapshot,我們即將使用的模式。創建一個新的pool時,默認也是這種模式。
- Self Managed Snapsoht,用戶管理的snapshot,這個用戶指的是librbd,也就是說,如果在pool創建了rbd實例就自動轉化為這種模式。
這兩種模式是相互排斥,只能使用其中一個。因此,如果pool中曾經創建了rbd對象(即使當前刪除了所有的image實例)就不能再對這個pool做快照了。反之,如果對一個pool做了快照,就不能創建rbd image了。
[root@mon1 ~]# ceph osd pool mksnap pool2 pool2_snap
created pool pool2 snap pool2_snap
[root@mon1 ~]#
刪除快照
[root@mon1 ~]# ceph osd pool rmsnap #remove snapshot <snap> from <pool> [root@mon1 ~]# ceph osd pool rmsnap pool2 pool2_snap removed pool pool2 snap pool2_snap [root@mon1 ~]#