使用RBD(rados块设备)
查看存储池
[root@node1~]# ceph osd lspools
将显示名为rbd的镜像池0
创建名为demo-img的镜像大小10GB
[ root @ node1~~] # rbdcreatedemo-img-- image-feature layering-- size 10g
[root@node1~]# rbd list
[root@node1~]# rbd info demo-img
3 .创建名为image的第二个镜像,并指定其位于rbd池中
[ root @ node1~~] # rbdcreaterbd/image-- image-feature layering-- size 10g
将image镜像大小缩小到7G
[ root @ node 1c Eph-clu ] # rbd resize-- size 7g image-- allow-shrink
[ root @ node 1c Eph-clu ] # rbdinfoimage
从image扩展到15G
[ root @ node 1c Eph-clu ] # rbd resize-- size 15g image
[ root @ node 1c Eph-clu ] # rbdinfoimage
使用node6作为客户端,使用ceph创建的镜像作为存储设备
安装客户端软件
[ root @ node6~ ] # yum install-YC Eph-common
复制相关文件
[ root @ node 1c Eph-clu ] # scp/etc/ceph/ceph.conf node 63360/etc/ceph /
[ root @ node 1c Eph-clu ] # scp/etc/ceph/ceph.client.admin.key ring node 63360/etc/ceph /
注: ceph.conf是一个配置文件,用于记录ceph群集访问的方式和地址
ceph.client.admin.keyring是client.admin用户的密钥文件
本地镜像image
[root@node6~]# rbd map image
/dev/rbd0 -rbd0是一个映射的硬盘文件
[root@node6~]# lsblk
[root@node6~]# rbd showmapped
格式,安装
[ root @ node6~ ] # mkfs.ext4/dev/rbd 0
[ root @ node6~ ] # mount/dev/rbd0/mnt /
[root@node6~]# df -h /mnt/
[ root @ node6~~] # echo ' hello world '/mnt/hello.txt
快照
查看image镜像的快照
[root@node6~]# rbd snap ls image
创建image的名为image-sn1的快照
[ root @ node6~~] # rbdsnapcreateimage-- snap image-sn1
模拟错误的删除操作,恢复数据
删除
[ root @ node6~~] # RM-f/mnt/hello.txt
卸载设备
[root@node6~]# umount /mnt/
(3)使用image-sn1恢复快照
[ root @ node6~~] # rbdsnaprollbackimage-- snap image-sn1
)4)挂载,检查是否恢复
[ root @ node6~ ] # mount/dev/rbd0/mnt /
[ root @ node6~~] # cat/mnt/hello.txt
克隆快照
克隆必须首先保护快照,防止意外删除等操作
[ root @ node6~~] # rbdsnapprotectimage-- snap image-sn1
克隆image-sn1快照。 克隆的名称为image-cl1
[ root @ node6~~] # rbdcloneimage-- snap image-s n1 image-cl1-- image-feature layering
查看状态
[root@node6~]# rbd info image-cl1
parent:rbd/image@image-sn1
合并克隆文件
[ root @ node6~ ] # rbdflattenimage-cl1
[ root @ node6~~] # rbdinfoimage-cl1中没有部件
删除
[root@node6~]# umount /mnt/
[root@node6~]# rbd showmapped
[ root @ node6~ ] # rbd unmap/dev/rbd/rbd/image