Ceph Deployment for Working with QEMU VMs
Overview
This document provides a step-by-step guide for deploying a Ceph storage cluster and integrating it with QEMU/KVM virtual machines. It covers the installation and configuration of Ceph using cephadm, adding hosts, deploying OSDs, creating pools and users, and preparing client machines. The guide also explains how to connect Ceph storage to virtual machines using libvirt and virt-manager, including moving existing VM images to Ceph and deploying new VMs from snapshots. This documentation is intended for administrators looking to leverage Ceph as a scalable, distributed storage backend for virtualization environments.
Setup Ceph Cluster
Install Cephadm 1
There are two primary methods to install cephadm: using the curl-based installation method or distribution-specific installation methods. This documentation focuses on the curl-based installation method. For distribution-specific installation instructions, please refer to the Ceph documentation.
Fetch build of cephadm
bashcurl --silent --remote-name --location https://github.com/ceph/ceph/raw/quincy/src/cephadm/cephadmEnsure cephadm is executable
bashchmod +x cephadmInstall cephadm command
bash./cephadm add-repo --release quincy ./cephadm install
Bootstrap Cluster 2
Connect to the desired node to run the bootstrapper. Note that running the bootstrapper will do the following:
- Creates a Mon and Mgr daemon for the new cluster on the local host.
- Generates a new SSH key for the Ceph cluster (
/root/.ssh/authorized_keys). - Writes a copy of the public key to
/etc/ceph/ceph.pub. - Writes a minimal configuration file to
/etc/ceph/ceph.conf. Needed to communicate with Ceph daemons. - Writes a copy of the
client.adminadministrative key to/etc/ceph/ceph.client.admin.keyring. - Adds the
_adminlabel to the local host. Any host with this label will get a copy of/etc/ceph/ceph.confand/etc/ceph/ceph.client.admin.keyring.
Run Bootstrapper.
bashcephadm bootstrap --mon-ip <Local_Host_IP>Example:
bashcephadm bootstrap --mon-ip 172.18.74.25 --allow-fqdn-hostname --cluster-network 192.168.74.0/24
Set Designated Monitor Subnet 3
To specify an IP subnet for Ceph monitor daemons, use this command in CIDR notation. This setting ensures that Cephadm deploys new monitor daemons exclusively on hosts within this subnet.
To execute ceph [options] [arguments], launch a ceph shell or use cephadm shell -- ceph [options] [arguments]. Run the following commands from the previously bootstrapped host.
Launch Ceph Shell.
bashcephadm shellSet designated public monitor subnet
bashceph config set mon public_network 172.18.74.0/24
Add Additional Hosts to the Cluster 4
To add a host into the Ceph cluster you must copy the public ssh key to the new host(s) as well as tell ceph to add the new host to the cluster:
Copy Cluster’s Public SSH Key to New Host
Use the following command structure.
bashssh-copy-id -f -i /etc/ceph/ceph.pub root@<Hostname>Example:
bashssh-copy-id -f -i /etc/ceph/ceph.pub root@host02.example.com ssh-copy-id -f -i /etc/ceph/ceph.pub root@host03.example.com
Tell Ceph Cluster to Add New Host
Use the following command structure.
bashceph orch host add <hostname> [IP] [--labels]Example:
bashceph orch host add host2.example.com 172.18.74.26 --labels _admin ceph orch host add host3.example.com 172.18.74.27 --labels _admin
Deploy OSDs 5
You can deploy OSDs in two ways:
Consume all Devices
To instruct Ceph to use all available and unused storage devices automatically, run the following command:
Apply OSD
bashceph orch apply osd --all-available-devices
Manually Set Specific Devices 6
To manually specify the devices on which OSDs will be deployed on a specific host, use the following command:
Create a yaml file (drivespec.yaml)
drivespec.yamlservice_type: osd service_id: osd_using_paths placement: host_pattern: host0*.example.com spec: data_devices: # Specify the data devices for the OSD. Stores primary data rotational: 1 # Match to HDDs db_devices: # Specify the db devices for the OSD. Stores metadata rotational: 0 # Match to SSDsApply OSD
Orch apply from inside of Ceph shell container
bashceph orch apply -i drivespec.yamlNote: You could apply the yaml from outside the Ceph shell container with the following command.
Orch apply from outside of Ceph shell container:
bashcephadm shell --mount /root/drivespec.yaml:/mnt/drivespec.yaml -- ceph orch apply -i /mnt/drivespec.yaml
Create RBD Pool
Pools are a logical partition that are used to store objects. Any pool that starts with . is reserved for Ceph operations. Run the following commands from within the Ceph shell container (cephadm shell).
Create OSD Pool 7
bashceph osd pool create {pool-name} [{pg-num} [{pgp-num}]] [replicated] [crush-rule-name] [expected-num-objects]Example
bashceph osd pool create rbd 1024 1024Associate pool with RBD application 8
bashceph osd pool application enable {pool-name} {application-name}Example
bashceph osd pool application enable rbd rbdInitialize the pool for use by RBD 9
bashrbd pool init <pool-name>Example:
rbd pool init rbd
Set Quota 10
In cases where you want to allow end-user groups to utilize your Ceph cluster for block storage, it is important to implement a way to limit their storage utilization to prevent overuse. You can achieve this by creating a new pool for each user group and specifying the max_bytes size to control the pool’s maximum allowable storage.
Run
set-quotacommandbashceph osd pool set-quota {pool-name} [max_objects {obj-count}] [max_bytes {bytes}]Example: Set “rbd” pool to have a max size of 10TB
bashceph osd pool set-quota rbd max_bytes 10000000000000
Create Client User 11
This section covers creating a user called qemu, applying capabilities (Ceph’s terminology for permissions), and creating a keyring file for the user account. This account will be used on client machines to run and interact with the environment without the possibility of using administrator privileges.
Open terminal of a Ceph host
Run
get-or-createcommandExample
bashceph auth get-or-create client.qemu mon 'profile rbd' osd 'profile rbd pool=rbd' mgr 'profile rbd pool=rbd'This command creates a user (client.qemu) with read/write permissions to the RBD pool.
Create user keyring file
bashceph auth get client.qemu -o /etc/ceph/ceph.client.qemu.keyring
Prepare Client Machine
Retrieve Keyring and Config files
To interact with the Ceph Cluster from a client node, authentication is required. Typically, this is accomplished using the ceph.client.{user}.keyring and ceph.conf files. By default, when executing a Ceph command, the system will search for these files in /etc/ceph/ unless specified otherwise.
Copy ceph.conf
bashscp root@host01.example.com:/etc/ceph/ceph.conf .Copy ceph.client.{user}.keyring
bashscp root@host01.example.com:/etc/ceph/ceph.client.qemu.keyring .
Install Ceph Client Package
To utilize Ceph commands a client machine needs to have the ceph-common package.
sudo yum install ceph-commonInstalling QEMU/KVM Packages
To run/emulate virtual machines the following packages should be installed.
sudo yum install qemu-kvm libvirt libvirt-daemon libvirt-daemon-config-networkRunning Virtual Machines (VMs) with libvirt
There are three scenarios administrators need to support when working with New VMs in the Ceph Cluster:
- Using an Existing VM Disk Image that is not stored on Ceph: If the user already has a virtual machine disk image (e.g., qcow2, raw) stored outside of Ceph.
- Using an Existing VM Disk Image Stored on Ceph as a Block Device: If the user’s virtual machine disk image is already stored on Ceph as a block device.
- Creating a New Virtual Machine: If the user doesn’t have a virtual machine.
Attach RBD to Virt-Manager
Create Secret 12
Generate a secret.
bashcat > secret.xml <<EOF <secret ephemeral='no' private='no'> <usage type='ceph'> <name>client.qemu secret</name> </usage> </secret> EOFDefine the secret.
bashsudo virsh secret-define --file secret.xmlOutput:
<secret UUID>Save the key string to a file.
Note that this command will only work if the client.admin keyring is on the local host. If the admin keyring is not there you can connect to a ceph cluster host and run the following command and then move the
*.keyfile to the client machine:bashceph auth get-key client.qemu | sudo tee client.qemu.keySet the UUID of the secret
bashsudo virsh secret-set-value --secret <secret UUID> --base64 $(cat client.qemu.key) && rm client.qemu.key secret.xml
Create Pool XML 13
Navigate to /etc/libvirt/storage
Create new pool rbd.xml (nano, vim, etc) 14
rbd.xml<pool type="rbd"> <name>rbd</name> <source> <name>rbd</name> <host name='host01.example.com' port='6789'/> <auth username='qemu' type='ceph'> <secret uuid='{uuid of secret}'/> </auth> </source> </pool>Create a persistent definition of storage pool.
bashvirsh pool-define rbd.xmlStart the RBD storage pool.
bashvirsh pool-start rbdVerify RBD pool shows active.
bashvirsh pool-list
Move/Convert VM Disk Image to Ceph Cluster 15
If you have an existing qcow file or another VM disk file that needs to be added to the Ceph Cluster, follow the procedure below to store the disk image on an RBD pool. Note Ceph recommends using the raw format for VM disk files.
qemu-img convert <file> rbd:<pool_name>/<new_image_name>Example:
qemu-img convert -f qcow2 -O raw windows_server_2022_2023_12_06.qcow2 rbd:rbd/windows2022-imgLaunch VM Image Stored on Ceph Cluster
Launch virt-manager
bashsudo virt-managerClick Create a new virtual machine
Select Import existing disk image
Click Forward
Click Browse…
Click rbd
Select windows2022-img
Click Choose Volume
Enter Microsoft Windows Server 2022 in “Choose the operating system you are installing” field.
Click Forward
Click Forward
Click Finish
Create New VM Image
Create Image RBD Pool 16
If you want to deploy a new OS image, you need to have a source from which to pull that image. For the best user experience, it is beneficial to have images where the OS is already installed, so the user doesn’t need to run through the ISO file installation. To achieve this, we will create a new pool called OS-Images. Once we have this pool, we will push our ready-to-deploy OS image to the OS-Images pool, create a snapshot of the image, and then protect the snapshot from deletion.
Create
OS-Imagepoolbashceph osd pool create OS-Images ceph osd pool application enable OS-Images rbd rbd pool init OS-ImagesAdd OS Image
bashqemu-img convert -f qcow2 -O raw windows_server_2022_2023_12_06.qcow2 rbd:OS-Images/windows2022Create Snapshot
bashrbd snap create OS-Images/windows2022@baseProtect Snapshot
bashrbd snap protect OS-Images/windows2022@base
Deploy New VM 17
To request a VM, a user will have the ability to utilize any of the offered operating systems that we have snapshotted in the OS-Images pool. Ensure users have read access to the OS-Images pool or wherever you have the VM snapshot stored. For example, the qemu user has the following capabilities:
caps: [mgr] profile rbd pool=rbd, profile rbd-read-only pool=OS-Images
caps: [mon] profile rbd
caps: [osd] profile rbd pool=rbd, profile rbd-read-only pool=OS-ImagesClone OS Snapshot
bashrbd clone {pool-name}/{parent-image-name}@{snap-name} {pool-name}/{child-image-name}Example:
bashrbd clone --id=qemu OS-Images/windows2022@base rbd/TestClone