Connecting and Configuring Ceph RBD Using a Linux Client
Ceph RBD (RADOS Block Device) offers users a network block device that appears as a local disk on the system where it is connected. The block device is entirely managed by the user, who can create a file system on it and use it according to his needs.
Advantages of RBD
- Ability to resize the block device image.
- Import / export of block device images.
- Stripping and replication within the cluster.
- Capability to create read-only snapshots and restore them (for RBD level snapshots, please contact us).
- Ability to connect using a Linux or QEMU KVM client
Setting Up the RBD Client (Linux)
To connect to RBD, it is recommended to use a newer kernel version on your system, as older kernel versions have deprecated RBD connection modules, meaning not all advanced features are supported. Developers suggest using at least kernel version 5.0 or higher. However, some functionalities have been backported to the CentOS 7 core.
Ceph client version For optimal functionality, it is highly recommended to use the same version of Ceph tools as the one currently running on our clusters. Then you can set up the appropriate repositories, as outlined below.
CentOS Setup
First, install the release.asc key for the Ceph repository.
In the directory /etc/yum.repos.d/ create a text file ceph.repo and fill in the record for Ceph instruments.
Some packages from the Ceph repository also require third-party libraries for proper functioning, so add the EPEL repository.
CentOS 7
CentOS 8
RedHat 7
Finally, install the basic tools for Ceph which also include RBD support.
CentOS 7
On CentOS 8
Ubuntu/Debian Setup
Ubuntu/Ceph includes all necessary packages natively, so you can just run following command:
RBD Configuration and Mapping
To configure and connect to RBD, use the credentials provided by the system administrator. The necessary details are as follows:
- pool name: rbd_vo_poolname
- image name: vo_name_username
- keyring: [client.rbd_user] key = key_hash ==
In the directory /etc/ceph/ create a text file ceph.conf with the following content.
CL1 Data Storage
CL2 Data Storage
CL3 Data Storage
CL4 Data Storage
CL5 Data Storage
Next, in the /etc/ceph/ directory, create a text file ceph.keyring. Then, save the keyring in that file, as shown in the example below.
If the files ceph.conf
and username.keyring
are located in a directory other than the default /etc/ceph/, you must specify the corresponding paths during the mapping process. See the example below.
Now, check the RBD status.
Encrypting and Creating a Filesystem
The next step is to encrypt the mapped image use cryptsetup-luks.
Then, it encrypts the device.
Finally, check the settings.
To perform further actions on an encrypted device, it must be decrypted first.
We recommend using XFS instead of EXT4 for larger images or those they may need to exceed 200TB over time, as EXT4 has a limit on the number of inodes.
Now, create file system on the device, here is an example xfs.
If you use XFS, do not use the nobarrier option while mounting, it could cause data loss!
Once the file system is ready, we can mount the device to a pre-created folder in /mnt/.
Ending the Work with RBD
Unmount the volume.
Close the encrypted volume.
Volume unmapping.
To optimize performance, choose an appropriate size for the read_ahead
cache based on your system´s memory size.
Example for 8GB:
Example for 512MB:
To apply the changes, you need to unmap the image and then map it again.
The method described above is not persistent (it will not survive a reboot). To make it persistent, you must add the following line to the “/etc/udev/rules.d/50-read-ahead-kb.rules” file.
You can configure specific kernel parameters for a subset of block devices (Ceph RBD)
Permanently Mapping RBD
Configuration for automatic RBD connection, including LUKS encryption and filesystem mounting, along with proper disconnection (in reverse order) when the machine is switched off in a controlled manner.
RBD Image
Edit the configuration file located at /etc/ceph/rbdmap
by adding the following lines.
LUKS
Edit configuration file located at /etc/crypttab
by adding the following lines.
where /etc/ceph/luks.keyfile
is a LUKS key.
Path to block device source device
is generally /dev/rbd/$POOL/$IMAGE
fstab file
Edit the configuration file located at /etc/fstab
by adding the following lines.
path to LUKS container (file system
) is generally /dev/mapper/$LUKS_NAME
, where $LUKS_NAME
is defined in /etc/crypttab
(like taget name
)
Systemd Unit
Edit the configuration file located at /etc/systemd/system/systemd-cryptsetup@rbd_luks_pool.service.d/10-deps.conf
by adding the following lines.
In one case, systemd units were used on Debian 10, but for some reason ceph-rbdmap.service
was used instead of rbdmap.service
(this must be adjusted in the lines After=
and Requires=
)
Manual Connection
If the systemd unit dependencies are correctly configured, it will performs the RBD mapping, unlock LUKS and mount all fs dependent on the rbdmap, as specified in the .mount unit needs (⇒ this will mount both images as described in the configuration).
Manual Disconnection
This command should execute correctly if the dependencies are set up properly, umount
, close
LUKS and unmap RBD.
Image Resize
When resizing an encrypted image, you need to follow the correct order, with the key step being the command cryptsetup --verbose resize image_name
.
Last updated on