会挽雕弓如满月,西北望,射天狼。这篇文章主要讲述Ceph运维之rbd常用命令相关的知识,希望能为你提供帮助。
1、创建池
[root@inf-c7-n1 ~]# ceph osd pool create data-vol 32 32
pool \'data-vol\' created
[root@inf-c7-n1 ~]# ceph osdpool application enable data-vol rbd
enabled application \'rbd\' on pool \'data-vol\'
2、查看池
[root@inf-c7-n1 ~]# ceph osd pool ls detail
pool 1 \'vms\' replicated size 3 min_size 2 crush_rule 0 object_hash rjenkins pg_num 32 pgp_num 32 autoscale_mode warn last_change 447 lfor 0/447/445 flags hashpspool stripe_width 0 application rbd
pool 2 \'data-vol\' replicated size 3 min_size 2 crush_rule 0 object_hash rjenkins pg_num 32 pgp_num 32 autoscale_mode warn last_change 453 flags hashpspool stripe_width 0 application rbd
3、创建卷
[root@inf-c7-n1 ~]# rbd create --size 1024 image1 --pool vms
[root@inf-c7-n1 ~]# rbd create --size 2G image2 --pool vms
4、查看卷
[root@inf-c7-n1 ~]# rbd info vms/image1
rbd image \'image1\':
size 1 GiB in 256 objects
order 22 (4 MiB objects)
snapshot_count: 0
id: 14587cfb19ad
block_name_prefix: rbd_data.14587cfb19ad
format: 2
features: layering, exclusive-lock, object-map, fast-diff, deep-flatten
op_features:
flags:
create_timestamp: Sun Sep 26 16:19:46 2021
access_timestamp: Sun Sep 26 16:19:46 2021
modify_timestamp: Sun Sep 26 16:19:46 2021
[root@inf-c7-n1 ~]# rados -p vms ls --all
rbd_directory
rbd_info
rbd_header.14587cfb19ad
rbd_object_map.14587cfb19ad
rbd_trash
rbd_id.image1
5、删除卷
[root@inf-c7-n1 ~]# rbd rm vms/image2
Removing image: 100% complete...done.
[root@inf-c7-n1 ~]# rbd ls -p vms
image1
6、将卷map到主机
[root@inf-c7-n1 ~]# rbd map vms/image1
rbd: sysfs write failed
RBD image feature set mismatch. You can disable features unsupported by the kernel with "rbd feature disable vms/image1 object-map fast-diff deep-flatten".
In some cases useful info is found in syslog - try "dmesg | tail".
rbd: map failed: (6) No such device or address
[root@inf-c7-n1 ~]# dmesg |tail
[783542.170907] libceph: mon0 10.199.13.119:6789 session lost, hunting for new mon
[783542.349515] libceph: mon1 10.199.13.122:6789 session established
[783542.410414] libceph: client5289 fsid 62fcf0e4-4491-45fd-934f-2ff184be6ff0
[783542.980954] rbd: image image1: image uses unsupported features: 0x38
[784048.386368] libceph: mon1 10.199.13.122:6789 session established
[784048.419541] libceph: mon1 10.199.13.122:6789 socket closed (con state OPEN)
[784048.419599] libceph: mon1 10.199.13.122:6789 session lost, hunting for new mon
[784048.439196] libceph: mon2 10.199.13.123:6789 session established
[784048.560592] libceph: client5188 fsid 62fcf0e4-4491-45fd-934f-2ff184be6ff0
[784048.610928] rbd: image image1: image uses unsupported features: 0x38
[root@inf-c7-n1 ~]# rbd feature disable vms/image1 object-map fast-diff deep-flatten
[root@inf-c7-n1 ~]# rbd map vms/image1
/dev/rbd0
7、查看主机映射的卷
[root@inf-c7-n1 ~]# rbd showmapped
id pool namespace imagesnap device
0vmsimage1 -/dev/rbd0
8、创建卷快照
[root@inf-c7-n1 ~]# rbd snap create -p vms image1@image1_snap01
[root@inf-c7-n1 ~]# rbd snap list -p vms image1
SNAPID NAMESIZEPROTECTED TIMESTAMP
4 image1_snap01 1 GiBSun Sep 26 17:04:18 2021
9、查看快照详细信息
[root@inf-c7-n1 ~]# rbd info -p vms image1@image1_snap01
rbd image \'image1\':
size 1 GiB in 256 objects
order 22 (4 MiB objects)
snapshot_count: 1
id: 14587cfb19ad
block_name_prefix: rbd_data.14587cfb19ad
format: 2
features: layering, exclusive-lock
op_features:
flags:
create_timestamp: Sun Sep 26 16:19:46 2021
access_timestamp: Sun Sep 26 16:19:46 2021
modify_timestamp: Sun Sep 26 16:19:46 2021
protected: False
10、克隆快照
[root@inf-c7-n1 ~]# ceph osd pool create vol-clone 16 16
pool \'vol-clone\' created
[root@inf-c7-n1 ~]# ceph osd pool application enable vol-clone clone
enabled application \'clone\' on pool \'vol-clone\'
[root@inf-c7-n1 ~]# rbd snap protect -p vms image1@image1_snap01
[root@inf-c7-n1 ~]# rbd snap list -p vms image1
SNAPID NAMESIZEPROTECTED TIMESTAMP
4 image1_snap01 1 GiB yesSun Sep 26 17:04:18 2021
[root@inf-c7-n1 ~]# rbd clone vms/image1@image1_snap01 vol-clone/image1_clone01
[root@inf-c7-n1 ~]# rbd ls -p vol-clone
image1_clone01
11、查看快照子关系
[root@inf-c7-n1 ~]# rbd children vms/image1
vol-clone/image1_clone01
12、去掉快照parent(克隆的块关系,生成独立的快照)
[root@inf-c7-n1 ~]# rbd flatten vol-clone/image1_clone01
Image flatten: 100% complete...done.
[root@inf-c7-n1 ~]# rbd children vms/image1
[root@inf-c7-n1 ~]#
13、恢复快照
[root@inf-c7-n1 ~]# rbd snap rollback -p vms image1@image1_snap01
Rolling back to snapshot: 100% complete...done.
14、删除快照
[root@inf-c7-n1 ~]# rbd snap remove -p vms image1@image1_snap01
2021-09-26 17:22:35.739 7f6a6e2a2c80 -1 librbd::Operations: snapshot is protected
Removing snap: 0% complete...failed.
rbd: snapshot \'image1_snap01\' is protected from removal.
[root@inf-c7-n1 ~]# rbd snap unprotect -p vms image1@image1_snap01
[root@inf-c7-n1 ~]# rbd snap remove -p vms image1@image1_snap01
Removing snap: 100% complete...done.
15、导出RBD镜像
[root@inf-c7-n1 ~]# rbd export vms/image1 /tmp/image1.raw
Exporting image: 100% complete...done.
[root@inf-c7-n1 ~]# ll /tmp/image1.raw
-rw-r--r-- 1 root root 1073741824 Sep 27 09:20 /tmp/image1.raw
16、导入镜像
[root@inf-c7-n1 ~]# rbd remove vms/image1
2021-09-27 09:23:33.422 7f0a67fff700 -1 librbd::image::PreRemoveRequest: 0x558951f3ca10 check_image_watchers: image has watchers - not removing
Removing image: 0% complete...failed.
rbd: error: image still has watchers
This means the image is still open or the client using it crashed. Try again after closing/unmapping it or waiting 30s for the crashed client to timeout.
[root@inf-c7-n1 ~]# rbd showmapped
id pool namespace imagesnap device
0vmsimage1 -/dev/rbd0
[root@inf-c7-n1 ~]# rbd unmap /dev/rbd0
[root@inf-c7-n1 ~]# rbd showmapped
[root@inf-c7-n1 ~]#
[root@inf-c7-n1 ~]# rbd remove vms/image1
Removing image: 100% complete...done.
[root@inf-c7-n1 ~]# rbd ls -p vms
[root@inf-c7-n1 ~]# ls /tmp/
image1.raw
tmp.XSHfXBgbFl
[root@inf-c7-n1 ~]# rbd import /tmp/image1.raw vms/image1 --image-format 2
Importing image: 100% complete...done.
[root@inf-c7-n1 ~]# rbd ls -p vms
image1
17、扩容镜像卷
[root@inf-c7-n1 ~]# rbd info vms/image1
rbd image \'image1\':
size 1 GiB in 256 objects
order 22 (4 MiB objects)
snapshot_count: 0
id: 1566ae93277a
block_name_prefix: rbd_data.1566ae93277a
format: 2
features: layering, exclusive-lock, object-map, fast-diff, deep-flatten
op_features:
flags:
create_timestamp: Mon Sep 27 09:28:49 2021
access_timestamp: Mon Sep 27 09:28:49 2021
modify_timestamp: Mon Sep 27 09:28:49 2021
[root@inf-c7-n1 ~]# rbd --pool vms --image image1 resize --size 2G
Resizing image: 100% complete...done.
[root@inf-c7-n1 ~]# rbd info vms/image1
rbd image \'image1\':
size 2 GiB in 512 objects
order 22 (4 MiB objects)
snapshot_count: 0
id: 1566ae93277a
block_name_prefix: rbd_data.1566ae93277a
format: 2
features: layering, exclusive-lock, object-map, fast-diff, deep-flatten
op_features:
flags:
create_timestamp: Mon Sep 27 09:28:49 2021
access_timestamp: Mon Sep 27 09:28:49 2021
modify_timestamp: Mon Sep 27 09:28:49 2021
18、缩小镜像卷
[root@inf-c7-n1 ~]# rbd --pool vms --image image1 resize --size 500M --allow-shrink
Resizing image: 100% complete...done.
[root@inf-c7-n1 ~]# rbd info vms/image1
rbd image \'image1\':
size 500 MiB in 125 objects
order 22 (4 MiB objects)
snapshot_count: 0
id: 1566ae93277a
block_name_prefix: rbd_data.1566ae93277a
format: 2
features: layering, exclusive-lock, object-map, fast-diff, deep-flatten
op_features:
flags:
create_timestamp: Mon Sep 27 09:28:49 2021
access_timestamp: Mon Sep 27 09:28:49 2021
modify_timestamp: Mon Sep 27 09:28:49 2021
【Ceph运维之rbd常用命令】?
推荐阅读
- git新建远程仓库qd-admin
- 开始学linux的日子 NO.4
- 实战——Nginx调优
- 浙大学习记之学习篇一
- Linux系统调优——实战
- Kubernetes/K8s CKA 认证实战班(K8s运维工程师) 李振良
- 如何在最小化安装的CentOS 7.5上编译安装Git2.19
- 性能测试之微信小程序小试
- linux之lsof使用技巧