ceph format2格式image

本文介绍如何创建RBD Format2格式的镜像,并详细解析了与镜像相关的元数据信息,包括如何查看镜像特性、元数据文件内容及如何在不同内核版本下正确映射和写入数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、接上篇,这创建一个format 2格式的image
$rbd create rbd/format2_image_1G –image-format=2 -s 1G

2、显示image元数据信息:size,order,block_name_prefix,format,features,flag
$rbd info rbd/format2_image_1G
rbd image ‘format2_image_1G’:
size 1024 MB in 256 objects
order 22 (4096 kB objects)
block_name_prefix: rbd_data.11062ae8944a
format: 2
features: layering, exclusive-lock, object-map, fast-diff, deep-flatten
flags:

3、查看rados -p rbd ls.多出了4个文件:
$rados -p rbd ls
rbd_object_map.11062ae8944a
rbd_directory
rbd_id.format2_image_1G
rbd_header.11062ae8944a

4、解释下这几个文件的内容
rbd_object_map.11062ae8944a:
rbd_directory:存放如上所示包含所有image name和ID的映射关系
rbd_id.format2_image_1G:保存的是image的ID信息
rbd_header.11062ae8944a:保存的image的元数据信息,如size,features, order,object_prefix,snap_seq, parent等。

5、接着上一篇查看rbd_directory是否包含有image的name和id的映射关系。
$rados -p rbd listomapvals rbd_directory
id_11062ae8944a
value (20 bytes) :
00000000 10 00 00 00 66 6f 72 6d 61 74 32 5f 69 6d 61 67 |….format2_imag|
00000010 65 5f 31 47 |e_1G|
00000014

name_format2_image_1G
value (16 bytes) :
00000000 0c 00 00 00 31 31 30 36 32 61 65 38 39 34 34 61 |….11062ae8944a|
00000010
果然有id(id_11062ae8944a) 和name(name_format2_image_1G)的纪录

6、查看rbd_id.format2_image_1G内容
$rados -p rbd get rbd_id.format2_image_1G 1.txt

$xxd 1.txt
0000000: 0c00 0000 3131 3036 3261 6538 3934 3461 ….11062ae8944a

也可以到目录(dev/osd0/current/1.42_head/)下查看文件(rbd\uid.format2\uimage\u1G__head_4C843142__1 ):
$cd dev/osd0/current/1.42_head/

$xxd rbd\uid.format2\uimage\u1G__head_4C843142__1
0000000: 0c00 0000 3131 3036 3261 6538 3934 3461 ….11062ae8944a

7、查看rbd_header.11062ae8944a文件内容
$rados -p rbd listomapvals rbd_header.11062ae8944a
features
value (8 bytes) :
00000000 3d 00 00 00 00 00 00 00 |=…….|
00000008

object_prefix
value (25 bytes) :
00000000 15 00 00 00 72 62 64 5f 64 61 74 61 2e 31 31 30 |….rbd_data.110|
00000010 36 32 61 65 38 39 34 34 61 |62ae8944a|
00000019

order
value (1 bytes) :
00000000 16 |.|
00000001

size
value (8 bytes) :
00000000 00 00 00 40 00 00 00 00 |…@….|
00000008

snap_seq
value (8 bytes) :
00000000 00 00 00 00 00 00 00 00 |……..|
00000008

object_prefix:对象的名字前缀
order:用来计算block size的,比如22,那么块大小就是1<<22=4MB
size:对象大小,这里是8字节
snap_seq:快照编号,没有快照的时候是0

8、往这个image中写点数据,首先需要map这个image到rbd块设备。
$sudo rbd map rbd/format2_image_1G
rbd: sysfs write failed
RBD image feature set mismatch. You can disable features unsupported by the kernel with “rbd feature disable”.
In some cases useful info is found in syslog - try “dmesg | tail” or so.
rbd: map failed: (6) No such device or address

这里是由于format 2格式的image有些功能只有内核3.11以上才支持,而我当前的内核版本是3.10的版本,所以会报错不支持该 format的的一些特性。因为我创建image的时候默认打开了所有的特性功能feature.如:
$rbd info rbd/format2_image_1G
rbd image ‘format2_image_1G’:
size 1024 MB in 256 objects
order 22 (4096 kB objects)
block_name_prefix: rbd_data.11062ae8944a
format: 2
features: layering, exclusive-lock, object-map, fast-diff, deep-flatten
flags:
这里features: layering, exclusive-lock, object-map, fast-diff, deep-flatten功能全部开启了。
layering: 支持分层
striping: 支持条带化 v2
exclusive-lock: 支持独占锁
object-map: 支持对象映射(依赖 exclusive-lock )
fast-diff: 快速计算差异(依赖 object-map )
deep-flatten: 支持快照扁平化操作
journaling: 支持记录 IO 操作(依赖独占锁)
所以要想在内核3.10上map这个格式的image则需要在创建的时候进行设置关闭掉其他功能,只打开layering功能即可,目前3.10只支持layering功能,其他特性需要更高的版本。所以这里需要重新创建image。

$rbd create rbd/format2_image_1G –image-format 2 –image-feature layering -s 1G

$rbd info rbd/format2_image_1G

rbd image ‘format2_image_1G’:
size 1024 MB in 256 objects
order 22 (4096 kB objects)
block_name_prefix: rbd_data.11212ae8944a
format: 2
features: layering
flags:

9、map format2_image_1G
$sudo rbd map rbd/format2_image_1G
/dev/rbd0

