# pool
# 创建池
- 创建副本池
root@Kylin:/sys# ceph osd pool create rbd_pool 1024 1024
pool 'rbd_pool' created
root@Kylin:/sys# ceph osd pool set rbd_pool size 3
set pool 9 size to 3
root@Kylin:/sys#
- 创建纠删池
root@Kylin:/sys# ceph osd erasure-code-profile set test_file k=2 m=1 plugin=jerasure ruleset-failure-domain=host technique=reed_sol_van
root@Kylin:/sys# ceph osd pool create bp_ec_pool 1024 1024 erasure test_file
pool 'bp_ec_pool' created
root@Kylin:/sys# ceph osd erasure-code-profile get test_file
directory=/usr/lib/ceph/erasure-code
k=2
m=1
plugin=jerasure
ruleset-failure-domain=host
technique=reed_sol_van
root@Kylin:/sys# ceph osd erasure-code-profile rm test_file
# 修改池
代码语言:javascript复制root@Kylin:/sys# ceph osd pool get testrbd size
size: 2
root@Kylin:/sys# ceph osd pool set testrbd size 3
set pool 5 size to 3
root@Kylin:/sys# ceph osd pool get testrbd size
size: 3
# 查看池
代码语言:javascript复制root@Kylin:/sys# ceph osd dump | grep pool
pool 1 'summer60sys000' replicated size 2 min_size 1 crush_ruleset 1 object_hash rjenkins pg_num 256 pgp_num 256 last_change 490 flags hashpspool crash_replay_interval 45 stripe_width 0
pool 3 'summer38-fec-691852341313819928811' erasure size 4 min_size 3 crush_ruleset 2 object_hash rjenkins pg_num 1024 pgp_num 1024 last_change 500 flags hashpspool stripe_width 12288
pool 5 'testrbd' replicated size 3 min_size 1 crush_ruleset 0 object_hash rjenkins pg_num 1024 pgp_num 1024 last_change 509 flags hashpspool stripe_width 0
root@Kylin:/sys# rados lspools
summer60sys000
summer38-fec-691852341313819928811
testrbd
root@Kylin:/sys# rados df
pool name KB objects clones degraded unfound rd rd KB wr wr KB
summer38-fec-691852341313819928811 63550735361 15515418 0 0 0 646239 18030316 16363738 63882405016
summer60sys000 61302 1535 0 0 0 298021 2242450 296434 2252475
testrbd 0 0 0 0 0 0 0 0 0
total used 86041904154 15516953
total avail 267288605958
total space 372084556416
root@Kylin:/sys# ceph osd pool ls
summer60sys000
summer38-fec-691852341313819928811
testrbd
root@Kylin:/sys# ceph osd lspools
1 summer60sys000,3 summer38-fec-691852341313819928811,5 testrbd,
# 压缩池
代码语言:javascript复制root@Kylin:/sys# ceph osd pool set testrbd compress true
set pool 5 compress to true
root@Kylin:/sys# ceph osd pool get testrbd compress
compress: true
root@Kylin:/sys#
# 加密池
代码语言:javascript复制root@Kylin:/sys# ceph osd pool set testrbd crypt true
set pool 5 crypt to true
root@Kylin:/sys# ceph osd pool get testrbd crypt
crypt: true
root@Kylin:/sys#
# 配额池
代码语言:javascript复制root@Kylin:/sys# ceph osd pool set-quota rbd_pool max_bytes 2097152000
set-quota max_bytes = 2097152000 for pool rbd_pool
root@Kylin:/sys# ceph osd pool get-quota rbd_pool
quotas for pool 'rbd_pool':
max objects: N/A
max bytes : 2000MB
# 删除池
代码语言:javascript复制root@Kylin:/sys# ceph osd pool delete test2rbd test2rbd --yes-i-really-really-mean-it
pool 'test2rbd' removed
# 块设备
# 创建快设备
代码语言:javascript复制root@Kylin:/sys# rbd create --size 10240 testrbd/creatrbd
root@Kylin:/sys# rbd -p testrbd ls
creatrbd
root@Kylin:/sys# rbd ls testrbd
creatrbd
# 扩容块设备
代码语言:javascript复制root@Kylin:/sys# rbd info testrbd/creatrbd
rbd image 'creatrbd':
size 10240 MB in 2560 objects
order 22 (4096 kB objects)
block_name_prefix: rbd_data.28d5f6b8b4567
format: 2
timestamp: 2021-05-13 09:27:32
features: layering
flags:
root@Kylin:/sys# rbd resize --size 20480 testrbd/creatrbd
Resizing image: 100% complete...done.
root@Kylin:/sys# rbd info testrbd/creatrbd
rbd image 'creatrbd':
size 20480 MB in 5120 objects
order 22 (4096 kB objects)
block_name_prefix: rbd_data.28d5f6b8b4567
format: 2
timestamp: 2021-05-13 09:27:32
features: layering
flags:
# 移动块设备
- 例子:将池
testrbd
中的块creatrbd
移动到池test2rbd
中
root@Kylin:/sys# rados lspools
summer60sys000
summer38-fec-691852341313819928811
testrbd
test2rbd
代码语言:javascript复制
root@Kylin:/sys# rbd ls testrbd
creatrbd
root@Kylin:/sys# rbd ls test2rbd
root@Kylin:/sys#
root@Kylin:/sys# rbd snap ls testrbd/creatrbd
SNAPID NAME SIZE
2 snapcreatrbd 20480 MB
代码语言:javascript复制
root@Kylin:/sys# rbd clone testrbd/creatrbd@snapcreatrbd test2rbd/creatrbd
2021-05-13 09:37:22.310112 ffff93209280 -1 librbd: parent snapshot must be protected
rbd: clone error: (22) Invalid argument
root@Kylin:/sys# rbd snap protect testrbd/creatrbd@snapcreatrbd
root@Kylin:/sys# rbd clone testrbd/creatrbd@snapcreatrbd test2rbd/creatrbd
root@Kylin:/sys# rbd ls testrbd
creatrbd
root@Kylin:/sys# rbd ls test2rbd
creatrbd
root@Kylin:/sys#
# 查看块设备
代码语言:javascript复制root@Kylin:/sys# rbd info testrbd/creatrbd
rbd image 'creatrbd':
size 20480 MB in 5120 objects
order 22 (4096 kB objects)
block_name_prefix: rbd_data.28d5f6b8b4567
format: 2
timestamp: 2021-05-13 09:27:32
features: layering
flags:
# 使用块设备
# map映射
# 映射rbd到本地客户端
代码语言:javascript复制root@Kylin:/sys# rbd map --image testrbd/creatrbd
/dev/cephrbd0
root@Kylin:/sys# rbd showmapped
id pool image snap device
0 testrbd creatrbd - /dev/cephrbd0
root@Kylin:/sys#
# 直接lsblk查看
代码语言:javascript复制root@Kylin:/sys# lsblk | grep cephrbd0
cephrbd0 252:0 0 20G 0 disk
# 格式化该设备
代码语言:javascript复制root@Kylin:/sys# mkfs.xfs /dev/cephrbd0
meta-data=/dev/cephrbd0 isize=512 agcount=17, agsize=326656 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=0
data = bsize=4096 blocks=5242880, imaxpct=25
= sunit=1024 swidth=1024 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=8 blks, lazy-count=1
realtime =无 extsz=4096 blocks=0, rtextents=0
# 挂载该设备
代码语言:javascript复制root@Kylin:/sys# mkdir /rbdtest
root@Kylin:/sys# mount /dev/cephrbd0 /rbdtest/
root@Kylin:/sys# df -h | grep rbd
/dev/cephrbd0 20G 33M 20G 1% /rbdtest
root@Kylin:/sys#
# 卸载并取消块设备映射
代码语言:javascript复制root@Kylin:/sys# umount -l /rbdtest/
root@Kylin:/sys# rbd unmap /dev/rbd/testrbd/creatrbd
root@Kylin:/sys# rbd showmapped
root@Kylin:/sys#
# iscsi映射
# 新建tgt
代码语言:javascript复制root@Kylin:/sys# tgtadm --lld iscsi --mode target --op new --tid 2 --targetname iqn.2021-05.com.919:192.168.88.105.sn.84736ec1e9db9037c6b1a32
root@Kylin:/sys# tgtadm -L iscsi -m target -o show | grep 'Target 2'
Target 2: iqn.2021-05.com.919:192.168.88.105.sn.84736ec1e9db9037c6b1a32
# 绑定rbd
代码语言:javascript复制root@Kylin:/sys# tgtadm -L iscsi -m logicalunit -o new -t 2 -l 1 -b testrbd/creatrbd --bstype rbd
# 授权所有
代码语言:javascript复制root@Kylin:/sys# tgtadm -L iscsi -m target -o bind -t 2 -I ALL
# 查看tgt
代码语言:javascript复制root@Kylin:/sys# tgtadm -L iscsi -m target -o show
...
Target 2: iqn.2021-05.com.919:192.168.88.105.sn.84736ec1e9db9037c6b1a32
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00020000
SCSI SN: beaf20
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00020001
SCSI SN: beaf21
Size: 21475 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: rbd
Backing store path: testrbd/creatrbd
Backing store flags:
Account information:
ACL information:
ALL
# 发现tgt
代码语言:javascript复制root in iscloud163-200 in ~ via