此内容没有您所选择的语言版本。

Chapter 6. QEMU


One of the use cases for Ceph Block Devices involves providing block device images to virtual machines. For example, a user may create a "golden" image with an operating system and any relevant software in an ideal configuration. Then, the user takes a snapshot of the image. Finally, the user clones the snapshot, typically many times. The ability to make copy-on-write clones of a snapshot means that Ceph can provision block device images to virtual machines quickly, because the client doesn’t have to download an entire image each time it spins up a new virtual machine. See Chapter 3, Snapshots for more details. Ceph Block Devices can integrate with the QEMU virtual machine.

Important

To use Ceph Block Devices with QEMU, you must have access to a running Ceph storage cluster.

6.1. Quick Start

A storage pool, a RBD image and a client key will need to be created to host the virtual machines images. Perform the following commands from a Ceph Monitor or a Ceph client node.

  1. Create a storage pool:

    Syntax

    # ceph osd pool create <pool_name> <pg_num> [<pgp_num>]
    Copy to Clipboard Toggle word wrap

    Example

    # ceph osd pool create libvirt-pool 128 128
    Copy to Clipboard Toggle word wrap

  2. Create a RBD image for the virtual machine:

    Syntax

    # rbd create <image_name> --size <megabytes> --pool <pool-name> --image-format 2
    Copy to Clipboard Toggle word wrap

    Example

    # rbd create librbd --size 13240 --pool libvirt-pool --image-format 2
    Copy to Clipboard Toggle word wrap

  3. Create a Ceph user and add capabilities:

    Syntax

    # ceph auth get-or-create client.<user_name> <daemon_type> 'allow <capability>' [<daemon_type> 'allow <capability> pool=<pool_name>']
    Copy to Clipboard Toggle word wrap

    Example

    # ceph auth get-or-create client.libvirt mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=libvirt-pool'
    Copy to Clipboard Toggle word wrap

  4. Verify the user’s authentication key and capabilities:

    Exmaple

    # ceph auth list client.libvirt
    
    client.libvirt
           key: AQC/+EhVmQ+NOxAA0OZAEXBSR0pD3gDPwxrFDA==
           caps: [mon] allow r
           caps: [osd] allow class-read object_prefix rbd_children, allow rwx pool=libvirt-pool
    Copy to Clipboard Toggle word wrap

    Note

    Make note of the client.libvirt key.

On the client node, verify that KVM/QEMU packages are installed and the libvirtd service is running. See the Red Hat Enterprise Linux Virtualization Deployment and Administration Guide for more details. Also, verify that the latest ceph-common package is installed. See the Red Hat Ceph Storage Installation Guide for more details. Then create a virtual machine, but do not add any storage devices to the virtual machine. If the virtual machine powers on after creation, then power off the virtual machine before editing.

  1. Edit the virtual machine configuration:

    Syntax

    # virsh edit <VM_name>
    Copy to Clipboard Toggle word wrap

    Exmaple

    # virsh edit example-vm
    Copy to Clipboard Toggle word wrap

  2. Add the new RBD image to the virtual machine configuration. Append the following code block to the end of the virtual machine configuration. Substitute the Ceph Monitor for the <monitor_host_name> variable:

    Example

    <disk type='network' device='disk'>
          <source protocol='rbd' name='libvirt-pool/librbd'>
                <host name='<monitor_host_name>' port='6789'/>
          </source>
          <target dev='vda' bus='virtio'/>
    </disk>
    Copy to Clipboard Toggle word wrap

  3. Create a secret.xml file using the client.libvirt user:

    Example

    # cat > secret.xml <<EOF
    <secret ephemeral='no' private='no'>
          <usage type='ceph'>
                <name>client.libvirt secret</name>
          </usage>
    </secret>
    EOF
    Copy to Clipboard Toggle word wrap

  4. Define the secret:

    Example

    # virsh secret-define --file secret.xml
    Copy to Clipboard Toggle word wrap

    Note

    Make note of the generated UUID that is returned. This will be used to set the secret.

  5. Set the UUID:

    Syntax

    # virsh secret-set-value --secret <uuid_from_previous_step> --base64 <ceph_user_key>
    Copy to Clipboard Toggle word wrap

    Example

    # virsh secret-set-value --secret 727c2e12-a6ac-4f57-a553-8b6fd13a1da9 --base64 AQC/+EhVmQ+NOxAA0OZAEXBSR0pD3gDPwxrFDA==
    Copy to Clipboard Toggle word wrap

  6. Edit the virtual machine configuration and add authentication block to the disk block:

    Authentication Block Example

    <auth username='libvirt'>
          <secret type='ceph' uuid='727c2e12-a6ac-4f57-a553-8b6fd13a1da9'/>
    </auth>
    Copy to Clipboard Toggle word wrap

    Full Disk Block Example

    <disk type='network' device='disk'>
          <driver name='qemu' type='raw'/>
              <auth username='libvirt'>
                  <secret type='ceph' uuid='727c2e12-a6ac-4f57-a553-8b6fd13a1da9'/>
              </auth>
          <source protocol='rbd' name='libvirt-pool/librbd'>
              <host name='MON1' port='6789'/>
          </source>
          <target dev='vda' bus='virtio'/>
    </disk>
    Copy to Clipboard Toggle word wrap

  7. Start the virtual machine and install an operating system.
Important

Configuring the authentication is required for each KVM/QEMU client.

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat