ceph rbd 块命令 块扩容 创建快照 rbd分层 rbd快照克隆 可写快照 rbd 导入导出,池、块、快照命令

1. 块命令基础

# ceph osd pool create testrbd 128
# ceph osd dump |grep -i size
# rbd -p testrbd create test_image --size 1024
# rbd -p testrbd ls
# rbd -p testrbd --image test_image info
# rbd -p testrbd --image test_image resize --size 2048
# rbd -p testrbd --image test_image info
# rbd -p testrbd --image test_image resize --size 4096
# rbd -p testrbd --image test_image info
# rbd -p testrbd --image test_image resize --size 1024 --allow-shrink
# rbd -p testrbd --image test_image info
或者
# rbd info poolcopy2/rbdimage2

#rbd create rbdtest --size 1024 新建
# rbd rm rbdtest        删除

# rbd map -p testrbd test_image   映射到本地
# rbd showmapped         查看映射
# rbd unmap aa          接触映射
# rbd rm aa         删除

# lsblk
# rbd showmapped
# mkfs.ext4 /dev/rbd0
# mkdir /rbdtest
# mount /dev/rbd0 /rbdtest/
1.1 块 rbd 简化命令
1,查看存储池
# rados lspools
2,创建存储池
# rados mkpool pooltest
successfully created pool pooltest
3,在指定存储池创建RBD
# rbd create pooltest/imagerbd --size 1023 --image-format 2 --order 24
4,查看存储池块列表
# rbd ls pooltest
5,查看存储池块信息
# rbd info pooltest/imagerbd
rbd image 'imagerbd':
    size 1023 MB in 64 objects
    order 24 (16384 kB objects)
    block_name_prefix: rbd_data.67a6d6b8b4567
    format: 2
    features: layering
    flags: 
6,删除image
# rbd rm pooltest/imagerbd
Removing image: 100% complete...done.
# rbd ls pooltest 

7.RBD映射到本地,格式化,挂载使用
# rbd ls poolcopy2
luncopy2
rbdimage1
rbdimage2

# rbd map poolcopy2/rbdimage1
/dev/rbd1
# mkfs.ext4 /dev/rbd1
# mount /dev/rbd1 /mnt/localrbdimage1/

# df -Th
/dev/rbd1                          ext4      2.0G  6.0M  1.8G   1% /mnt/localrbdimage1
1.2 创建指定条带大小的rbd
# rbd create poolcopy2/rbd16Mimage --size 10240 --image-format 2 --order 24
# rbd -p poolcopy2 --image rbd16Mimage info  或者 # rbd info poolcopy2/rbdimage2
rbd image 'rbd16Mimage':
    size 10240 MB in 640 objects
    order 24 (16384 kB objects)
    block_name_prefix: rbd_data.6613e6b8b4567
    format: 2
    features: layering
    flags: 

# --order 242^24bytes 为16M,条带大小为16M
# --order 222^22bytes 为4M,条带大小为4M

2. 创建rbd

# rbd create poolcopy2/rbdimage1 --size 2048 --image-format 2
format 2 支持RBD分层,实现COW,可写快照
默认是format 1 原始格式 不支持RBD分层

# rbd -p poolcopy2 ls
luncopy2
rbdimage1

长格式查看
# rbd ls poolcopy2 -l
NAME                      SIZE PARENT FMT PROT LOCK 
luncopy2                 5120M          2           
luncopy2@snapcopy01      5120M          2 yes       
rbdimage1                2048M          2           
rbdimage1@rbdimage1_snap 2048M          2           
rbdimage2                3072M          2   




# rbd -p poolcopy2 --image rbdimage1 info
rbd image 'rbdimage1':
    size 2048 MB in 512 objects
    order 22 (4096 kB objects)
    block_name_prefix: rbd_data.8e1216b8b4567
    format: 2
    features: layering
    flags: 

3. 创建快照snapshot,快照保护,快照克隆,快照分层取消快照父子关系

1,查看快照
# rbd snap list poolcopy2/luncopy2
SNAPID NAME          SIZE 
     4 snapcopy01 5120 MB
# rbd snap ls poolcopy2/luncopy2
SNAPID NAME          SIZE 
     4 snapcopy01 5120 MB

2,查看存储池 rbd 所有快照 ,使用长格式
# rbd ls poolcopy2 -l

3,创建快照
# rbd snap create poolcopy2/rbdimage2@snap_image
# rbd snap ls poolcopy2/rbdimage2
SNAPID NAME          SIZE 
     7 snap_image 3072 MB


4,查看快照详细信息
# rbd info poolcopy2/rbdimage2@snap_image
rbd image 'rbdimage2':
    size 3072 MB in 768 objects
    order 22 (4096 kB objects)
    block_name_prefix: rbd_data.652746b8b4567
    format: 2
    features: layering
    flags: 
    protected: False


5,快照克隆(快照处于保护状态)
# rados lspools
poolcopy2
# rbd ls poolcopy2
rbdimage1
# rbd snap ls poolcopy2/rbdimage1
SNAPID NAME              SIZE 
     5 rbdimage1_snap 2048 MB 
# rbd info poolcopy2/rbdimage1@rbdimage1_snap
rbd image 'rbdimage1':
    size 2048 MB in 512 objects
    order 22 (4096 kB objects)
    block_name_prefix: rbd_data.8e1216b8b4567
    format: 2
    features: layering
    flags: 
    protected: False        # 快照未保护

5.1,设置快照保护
# rbd snap protect poolcopy2/rbdimage1@rbdimage1_snap
# rbd info poolcopy2/rbdimage1@rbdimage1_snap
rbd image 'rbdimage1':
    size 2048 MB in 512 objects
    order 22 (4096 kB objects)
    block_name_prefix: rbd_data.8e1216b8b4567
    format: 2
    features: layering
    flags: 
    protected: True         # 快照已保护

5.2 快照克隆(克隆快照到另外一个存储池并成为一个新的image),也叫可写快照
# rbd clone poolcopy2/rbdimage1@rbdimage1_snap pooltest/rbdimage1_snap_clone
# rbd ls pooltest -l
NAME                  SIZE PARENT                             FMT PROT LOCK 
rbdimage1_snap_clone 2048M poolcopy2/rbdimage1@rbdimage1_snap   2           


5.3 查看快照的子image
# rbd children poolcopy2/rbdimage1@rbdimage1_snap
pooltest/rbdimage1_snap_clone

5.4 把分层的rbd image 变为扁平的没有父子层级的image,

# rbd flatten pooltest/rbdimage1_snap_clone
Image flatten: 99% complete...2017-11-15 18:29:19.110186 7f0587b32700  0 monclient: hunting for new mon
Image flatten: 100% complete...done.

# rbd ls pooltest -l
NAME                  SIZE PARENT FMT PROT LOCK 
rbdimage1_snap_clone 2048M          2                 
解除了rbd快照的父子关系


5.4 RBD 导入和导出(用于RBD块设备的备份和恢复)
# rbd export poolcopy2/luncopy2 /root/export/luncopy2_export
Exporting image: 100% complete...done.
# cd export/;ls -lh
-rw-r--r-- 1 root root 5.0G Nov 15 18:49 luncopy2_export

导入
# rbd import /root/export/luncopy2_export pooltest/image --image-format 2
报错,提示已经存在,

4. 快命令总结

创建快照:
    rbd snap create {pool-name}/{image-name}@{snap-name}
列出快照:
    rbd snap ls {pool-name}/{image-name}
列出存储池块和快照
    rbd ls {pool-name} -l
快照回滚:
    rbd snap rollback {pool-name}/{image-name}@{snap-name}
删除快照:
    rbd snap rm {pool-name}/{image-name}@{snap-name}


参考:
1.快照
2.RBD命令

你可能感兴趣的:(ceph)