Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Ceph Block Device Block device Operation

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the example analysis of Ceph Block Device block equipment operation, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.

Using ceph block device requires the following three steps:

1. Create a Block Device image in the pool of the ceph cluster.

2. Ceph Client uses RBD devices to map to the Block Device image of the ceph cluster (Map).

3. The User Space of ceph Client can mount (Mount) the RBD device.

Step1 creates Block Device Image

First, you need to create a new pool. If you don't want to create a new pool, you can use the default pool, rbd.

Command: ceph osd pool create

Parameter: creating_pool_name: name of the pool to be created

Pg_num: number of Placement Group

# ceph osd pool create testpool 512

Pool testpool' created

You need to create a Block Device Image in the ceph cluster (view the rbd command and enter the "man rbd" command)

Command: rbd create-- size {MegaBytes} {pool-name} / {image-name}

For example: create an Image of "bar" in a pool named "testpool" with a capacity of 1024MB

# rbd create-- size 1024 testpool/bar

View Block Device Images

# rbd ls testpool

Rbd

And view the details of a Block Device Images

# rbd info testpool/bar

Rbd image 'bar':

Size 1024 MB in 256 objects

Order 22 (4096 kB objects)

Block_name_prefix: rbd_data.5e3b248a65f6

Format: 2

Features: layering

Flags:

Step2 ceph Client uses RBD devices to map to the Block Device image of the ceph cluster (Map)

Command: sudo rbd map rbd/myimage-- id admin-- keyring / path/to/keyring

For example

# sudo rbd map testpool/bar-id admin-keyring / etc/ceph/ceph.client.admin.keyring

Dev/rbd0

View Block Device information that has been mapped

# rbd showmapped

Id pool image snap device

0 testpool bar-/ dev/rbd0

Step3 ceph Client's User Space mount (Mount) the RBD device

First, use the block device to create a file system on client-node.

# sudo mkfs.ext4-M0 / dev/rbd/testpool/bar

Mke2fs 1.42.9 (28-Dec-2013)

Discarding device blocks: done

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=1024 blocks, Stripe width=1024 blocks

65536 inodes, 262144 blocks

0 blocks (0.005%) reserved for the super user

First data block=0

Maximum filesystem blocks=268435456

8 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks:

32768, 98304, 163840, 229376

Allocating group tables: done

Writing inode tables: done

Creating journal (8192 blocks): done

Writing superblocks and filesystem accounting information: done

Second, mount the file system

# sudo mkdir / mnt/ceph-block-device

# sudo mount / dev/rbd/testpool/bar / mnt/ceph-block-device

View mount information

# mount

...

/ dev/rbd0 on / mnt/ceph-block-device type ext4 (rw,relatime,seclabel,stripe=1024,data=ordered)

* other related operations of Ceph Block Deviced

To create a new rbd image that is 100 GB:

Rbd create mypool/myimage-size 102400

To use a non-default object size (8 MB):

Rbd create mypool/myimage-size 102400-object-size 8m

To delete an rbd image (be careful!):

Rbd rm mypool/myimage

To create a new snapshot:

Rbd snap create mypool/myimage@mysnap

To create a copy-on-write clone of a protected snapshot:

Rbd clone mypool/myimage@mysnap otherpool/cloneimage

To see which clones of a snapshot exist:

Rbd children mypool/myimage@mysnap

To delete a snapshot:

Rbd snap rm mypool/myimage@mysnap

To map an image via the kernel with cephx enabled:

Rbd map mypool/myimage-id admin-keyfile secretfile

To map an image via the kernel with different cluster name other than default ceph.

Rbd map mypool/myimage-cluster cluster name

To unmap an image:

Rbd unmap / dev/rbd0

To create an image and a clone from it:

Rbd import-image-format 2 image mypool/parentrbd snap create mypool/parent@snaprbd snap protect mypool/parent@snaprbd clone mypool/parent@snap otherpool/child

To create an image with a smaller stripe_unit (to better distribute small writes in some workloads):

Rbd create mypool/myimage-size 102400-stripe-unit 65536B-stripe-count 16

To change an image from one image format to another, export it and then import it as the desired image format:

Rbd export mypool/myimage@snap / tmp/imgrbd import-- image-format 2 / tmp/img mypool/myimage2

To lock an image for exclusive use:

Rbd lock add mypool/myimage mylockid

To release a lock:

Rbd lock remove mypool/myimage mylockid client.2485 thank you for reading this article carefully. I hope the article "sample Analysis of Ceph Block Device Block device Operation" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report