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

rbd命令行参数:
http://docs.ceph.com/docs/wip-5900/man/8/rbd/

image相关

http://docs.ceph.com/docs/wip-5900/rbd/rados-rbd-cmds/

列出pools
http://docs.ceph.com/docs/wip-5900/rados/operations/pools/

root@maqi-openstack:~$ ceph osd lspools
0 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 ls
foo
root@maqi-openstack:~$ rbd ls rbd        #rbd是默认pool
foo

查看image详细信息

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

Resize image

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

删除image

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

snapshot相关

http://docs.ceph.com/docs/wip-5900/rbd/rbd-snapshot/

snapshot可以这样表示:

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

创建snapshot

root@maqi-openstack:~$ rbd --pool rbd snap create --snap snapname foo
root@maqi-openstack:~$ rbd --pool rbd snap ls foo
SNAPID NAME        SIZE2 snapname 1024 MB

或者

root@maqi-openstack:~$ rbd snap create rbd/foo@snapshot
root@maqi-openstack:~$ rbd snap ls rbd/foo
SNAPID NAME        SIZE2 snapname 1024 MB3 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 foo
Rolling back to snapshot: 100% complete...done.

或者

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

删除snapshot

root@maqi-openstack:~$ rbd --pool rbd snap rm --snap snapname foo
root@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.

  • 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 foo
root@maqi-openstack:~$ rbd snap protect --pool rbd --snap parent_snap foo
rbd: protecting snap failed: (38) Function not implemented
2015-10-13 06:31:42.966603 7fc2ecf95840 -1 librbd: snap_protect: image must support layering

只有format 2的image支持layering:http://docs.ceph.com/docs/wip-5900/rbd/rbd-snapshot/#layering

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

protect之后不能删除:

op@ubuntu-op:~$ sudo rbd snap rm rbd/bar@parent_snap
rbd: 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
bar
bar_child_1
op@ubuntu-op:~$ sudo rbd ls -l
NAME             SIZE PARENT              FMT PROT LOCK
bar             1024M                       2
bar@parent_snap 1024M                       2 yes
bar_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_2
rbd: snap name was not specified

Unprotect a snapshot

op@ubuntu-op:~$ sudo rbd snap unprotect rbd/bar@parent_snap
2015-10-13 15:25:01.553498 7faa3eac97c0 -1 librbd: snap_unprotect: can't unprotect; at least 1 child(ren) in pool rbd
rbd: unprotecting snap failed: (16) Device or resource busy
op@ubuntu-op:~$ sudo rbd rm rbd/bar_child_1
Removing 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_snap
rbd/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_1
Image flatten: 100% complete...done.op@ubuntu-op:~$ sudo rbd ls -l
NAME             SIZE PARENT FMT PROT LOCK
bar             1024M          2
bar@parent_snap 1024M          2 yes
bar_child_1     1024M          2

RBD layering

http://docs.ceph.com/docs/wip-5900/dev/rbd-layering/
简单来说,就是使用rbd clone命令,从image的某个snapshot克隆出一个新的image。

Incremental snapshot

https://ceph.com/dev-notes/incremental-snapshots-with-rbd/
针对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_2
op@ubuntu-op:~$ sudo rbd snap list bar
SNAPID NAME           SIZE3 parent_snap 1024 MB5 bar_snap_2  1024 MB

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

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

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

op@ubuntu-op:~$ sudo rbd export-diff bar diff_1 --snap parent_snap
Exporting image: 100% complete...done.
op@ubuntu-op:~$ cat diff_1
rbd diff v1
tparent_snaps@eop@ubuntu-op:~$ file diff_1
diff_1: data

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

op@ubuntu-op:~$ sudo rbd import-diff diff_1 bar
end snapshot 'parent_snap' already exists, aborting
Importing image diff: 0% complete...failed.op@ubuntu-op:~$ sudo rbd import-diff diff_1 bar_child_1
Importing 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

