OpenStack 与 Ceph 对接配置

在 OpenStack + Ceph 环境中,与 Ceph 进行交互的 OpenStack 组件包括 Glance、Cinder、Nova,如下图所示(网络组件 Neutron 不涉及 Ceph,未在图中进行标注),各组件相互协作对外提供虚机服务。

其中:

  • Glance 为 Nova 提供镜像服务,如镜像上传、删除等,镜像存储在 Ceph 集群中;
  • Cinder 为 Nova 提供云盘服务,如云盘创建、删除等,云盘存储在 Ceph 集群中;
  • Nova 基于 Glance & Cinder 提供的存储服务,Neutron 提供的网络服务,以及自身提供的计算服务,对外提供虚机服务;
  • 虚机所需的根卷存储由 Glance 镜像、或者 Cinder 可启动云盘提供,用户数据存储由 Cinder 云盘提供;
  • Glance、Cinder 给虚机提供的是控制面服务,虚机的 IO 通过 qemu 的块设备层经由 rbd 驱动直接访问 Ceph 集群。

作为 Ceph 客户端,需要如下一些配置才能访问 Ceph 集群提供的存储服务:

  1. Ceph 配置文件,里面最重要的字段是 MON 地址的定义,客户端通过访问 MON 才能拿到集群的信息,从而访问存储
    相关的服务;
  2. Ceph 用户(即客户端 id),客户端通过自身的 id 区分配置文件中各自的配置选项;
  3. 在开启 cephx 认证 的情况下, Ceph 集群通过客户端 id 并结合认证密钥(key)实现集群访问的认证和权限管理,因此还需要通过 keyring 文件等方式给客户端提供密钥,当然在 Ceph 集群侧还要为该用户配置合适的访问权限;

显然,Glance、Cinder、Nova 每个组件都需要访问 Ceph 存储,似乎它们都需要 Ceph 相关的配置才能访问 Ceph 集群,事实上也确实是这样,下面分析一下这三个组件都需要配置 Ceph 存储的哪些参数。

Glance

~# vim /etc/glance/glance-api.conf
stores = rbd
default_store = rbd
rbd_store_chunk_size = 8
# 镜像存储所使用的存储池
rbd_store_pool = images
# Glance 访问镜像所用的 Ceph 用户
rbd_store_user = glance
# Ceph 配置文件
rbd_store_ceph_conf = /etc/ceph/ceph.conf
show_image_direct_url = True

Ceph 用户的密钥,可以在 Ceph 配置文件中指定,或者使用默认的 keyring 文件(如 /etc/ceph/ceph.client.<id>.keyring,/etc/ceph/ceph.keyring, /etc/ceph/keyring 等)。

由于 Glance 只需要访问镜像存储所属的存储池,因此配置 cephx 权限时只需要为该用户配置 images 存储池的权限。

Cinder

~# vim /etc/cinder/cinder.conf
[DEFAULT]
enabled_backends = ceph
glance_api_version = 2
...

[ceph]
volume_driver = cinder.volume.drivers.rbd.RBDDriver
# 最好不要配置,应该由 Ceph 客户端通过 rbd_ceph_conf 来获取(即 Ceph 配置文件名去掉 .conf 后缀)
rbd_cluster_name = ceph
# 当前后端所使用的存储池
rbd_pool = volumes
# Cinder 访问云盘所用的 Ceph 用户,同时也是 Nova 访问云盘所用的 Ceph 用户
rbd_user = cinder
# Ceph 配置文件
rbd_ceph_conf = /etc/ceph/ceph.conf
rbd_flatten_volume_from_snapshot = false
# rbd_user 所对应的 libvirt secret uuid,Nova 访问云盘需要,通过该 uuid 可以找到 libvirt 中保存的 Ceph 用户密钥
rbd_secret_uuid = 4b5fd580-360c-4f8c-abb5-c83bb9a3f964
rbd_max_clone_depth = 5
rbd_store_chunk_size = 4
rados_connect_timeout = -1

Cinder 支持多存储后端(可以是不同的 Ceph 存储池),不同的后端可以单独指定 Ceph 配置选项。

由于 Cinder 后端配置的 Ceph 用户会被 Nova 组件使用到,而 Nova 不直接使用 keyring 文件,因此该用户的 Ceph key 需要通过在 libvirt 中通过 virsh secret-define 命令进行注册,该命令返回的 uuid 就是上面的 rbd_scret_uuid 选项所指定的 uuid。

至于 Cinder 需要用到的 Ceph 用户密钥,和 Glance 的处理一致。

由于 Cinder 只需要访问云盘存储所属的存储池,因此配置 cephx 权限时只需要为该用户配置 volumes 存储池的权限。

Nova

~# vim /etc/nova/nova.conf
[libvirt]
images_type = rbd
# 虚机根卷存储所使用的存储池
images_rbd_pool = vms
# Ceph 配置文件
images_rbd_ceph_conf = /etc/ceph/ceph.conf
# Nova 访问镜像和虚机根卷所用的 Ceph 用户
rbd_user = cinder
# rbd_user 所对应的 libvirt secret uuid,Nova 访问镜像和虚机根卷需要,通过该 uuid 可以找到 libvirt 中保存的 Ceph 用户密钥
rbd_secret_uuid = 4b5fd580-360c-4f8c-abb5-c83bb9a3f964
disk_cachemodes="network=writeback"
inject_password = false
inject_key = false
inject_partition = -2
hw_disk_discard = unmap

注意从 OpenStack Pike 版本开始,Nova 自身配置文件中指定的 Ceph 配置文件、用户名和 uuid 只用来访问镜像和虚机根卷,Nova 访问云盘所需的 Ceph 用户和密钥完全由 Cinder 提供(参考 Nova 云盘驱动代码 LibvirtNetVolumeDriver::_set_auth_config_rbd 的注释),但是老的 OpenStack 版本在访问云盘时使用的用户名和 uuid 优先使用 Nova 自身配置文件中指定的参数,然后才是 Cinder 提供的。

这里有一个不合理的地方,Nova 实际上不应该感知底层存储的存在,不管是根卷还是云盘访问所需的信息都应该由 Glance 和 Cinder 提供,但由于 Glance 并没有提供足够多的信息,导致 Nova 从镜像创建虚机时,需要读取 Nova 自身的存储配置参数(从云盘创建虚机不需要,因为 Cinder 已经提供了足够的信息)。

注意到 Cinder 和 Nova 都使用 cinder 这个 Ceph 用户,而这个用户既要用于 Cinder 管理云盘,还要用于 Nova 从镜像创建并读写根卷,或从云盘创建并读写根卷,或直接读写云盘,因此配置 cephx 权限时需要为该用户配置 images、vms 以及 volumes 所有三个存储池的权限(当然由于对于 images 的访问是只读的,因此不需要写权限)。

代码实现

Cinder 提供给 Nova 的云盘信息:

cinder/volume/dirivers/rbd.py

class RBDDriver::initialize_connection

Nova 云盘驱动:

nova/virt/libvirt/volume/net.py

class LibvirtNetVolumeDriver::_set_auth_config_rbd

Nova 镜像驱动:

nova/virt/libvirt/imagebackend.py

class Rbd(Image)

参考资料

Secret XML format

https://libvirt.org/formatsecret.html

BLOCK DEVICES AND OPENSTACK

http://docs.ceph.com/docs/master/rbd/rbd-openstack/

What’s the difference between ephemeral and volume boot disks?

https://help.dreamhost.com/hc/en-us/articles/217701757-What-s-the-difference-between-ephemeral-and-volume-boot-disks-

INSTALLING AND CONFIGURING CEPH CLIENTS

https://access.redhat.com/documentation/en-us/red_hat_ceph_storage/3/html/ceph_block_device_to_openstack_guide/installing_and_configuring_ceph_clients

CONFIGURING OPENSTACK TO USE CEPH

https://access.redhat.com/documentation/en-us/red_hat_ceph_storage/3/html/ceph_block_device_to_openstack_guide/configuring_openstack_to_use_ceph


最后修改于 2019-02-26