OpenStack有3个组件可以使用Ceph:
1. Glance:Glance可以把镜像存储在Ceph上;
2. Cinder:Cinder负责管理volume,把volume挂载给instance使用或者直接从volume启动instance。集成Ceph后可以让Cinder在Ceph上创建volume;
3. Nova:在OpenStack Havana版本开始,Nova可以直接把instance的disk存放在Ceph上。
下面记录了如何把这些组件改造为使用Ceph。
环境介绍:
OpenStack Queens版本,1台控制节点controller,1台计算节点compute;
操作系统:CentOS 7.5
Ceph版本12.2.4,luminous
第一步,创建存储池
在Ceph集群上总共创建3个存储池,分别给Glance,Cinder和Nova使用,
[root@ceph1 ~]# ceph osd pool create images 192 #Glance的存储池 [root@ceph1 ~]# ceph osd pool create volumes 192 #Cinder的存储池 [root@ceph1 ~]# ceph osd pool create vms 192 #Nova的存储池 |
第二步,配置OpenStack的Ceph客户端
1. 拷贝ceph.conf
把Ceph的配置文件/etc/ceph/ceph.conf拷贝到2台OpenStack节点上,控制节点和计算节点都需要,因为他们都要跟Ceph通信。
2. 安装软件包
在控制节点安装python-rbd和ceph软件包:
[root@controller ~]# yum install -y python-rbd ceph |
在计算节点安装ceph:
[root@compute ~]# yum install -y ceph |
如果不安装ceph,OpenStack在使用Ceph时会报找不到ceph命令。
3. 配置cephx认证
#创建client.cinder用户给Cinder和Nova使用,cinder用户有存储池volumes、vms和images的所有权限 [root@ceph1 ~]# 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' #创建client.glance用户给Glance使用,glance用户有存储池images的所有权限 [root@ceph1 ~]# ceph auth get-or-create client.glance mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=images' |
生成2个用户的密钥文件,
[root@ceph1 ~]# ceph auth get-or-create client.cinder > /etc/ceph/ceph.client.cinder.keyring [root@ceph1 ~]# ceph auth get-or-create client.glance > /etc/ceph/ceph.client.glance.keyring |
然后把/etc/ceph/ceph.client.cinder.keyring和/etc/ceph/ceph.client.glance.keyring拷到controller的/etc/ceph下,并且修改文件权限:
[root@controller ~]# chown cinder:cinder /etc/ceph/ceph.client.cinder.keyring [root@controller ~]# chown glance:glance /etc/ceph/ceph.client.glance.keyring |
把/etc/ceph/ceph.client.cinder.keyring拷到compute的/etc/ceph下,并且修改文件权限:
[root@compute ~]# chown nova:nova /etc/ceph/ceph.client.cinder.keyring |
4. 配置compute节点的libvirt
在ceph上获取client.cinder的key
[root@ceph1 ~]# ceph auth get-key client.cinder > client.cinder.key |
把client.cinder.key拷到compute节点的/etc/ceph下,在compute节点上执行以下步骤:
[root@compute ~]# cat > secret.xml <<EOF <secret ephemeral='no' private='no'> <uuid>e21a123a-31f8-425a-86db-7204c33a6161</uuid> <usage type='ceph'> <name>client.cinder secret</name> </usage> </secret> EOF [root@compute ~]# virsh secret-define --file secret.xml [root@compute ~]# virsh secret-set-value --secret e21a123a-31f8-425a-86db-7204c33a6161 --base64 $(cat /etc/ceph/client.cinder.key) && rm client.cinder.key secret.xml |
第三步,配置Glance
修改glance-api.conf,
[DEFAULT] ...... default_store = rbd [glance_store] stores = rbd rbd_store_chunk_size = 8 rbd_store_pool = images rbd_store_user = glance rbd_store_ceph_conf = /etc/ceph/ceph.conf |
重启Glance服务,
[root@controller ~]# systemctl restart openstack-glance-api openstack-glance-registry |
第四步,配置Cinder
修改cinder.conf,
[DEFAULT] ...... enabled_backends = ceph [ceph] rbd_pool = volumes rbd_user = cinder rbd_ceph_conf = /etc/ceph/ceph.conf rbd_flatten_volume_from_snapshot = false rbd_secret_uuid = e21a123a-31f8-425a-86db-7204c33a6161 rbd_max_clone_depth = 5 rbd_store_chunk_size = 4 rados_connect_timeout = -1 volume_driver = cinder.volume.drivers.rbd.RBDDriver volume_backend_name = ceph |
重启Cinder服务,
[root@controller ~]# systemctl restart openstack-cinder-api openstack-cinder-volume |
第五步,配置Nova
修改compute节点的nova.conf,
[libvirt] virt_type=kvm inject_password=false inject_key=false inject_partition=-2 disk_cachemodes = "network=writeback" images_type=rbd images_rbd_pool=vms images_rbd_ceph_conf = /etc/ceph/ceph.conf hw_disk_discard=unmap rbd_user=cinder rbd_secret_uuid=e21a123a-31f8-425a-86db-7204c33a6161 |
重启nova-compute服务,
[root@compute ~]# systemctl restart openstack-nova-compute |
第六步,验证
创建测试镜像,
[root@controller ~]# wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img #Glance以Ceph RBD为后端存储时只支持raw格式,不是raw格式创建实例时会出错 [root@controller ~]# qemu-img convert -f qcow2 -O raw cirros-0.4.0-x86_64-disk.img cirros-0.4.0-x86_64-disk.raw [root@controller ~]# openstack image create "cirros" --file cirros-0.4.0-x86_64-disk.raw --disk-format raw --container-format bare --public |
有两种在Ceph上启动实例的方式:
1. 以镜像为基础创建可启动的卷,然后启动实例时选择boot-from-volume,选择此卷;
2. 直接使用镜像创建实例,这种用法是Havana版本后才支持的。
第一种情况的测试:
1. 创建卷
2. 创建实例时source选择volume,
创建成功,
第二种情况:
创建实例,source选择image,
创建成功,