博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Ceph rbd cmd练习
阅读量:5157 次
发布时间:2019-06-13

本文共 9059 字,大约阅读时间需要 30 分钟。

目的:阅读官方文档,熟悉rbd命令。

rbd命令行参数:

image相关

列出pools

root@maqi-openstack:~$ ceph osd lspools0 rbd,1 cephfs_data,2 cephfs_metadata,3 .rgw.root,4 .rgw.control,5 .rgw,6 .rgw.gc,7 .users.uid,

这里显示了0 ~ 7共8个pool。

The default pools include:

  • data
  • metadata
  • rbd

创建image

root@maqi-openstack:~$ rbd create foo --size 1024

列出image

root@maqi-openstack:~$ rbd lsfooroot@maqi-openstack:~$ rbd ls rbd        #rbd是默认poolfoo

查看image详细信息

root@maqi-openstack:~$ rbd --image foo inforbd image 'foo':    size 1024 MB in 256 objects    order 22 (4096 kB objects)    block_name_prefix: rb.0.102b.74b0dc51    format: 1root@maqi-openstack:~$ rbd --image foo -p rbd inforbd image 'foo':    size 1024 MB in 256 objects    order 22 (4096 kB objects)    block_name_prefix: rb.0.102b.74b0dc51    format: 1

Resize image

root@maqi-openstack:~$ rbd resize --image foo --size 2048Resizing image: 100% complete...done.root@maqi-openstack:~$ rbd --image foo inforbd image 'foo':    size 2048 MB in 512 objects    order 22 (4096 kB objects)    block_name_prefix: rb.0.102b.74b0dc51    format: 1

删除image

root@maqi-openstack:~$ rbd rm foo -p rbdRemoving image: 100% complete...done.root@maqi-openstack:~$ rbd lsroot@maqi-openstack:~$ rbd --image foo info2015-10-12 15:56:48.457090 7f81b9afc840 -1 librbd::ImageCtx: error finding header: (2) No such file or directoryrbd: error opening image foo: (2) No such file or directory

snapshot相关

snapshot可以这样表示:

{pool-name}/{image-name}@{snap-name}

创建snapshot

root@maqi-openstack:~$ rbd --pool rbd snap create --snap snapname fooroot@maqi-openstack:~$ rbd --pool rbd snap ls fooSNAPID NAME        SIZE     2 snapname 1024 MB

或者

root@maqi-openstack:~$ rbd snap create rbd/foo@snapshotroot@maqi-openstack:~$ rbd snap ls rbd/fooSNAPID NAME        SIZE     2 snapname 1024 MB     3 snapshot 1024 MB

Rollback snapshot

Rolling back an image to a snapshot means overwriting the current version of the image with data from a snapshot. The time it takes to execute a rollback increases with the size of the image. It is faster to clone from a snapshot than to rollback an image to a snapshot, and it is the preferred method of returning to a pre-existing state.

root@maqi-openstack:~$ rbd --pool rbd snap rollback --snap snapname fooRolling back to snapshot: 100% complete...done.

或者

root@maqi-openstack:~$ rbd snap rollback rbd/foo@snapshotRolling back to snapshot: 100% complete...done.

删除snapshot

root@maqi-openstack:~$ rbd --pool rbd snap rm --snap snapname fooroot@maqi-openstack:~$ rbd snap rm rbd/foo@snapshot

snapshot layering

Ceph supports the ability to create many copy-on-write (COW) clones of a block device shapshot. Snapshot layering enables Ceph block device clients to create images very quickly. For example, you might create a block device image with a Linux VM written to it; then, snapshot the image, protect the snapshot, and create as many copy-on-write clones as you like. A snapshot is read-only, so cloning a snapshot simplifies semantics–making it possible to create clones rapidly.

这里写图片描述

Each cloned image (child) stores a reference to its parent image, which enables the cloned image to open the parent snapshot and read it.

A COW clone of a snapshot behaves exactly like any other Ceph block device image. You can read to, write from, clone, and resize cloned images. There are no special restrictions with cloned images. However, the copy-on-write clone of a snapshot refers to the snapshot, so you MUST protect the snapshot before you clone it. The following diagram depicts the process.

enter image description here

  • snapshot都是read-only的
  • 对snapshot做clone,利用了COW方式,生成新的image

使用snapshot layering时(也就是多次snapshot):

  1. 对image创建snapshot
  2. protect这个snapshot,使其成为parent snapshot
  3. clone这个parent snapshot。clone出来的image就像一个普通的image。

Protect a snapshot

root@maqi-openstack:~$ rbd snap create --pool rbd --snap parent_snap fooroot@maqi-openstack:~$ rbd snap protect --pool rbd --snap parent_snap foorbd: protecting snap failed: (38) Function not implemented2015-10-13 06:31:42.966603 7fc2ecf95840 -1 librbd: snap_protect: image must support layering

只有format 2的image支持layering:

op@ubuntu-op:~$ sudo rbd create bar --image-format 2 --size 1024op@ubuntu-op:~$ sudo rbd snap create rbd/bar@parent_snapop@ubuntu-op:~$ sudo rbd snap protect rbd/bar@parent_snapop@ubuntu-op:~$ sudo rbd ls      # 只列出imagebarop@ubuntu-op:~$ sudo rbd ls -l   # 列出image和snapshotNAME             SIZE PARENT              FMT PROT LOCKbar             1024M                       2bar@parent_snap 1024M                       2 yes

protect之后不能删除:

op@ubuntu-op:~$ sudo rbd snap rm rbd/bar@parent_snaprbd: snapshot 'parent_snap' is protected from removal.2015-10-13 15:18:57.462634 7fe483d067c0 -1 librbd: removing snapshot from header failed: (16) Device or resource busy

Clone a snapshot

op@ubuntu-op:~$ sudo rbd  clone rbd/bar@parent_snap rbd/bar_child_1op@ubuntu-op:~$ sudo rbd ls      barbar_child_1op@ubuntu-op:~$ sudo rbd ls -lNAME             SIZE PARENT              FMT PROT LOCKbar             1024M                       2bar@parent_snap 1024M                       2 yesbar_child_1     1024M rbd/bar@parent_snap   2

注意:

  1. clone出来的东东是image,而不是snapshot
  2. clone命令只能针对snap,不能直接clone image:
op@ubuntu-op:~$ sudo rbd clone bar rbd/bar_child_2rbd: snap name was not specified

Unprotect a snapshot

op@ubuntu-op:~$ sudo rbd snap unprotect rbd/bar@parent_snap2015-10-13 15:25:01.553498 7faa3eac97c0 -1 librbd: snap_unprotect: can't unprotect; at least 1 child(ren) in pool rbdrbd: unprotecting snap failed: (16) Device or resource busyop@ubuntu-op:~$ sudo rbd rm rbd/bar_child_1Removing image: 100% complete...done.op@ubuntu-op:~$ sudo rbd snap unprotect rbd/bar@parent_snap

查看某个snapshot有没有被clone过(使用children命令)

op@ubuntu-op:~$ sudo rbd children rbd/bar@parent_snaprbd/bar_child_1

Flatten a child image

Cloned images retain a reference to the parent snapshot. When you remove the reference from the child clone to the parent snapshot, you effectively “flatten” the image by copying the information from the snapshot to the clone. The time it takes to flatten a clone increases with the size of the snapshot. To delete a snapshot, you must flatten the child images first.

op@ubuntu-op:~$ sudo rbd flatten bar_child_1Image flatten: 100% complete...done.op@ubuntu-op:~$ sudo rbd ls -lNAME             SIZE PARENT FMT PROT LOCKbar             1024M          2bar@parent_snap 1024M          2 yesbar_child_1     1024M          2

RBD layering