Ceph rbd cmd练习相关推荐

  1. 牛批,Ceph RBD 备份与恢复完全指南

    一.RBD 回收机制 ceph RBD 默认提供回收站机制trash,也就是我们可以把块数据放在回收站,在回收站中保持一定的存储周期,当我们后期还需要使用的时候可以在回收站在拿回来. 同样,在公有云也 ...

  2. Ceph RBD:条带(stripe)详解

    文章目录 引言 条带的概念 基本概念 条带数据如何分布? 为什么要有条带? Ceph RBD如何使用条带? 条带观察实践 创建rbd image,stripe_unit为1M,stripe_count ...

  3. k8s主从自动切换mysql_K8S与Ceph RBD集成-多主与主从数据库示例

    参考文章: 感谢以上作者提供的技术参考,这里我加以整理,分别实现了多主数据库集群和主从数据库结合Ceph RDB的实现方式.以下配置只为测试使用,不能做为生产配置. K8S中存储的分类 在K8S的持久 ...

  4. k8s(十二)、分布式存储Ceph RBD使用

    前言 上篇文章介绍了k8s使用pv/pvc 的方式使用cephfs, k8s(十一).分布式存储Cephfs使用 Ceph存储有三种存储接口,分别是: 对象存储 Ceph Object Gateway ...

  5. K8S使用Ceph RBD作为后端存储

    一.准备工作 Ceph版本:v13.2.5 mimic稳定版 1.Ceph上准备存储池 [root@ceph-node1 ceph]# ceph osd pool create k8s 128 128 ...

  6. k8s1.18 StorageClass 使用rbd-provisioner提供ceph rbd持久化存储

    rbd-provisioner为kubernetes 1.5+版本提供了类似于kubernetes.io/rbd的ceph rbd持久化存储动态配置实现. 一些用户会使用kubeadm来部署集群,或者 ...

  7. 通过iscsi协议使用ceph rbd

    通过iscsi协议使用ceph rbd Ceph iscsi gatway基本框架图:   1. 常见的几种iscsi target GNU/Linux 系统中流行的 SCSI target 框架或 ...

  8. Kubernetes 基于ceph rbd生成pv

    1.创建ceph-secret这个k8s secret对象,这个secret对象用于k8s volume插件访问ceph集群,获取client.admin的keyring值,并用base64编码,在m ...

  9. Ceph RBD 入门系列(一) : 块设备的基本使用及librbd在各个应用场景的位置

    一.Ceph 块设备 块设备是Ceph三种类型存储方式(块存储/对象存储/文件存储)最重要的 1. 先在Ceph 存储集群中创建一个映像(image),使用下列命令: rbd create --siz ...

最新文章

  1. 高翔博士SLAMBOO2十二讲代码库中的三方库没有下载下来 ,需要手动对三方库单独下载的git的命令如下
  2. 微信小程序开发记录一,开发工具的使用
  3. Bugku密码学(一)
  4. 最优化课堂笔记03:整数规划
  5. JavaScript表单序列化的方法详解
  6. 光线求交加速算法:边界体积层次结构(Bounding Volume Hierarchies)2-表面积启发式法(The Surface Area Heuristic)
  7. 民航重组:做大容易做强难
  8. JAVA入门[14]-Spring MVC AOP
  9. 利用application在页面中显示访问次数
  10. 常用邮箱的POP3、IMAP地址
  11. 第五章 线性回归 学习笔记上
  12. 电路分析基础笔记(静态电路+动态电路)
  13. 计算机芯片级维修包括哪些,计算机芯片级维修中心(芯片级维培训教材)b.doc
  14. 汉堡式折叠html,3种超酷汉堡包菜单按钮变形动画特效
  15. canvas用于绘制视频
  16. IT女白领突击怀孕避裁员
  17. 2021手机试玩平台《手赚网》源码
  18. Struts2 ValueStack ActionContext OGNL 关系
  19. java 字符和汉字比较_Java比较汉字字符串排序与C++比较汉字排序
  20. Revit二开 批量链接模型

热门文章

  1. 自学前端很难吗?只要你足够努力,高中学历也能获得offer
  2. python线性链表_线性表 (单链表、循环链表-python实现)
  3. 关于excel表的生成
  4. automake生成静态库文件_基于CocoaPods的组件化原理及私有库实践
  5. linux内核烧制,手机烧录自己编译的linux kernel
  6. android xml图片旋转,如何在Android中进行平滑的图像旋转?
  7. a标签鼠标放上去变色_一切为了集齐一套装备:杜伽LEO600游戏鼠标和P300鼠标垫简评...
  8. tensorflow里面函数记录
  9. 移动数据库 Realm 在 React-Native 的使用详解
  10. ansible批量安装服务器思路