10、写4K数据到format2_image_1G
$sudo dd if=./testfile of=/dev/rbd0 bs=4k count=1
0+1 records in
0+1 records out
26 bytes (26 B) copied, 0.0134987 s, 1.9 kB/s

$rados -p rbd ls
rbd_header.11212ae8944a
rbd_directory
rbd_id.format2_image_1G
rbd_data.11212ae8944a.0000000000000000
多了对象(4M)rbd_data.11212ae8944a.0000000000000000

11、获取对象内容,两种方式,一种是通过rados get到临时文件,一种是到目录下查看文件内容。
$rados -p rbd get rbd_data.11212ae8944a.0000000000000000 1.txt

$xxd 1.txt
0000000: 7468 6973 2069 7320 7465 7374 2066 696c this is test fil
0000010: 6520 636f 6e74 6578 740a 0000 0000 0000 e context…….
0000020: 0000 0000 0000 0000 0000 0000 0000 0000 …………….
0000030: 0000 0000 0000 0000 0000 0000 0000 0000 …………….
0000040: 0000 0000 0000 0000 0000 0000 0000 0000 …………….
0000050: 0000 0000 0000 0000 0000 0000 0000 0000 …………….

$cd dev/osd0/current/1.8d_head/

$xxd rbd\udata.11212ae8944a.0000000000000000__head_3498F58D__1
0000000: 7468 6973 2069 7320 7465 7374 2066 696c this is test fil
0000010: 6520 636f 6e74 6578 740a 0000 0000 0000 e context…….
0000020: 0000 0000 0000 0000 0000 0000 0000 0000 …………….
0000030: 0000 0000 0000 0000 0000 0000 0000 0000 …………….
0000040: 0000 0000 0000 0000 0000 0000 0000 0000 …………….
0000050: 0000 0000 0000 0000 0000 0000 0000 0000 …………….

### Ceph CSI 配置和使用指南 Ceph CSI 是一种容器存储接口(Container Storage Interface, CSI),用于实现 Kubernetes 容器编排工具与 Ceph 存储集群之间的交互。以下是关于如何配置和使用 Ceph CSI 的详细介绍。 #### 1. 基本概念 Ceph CSI 提供了两种主要的存储接口:RBDCephFS[^1]。 - **RBD**:基于块设备的存储,适用于高性能需求的应用场景。 - **CephFS**:文件系统类型的存储,适合共享文件访问的需求。 这两种模式都可以通过动态卷供应的方式集成到 Kubernetes 中,并提供持久化存储功能。 --- #### 2. 环境准备 在部署之前,请确保满足以下条件: - 已经有一个运行中的 Ceph 集群,并且能够正常访问其 API。 - Kubernetes 集群版本应高于 v1.13,因为这是 CSI 支持的最低版本。 - 如果操作系统为 openEuler,则需要注意内核版本可能带来的兼容性问题[^3]。 --- #### 3. 部署步骤 ##### (a) 下载并应用 YAML 文件 可以通过官方文档或者 GitHub 上发布的最新版本下载所需的 manifest 文件。例如: ```bash kubectl apply -f https://raw.githubusercontent.com/ceph/ceph-csi/main/rbd/deploy/kubernetes/cephfs/csi-cephfsplugin-provisioner.yaml ``` 对于 NFS 类型的驱动也可以采用类似的命令[^2]: ```bash kubectl apply -f deploy/kubernetes/releases/csi-driver-nfs/latest/csi-driver-nfs.yaml ``` ##### (b) 创建 StorageClass 定义一个 `StorageClass` 来描述默认的存储参数。下面是一个简单的例子针对 RBD: ```yaml apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: csi-rbd-sc provisioner: rbd.csi.ceph.com parameters: clusterID: rook-cluster pool: replicapool imageFormat: "2" imageFeatures: layering reclaimPolicy: Delete allowVolumeExpansion: true mountOptions: - debug volumeBindingMode: Immediate ``` 同样可以创建支持 CephFS 的 `StorageClass` : ```yaml apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: csi-cephfs-sc provisioner: cephfs.csi.ceph.com parameters: fsName: myfs driverConfigMapName: csi-config-map reclaimPolicy: Retain allowVolumeExpansion: false volumeBindingMode: WaitForFirstConsumer ``` ##### (c) 测试 PVC 功能 为了验证配置是否成功,可以在同一命名空间下申请 PersistentVolumeClaim(PVC): ```yaml apiVersion: v1 kind: PersistentVolumeClaim metadata: name: test-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi storageClassName: csi-rbd-sc ``` 等待几分钟后查看状态变化情况: ```bash kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE test-pvc Bound pvc-d9e7d4df-f5cb-4fa6-a0bc-eaeacdbbbddd 1Gi RWO csi-rbd-sc 2m ``` 如果显示绑定完成则说明一切正常。 --- #### 4. 故障排查 当遇到某些特定错误时可参考如下建议解决办法: - 若发现 CSI 注册失败可能是由于 Linux Kernel 版本过高引起的问题[^3]; - 使用日志调试工具定位具体原因如 journalctl 或者 dmesg 查看是否有异常记录; - 参考官方文档获取更多帮助信息[^5]。 --- #### 5. 总结评价 作为一款成熟的开源软件产品,Ceph CSI 不仅提供了丰富的特性还保持良好的稳定性表现[^4]。无论是开发测试环境还是生产环境中都非常适用。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值