简单来说,就是使用rbd clone命令,从image的某个snapshot克隆出一个新的image。

Incremental snapshot

针对image,rbd有3个diff命令,可以比较image的变化:diff, export-diff, import-diff

  • export-diff [image-name] [dest-path] [–from-snap snapname]

    Exports an incremental diff for an image to dest path (use - for stdout). If an initial snapshot is specified, only changes since that snapshot are included; otherwise, any regions of the image that contain data are included. The end snapshot is specified using the standard –snap option or @snap syntax (see below). The image diff format includes metadata about image size changes, and the start and end snapshots. It efficiently represents discarded or ‘zero’ regions of the image.

  • import-diff [src-path] [image-name]

    Imports an incremental diff of an image and applies it to the current image. If the diff was generated relative to a start snapshot, we verify that snapshot already exists before continuing. If there was an end snapshot we verify it does not already exist before applying the changes, and create the snapshot when we are done.

  • diff [image-name] [–from-snap snapname]

    Dump a list of byte extents in the image that have changed since the specified start snapshot, or since the image was created. Each output line includes the starting offset (in bytes), the length of the region (in bytes), and either ‘zero’ or ‘data’ to indicate whether the region is known to be zeros or may contain other data.

image bar有两个snapshot:

op@ubuntu-op:~$ sudo rbd snap create rbd/bar --snap bar_snap_2op@ubuntu-op:~$ sudo rbd snap list barSNAPID NAME           SIZE     3 parent_snap 1024 MB     5 bar_snap_2  1024 MB

查看bar从创建以来的改动,输出到标准输出(因为没有改动,所以为空):

op@ubuntu-op:~$ sudo rbd export-diff bar -rbd diff v1Exporting image: 100% complete...done.

查看bar从snapshot parent_snap以后的改动,输入到文件中:

op@ubuntu-op:~$ sudo rbd export-diff bar diff_1 --snap parent_snapExporting image: 100% complete...done.op@ubuntu-op:~$ cat diff_1rbd diff v1t parent_snaps@eop@ubuntu-op:~$ file diff_1diff_1: data

用export-diff取得diff文件后,可以用import-diff把这个diff文件import到某个image中

op@ubuntu-op:~$ sudo rbd import-diff diff_1 barend snapshot 'parent_snap' already exists, abortingImporting image diff: 0% complete...failed.op@ubuntu-op:~$ sudo rbd import-diff diff_1 bar_child_1Importing image diff: 100% complete...done.
rbd import-diff /path/to/diff backup_image

This will write the contents of the differential to the backup_image and create a snapshot with the same name as the original ending snapshot. It will fail and do nothing if a snapshot with this name already exists. Since overwriting the same data is idempotent, it’s safe to have an import-diff interrupted in the middle.

转载于:https://www.cnblogs.com/qeelee/p/5159136.html

你可能感兴趣的文章
java笔记 chapter3 包装类,类型转换,程序的运行流程,面向对象的三大特征
查看>>
.Net基础篇_学习笔记_第四天_关系运算符和逻辑运算符
查看>>
send_signal函数注解
查看>>
模拟练习1
查看>>
判断App是否在后台运行
查看>>
为什么要在onNewIntent的时候要显示的去调用setIntent
查看>>
hive优化实战
查看>>
Django 1.10 中文文档------3.2.1 模型Models
查看>>
ip地址
查看>>
re模块的高级用法
查看>>
Intro to Python for Data Science Learning 2 - List
查看>>
js闭包
查看>>
Jenkins常用插件之Deploy Plugin
查看>>
Shell基础
查看>>
LA 3177 长城守卫
查看>>
UVa 1151 (枚举 + MST) Buy or Build
查看>>
UVa 10601 (Polya计数 等价类计数) Cubes
查看>>
数据库SQL优化大总结
查看>>
利用定时器和moment.js显示当前年月日 周时分秒
查看>>
DOM进行表格动态操作
查看>>