如何使用Ceph块设备增强OpenStack云环境 下载本文

内容发布更新时间 : 2024/5/3 11:19:56星期一 下面是文章的全部内容请认真阅读。

教你如何使用Ceph块设备增强OpenStack云环境

也许Ceph最有意思的部分就是同OpenStack的集成了。libvirt 配置了 librbd 的 QEMU 接口,通过它可以在 OpenStack 中使用 Ceph 块设备镜像。Ceph 块设备镜像被当作集群对象,这意味着它比独立的服务器有更好的性能。

在 OpenStack 中使用 Ceph 块设备,必须首先安装 QEMU,libvirt 和 OpenStack。建议 OpenStack 安装的时候使用独立的物理节点。OpenStack 节点建议最小 8G RAM和四核处理器。下图描述了 OpenStack 和 Ceph 技术层次。

Important:要在 OpenStack 中使用 Ceph,必须首先运行 Ceph 存储集群

OpenStack 与 Ceph 的三个结合点:

? ? ?

镜像:OpenStack Glance 管理虚拟机镜像。镜像是不变的。OpenStack 把镜像当作二进制对象并以此格式下载。

卷:卷是块设备。OpenStack 使用卷来启动虚拟机,或者绑定卷到运行中的虚拟机。OpenStack 使用 Cinder 服务管理卷。

客户磁盘:客户磁盘是客户操作系统磁盘。默认情况下,当启动一台虚拟机时,它的系统盘以文件的形式出现在 hypervisor 系统上(通常在/var/lib/nova/instances/)。在 OpenStack Havana 以前的版本,在 Ceph 中启动虚拟机的唯一方式是使用 Cinder 的 boot-from-volume 功能,现在能够在 Ceph 中直接启动虚拟机而不用依赖于 Cinder,这是非常有利的因为它能够让你很容易的进行虚拟机的热迁移。除此之外,如果 hypervisor 挂掉还能够方便地触发 nova evacute 然后无缝得在其他的地方继续运行虚拟机。

可以使用 OpenStack Glance 来存储镜像在 Ceph 块设备中,也可以使用 Cinder 通过镜像的写时复制来启动虚拟机。

下面详细介绍 Glance,Cinder 和 Nova 的配置过程,尽管它们没有必要一起使用。当虚拟机运行使用本地磁盘运行的时候,可以把镜像存储在 Ceph 块设备中,或者正相反。

Important:Ceph 不支持 QCOW2 格式的虚拟机磁盘。所以,如果想要在 Ceph 中启动虚拟机(后端文件或者从卷启动),Glance 镜像必须是 RAW格式

Tip:本文档描述的 Ceph 块设备是基于 OpenStack Havana。更早的版本请看Block Devices and OpenStack (Dumpling)。 创建一个池

默认情况下,Ceph 块设备使用 rbd 池。可以使用任何能够使用的池。建议为 Cinder 和 Glance 单独创建池。确保 Ceph 集群正常运行,然后创建池。

1. 2.

ceph osd pool create volumes 128 ceph osd pool create images 128

3. 4.

ceph osd pool create backups 128 ceph osd pool create vms 128

看 Create a Pool 和 Placement Groups 来了解指定池的 pg 数量的详细信息和应该为你的池指定多少 pg。

配置 OpenStack Ceph 客户端

运行 glance-api,cinder-volume,nova-compute 和 cinder-backup 的节点是 Ceph 客户端。每一个节点都需要 ceph.conf 文件:

1. ssh {your-openstack-server} sudo tee /etc/ceph/ceph.conf

安装 Ceph 客户端包

在 glance-api 节点,需要为 librbd 绑定 Python

1. 2.

sudo apt-get install python-ceph sudo yum install python-ceph

在 nova-compute,cinder-backup 和 cinder-volume 节点要用到 Python 和 Ceph 客户端命令行工具:

1. 2.

sudo apt-get install ceph-common sudo yum install ceph

设置 Ceph 客户端认证

如果使用了 cephx authentication,创建一个新用户为 Nova/Cinder 和 Glance。执行下面的命令:

1. ceph auth get-or-create client.cinder mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=volumes, allow rwx pool=vms, allow rx pool=images'

2. ceph auth get-or-create client.glance mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=images'

3. ceph auth get-or-create client.cinder-backup mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=backups'

为 client.cinder,client.glance 和 client.cinder-backup 添加密钥来访问节点并改变所有者:

1. ceph auth get-or-create client.glance | ssh {your-glance-api-server} sudo tee /etc/ceph/ceph.client.glance.keyring

2. 3.

ssh {your-glance-api-server} sudo chown glance:glance /etc/ceph/ceph.client.glance.keyring

ceph auth get-or-create client.cinder | ssh {your-volume-server} sudo tee /etc/ceph/ceph.client.cinder.keyring

4. 5.

ssh {your-cinder-volume-server} sudo chown cinder:cinder /etc/ceph/ceph.client.cinder.keyring

ceph auth get-or-create client.cinder-backup | ssh {your-cinder-backup-server} sudo tee /etc/ceph/ceph.client.cinder-backup.keyring

6. ssh {your-cinder-backup-server} sudo chown cinder:cinder /etc/ceph/ceph.client.cinder-backup.keyring

运行 nova-compute 的节点 nova-compute 进程需要密钥文件。它们也存储 client.cinder 用户的密钥在 libvirt。libvirt 进程在 Cinder 中绑定块设备时需要用到它来访问集群。

创建一个临时的密钥文件副本在运行 nova-compute 的节点:

1. ceph auth get-key client.cinder | ssh {your-compute-node} tee client.cinder.key

然后在计算节点,为 libvirt 添加密钥文件并且移除临时的副本密钥:

1. 2. 3. 4. 5. 6. 7. 8. 9.

uuidgen

457eb676-33da-42ec-9a8c-9293d545c337

cat > secret.xml <

457eb676-33da-42ec-9a8c-9293d545c337

client.cinder secret

10. 11. EOF

12. sudo virsh secret-define --file secret.xml

13. Secret 457eb676-33da-42ec-9a8c-9293d545c337 created

14. sudo virsh secret-set-value --secret 457eb676-33da-42ec-9a8c-9293d545c337 \\ 15. --base64 $(cat client.cinder.key) && rm client.cinder.key secret.xml

Important:没有必要保存所有计算节点的 UUID。但是为了平台的一致性,最好保存相同的 UUID。

配置 OpenStack 使用 Ceph

配置 Glance

Glance 能够使用多种后端来存储镜像。默认使用 Ceph 块设备,配置 Glance 如下:

Juno 之前的版本

编辑 /etc/glance/glance-api.conf 并且添加下面的 [DEFAULT] 部分:

1. default_store = rbd rbd_store_user = glance rbd_store_pool = images rbd_store_chunk_size = 8

Juno

编辑 /etc/glance/glance-api.conf 并且添加 [glance_store] 部分:

1. 2. 3.

[DEFAULT] ...

default_store = rbd