libvirt 配置了 librbd 的 QEMU 接口,经过它能够在 OpenStack 中使用 Ceph 块设备镜像。Ceph 块设备镜像被看成集群对象,这意味着它比独立的服务器有更好的性能。 html
在 OpenStack 中使用 Ceph 块设备,必须首先安装 QEMU,libvirt 和 OpenStack。建议 OpenStack 安装的时候使用独立的物理节点。OpenStack 节点建议最小 8G RAM和四核处理器。下图描述了 OpenStack 和 Ceph 技术层次。 node
Important:要在 OpenStack 中使用 Ceph,必须首先运行 Ceph 存储集群 python
OpenStack 与 Ceph 的三个结合点: git
可使用 OpenStack Glance 来存储镜像在 Ceph 块设备中,也可使用 Cinder 经过镜像的写时复制来启动虚拟机。 github
下面详细介绍 Glance,Cinder 和 Nova 的配置过程,尽管它们没有必要一块儿使用。当虚拟机运行使用本地磁盘运行的时候,能够把镜像存储在 Ceph 块设备中,或者正相反。 后端
Important:Ceph 不支持 QCOW2 格式的虚拟机磁盘。因此,若是想要在 Ceph 中启动虚拟机(后端文件或者从卷启动),Glance 镜像必须是 RAW格式 api
Tip:本文档描述的 Ceph 块设备是基于 OpenStack Havana。更早的版本请看Block Devices and OpenStack (Dumpling)。
缓存
默认状况下,Ceph 块设备使用 rbd 池。可使用任何可以使用的池。建议为 Cinder 和 Glance 单首创建池。确保 Ceph 集群正常运行,而后建立池。 服务器
ceph osd pool create volumes 128 ceph osd pool create images 128 ceph osd pool create backups 128 ceph osd pool create vms 128 |
看 Create a Pool 和 Placement Groups 来了解指定池的 pg 数量的详细信息和应该为你的池指定多少 pg。 ssh
运行 glance-api,cinder-volume,nova-compute 和 cinder-backup 的节点是 Ceph 客户端。每个节点都须要 ceph.conf 文件:
ssh {your-openstack-server} sudo tee /etc/ceph/ceph.conf </etc/ceph/ceph.conf |
在 glance-api 节点,须要为 librbd 绑定 Python
sudo apt-get install python-ceph sudo yum install python-ceph |
在 nova-compute,cinder-backup 和 cinder-volume 节点要用到 Python 和 Ceph 客户端命令行工具:
sudo apt-get install ceph-common sudo yum install ceph |
若是使用了 cephx authentication,建立一个新用户为 Nova/Cinder 和 Glance。执行下面的命令:
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' ceph auth get-or-create client.glance mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=images' 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 添加密钥来访问节点并改变全部者:
ceph auth get-or-create client.glance | ssh {your-glance-api-server} sudo tee /etc/ceph/ceph.client.glance.keyring 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 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 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 的节点:
ceph auth get-key client.cinder | ssh {your-compute-node} tee client.cinder.key |
而后在计算节点,为 libvirt 添加密钥文件而且移除临时的副本密钥:
uuidgen 457eb676-33da-42ec-9a8c-9293d545c337 cat > secret.xml <<EOF <secret ephemeral='no' private='no'> <uuid>457eb676-33da-42ec-9a8c-9293d545c337</uuid> <usage type='ceph'> <name>client.cinder secret</name> </usage> </secret> EOF sudo virsh secret-define --file secret.xml Secret 457eb676-33da-42ec-9a8c-9293d545c337 created sudo virsh secret-set-value --secret 457eb676-33da-42ec-9a8c-9293d545c337 \ --base64 $(cat client.cinder.key) && rm client.cinder.key secret.xml |
Important:没有必要保存全部计算节点的 UUID。可是为了平台的一致性,最好保存相同的 UUID。
Glance 可以使用多种后端来存储镜像。默认使用 Ceph 块设备,配置 Glance 以下:
编辑 /etc/glance/glance-api.conf 而且添加下面的 [DEFAULT] 部分:
default_store = rbd rbd_store_user = glance rbd_store_pool = images rbd_store_chunk_size = 8 |
编辑 /etc/glance/glance-api.conf 而且添加 [glance_store] 部分:
[DEFAULT] ... default_store = rbd ... [glance_store] stores = rbd rbd_store_pool = images rbd_store_user = glance rbd_store_ceph_conf = /etc/ceph/ceph.conf rbd_store_chunk_size = 8 |
更多关于 Glance 的配置信息请看:http://docs.openstack.org/trunk/config-reference/content/section_glance-api.conf.html。
Important:Glance 尚未彻底移到 'store'。因此仍然须要在 DEFAULT 部分配置 store。
若是要启用镜像的写时复制功能,添加下面的 [DEFAULT] 部分:
show_image_direct_url = True |
注意这会在 Glance API 中暴露后端存储位置,因此 endpoint 不该该被公开访问
禁用 Glance 缓存管理来避免镜像被缓存到 /var/lib/glance/image-cache/,确保配置文件中有 flavor = keystone+cachemanagement:
[paste_deploy] flavor = keystone |
OpenStack 须要驱动来与 Ceph 块设备交互。必须为块设备指定池,在 OpenStack 节点编辑 /etc/cinder/cinder.conf 并添加:
volume_driver = cinder.volume.drivers.rbd.RBDDriver rbd_pool = volumes rbd_ceph_conf = /etc/ceph/ceph.conf rbd_flatten_volume_from_snapshot = false rbd_max_clone_depth = 5 rbd_store_chunk_size = 4 rados_connect_timeout = -1 glance_api_version = 2 |
OpenStack Cinder Backup 须要一个守护进程,不要忘记安装它。在 Cinder Backup 节点,编辑 /etc/cinder/cinder.conf 并添加:
backup_driver = cinder.backup.drivers.ceph backup_ceph_conf = /etc/ceph/ceph.conf backup_ceph_user = cinder-backup backup_ceph_chunk_size = 134217728 backup_ceph_pool = backups backup_ceph_stripe_unit = 0 backup_ceph_stripe_count = 0 restore_discard_excess_bytes = true |
配置 Nova 绑定 Ceph rbd 块设备
为了绑定 Cinder 设备(块设备或者启动卷),必须告诉 Nova(和 libvirt)用户和 UUID。libvirt 在与 Ceph 集群进行链接和认证的时候提供这个用户。
rbd_user = cinder rbd_secret_uuid = 457eb676-33da-42ec-9a8c-9293d545c337 |
这两个配置项一样用于 Nova 的后端。
为了直接从 Ceph 启动全部虚拟机,你必须配置 Nova 的临时后端。
建议在 Ceph 配置文件中启用 RBD 缓存(从 Giant 版本默认启用)。还有,启用 admin socket 对于故障排除的时候颇有帮助。每台使用 Ceph 块设备的虚拟机都有一个 socket 有助于性能分析和错误判断。
socket 能够经过这种方式访问:
ceph daemon /var/run/ceph/ceph-client.cinder.19195.32310016.asok help |
如今,在每一个计算节点编辑 Ceph 配置文件:
[client] rbd cache = true rbd cache writethrough until flush = true admin socket = /var/run/ceph/$cluster-$type.$id.$pid.$cctid.asok |
Tip:若是虚拟机正在运行,能够直接重启来得到 socket。
HAVANA 和 ICEHOUSE 须要补丁来实现写时复制而且修复 rbd 临时磁盘的镜像大小和热迁移 Bug。这些可用的分支基于主干 Nova stable/havana 和 stable/icehouse。使用它们不是强制性的可是是很是建议的,为了利用写时复制的功能。
在每一个计算节点,编辑 /etc/nova/nova.conf 而且添加:
libvirt_images_type = rbd
libvirt_images_rbd_pool = vms
libvirt_images_rbd_ceph_conf = /etc/ceph/ceph.conf
rbd_user = cinder
rbd_secret_uuid = 457eb676-33da-42ec-9a8c-9293d545c337 |
禁用文件注入也是一个好的习惯。启动一个实例的时候,Nova 一般试图去打开虚拟机的根文件系统。而后 Nova 注入值好比密码,ssh 密钥等,直接进入文件系统。然而,最好依赖元数据服务和 cloud-init。
在每一个计算节点,编辑 /etc/nova/nova.conf 而且添加:
libvirt_inject_password = false libvirt_inject_key = false libvirt_inject_partition = -2 |
确保热迁移,使用下面的标志:
libvirt_live_migration_flag="VIR_MIGRATE_UNDEFINE_SOURCE,VIR_MIGRATE_PEER2PEER,VIR_MIGRATE_LIVE,VIR_MIGRATE_PERSIST_DEST" |
在 Juno 版本,Ceph 块设备被移到 [libvirt] 部分。在每一个计算节点,编辑 /etc/nova/nova.conf 在 [libvirt] 部分添加:
[libvirt] images_type = rbd images_rbd_pool = vms images_rbd_ceph_conf = /etc/ceph/ceph.conf rbd_user = cinder rbd_secret_uuid = 457eb676-33da-42ec-9a8c-9293d545c337 |
禁用文件注入也是一个好的习惯。启动一个实例的时候,Nova 一般试图去打开虚拟机的根文件系统。而后 Nova 注入值好比密码,ssh 密钥等,直接进入文件系统。然而,最好依赖元数据服务和 cloud-init。
在每一个计算节点,编辑 /etc/nova/nova.conf 而且添加:
libvirt_inject_password = false libvirt_inject_key = false libvirt_inject_partition = -2 |
确保热迁移,使用下面的标志:
libvirt_live_migration_flag="VIR_MIGRATE_UNDEFINE_SOURCE,VIR_MIGRATE_PEER2PEER,VIR_MIGRATE_LIVE,VIR_MIGRATE_PERSIST_DEST" |
激活 Ceph 块设备驱动而且载入块设备池的名称到配置中,必须重启 OpenStack。基于 Debian 的系统执行这些命令:
sudo glance-control api restart sudo service nova-compute restart sudo service cinder-volume restart sudo service cinder-backup restart |
基于 Red Hat 的系统执行这些命令:
sudo service openstack-glance-api restart sudo service openstack-nova-compute restart sudo service openstack-cinder-volume restart sudo service openstack-cinder-backup restart |
OpenStack 启动并运行起来以后,就可以建立一个卷并从它启动。
使用下面的 Cinder 命令建立一个来自镜像的卷:
cinder create --image-id {id of image} --display-name {name of volume} {size of volume} |
注意镜像必须是 RAW 格式。可使用 qemu-img 转换镜像格式。例如:
qemu-img convert -f {source-format} -O {output-format} {source-filename} {output-filename} qemu-img convert -f qcow2 -O raw precise-cloudimg.img precise-cloudimg.raw |
当 Glance 和 Cinder 都使用 Ceph 块设备,镜像是写时复制的,因此建立一个新的卷很是迅速。在 OpenStack Dashboard 中,能够经过下面的步骤来从卷启动虚拟机: