配置Ceph集群为OpenStack后端存储

配置Ceph存储OpenStack的后端存储

1  前期配置

Ceph官网提供的配置Ceph块存储为OpenStack后端存储的文档说明链接地址:http://docs.ceph.com/docs/master/rbd/rbd-openstack/

1.1  注意点

1)OpenStack的节点使用的Ceph客户端的版本应该跟Ceph节点使用的Ceph版本一致,不然可能会出现类似Functional not supported的问题,这里我使用的Ceph版本是0.94.10版本的。

2)OpenStack节点Ceph客户端访问集群的网络配置应该跟Ceph集群的前端网络在同一个网段。

3)OpenStack节点和Ceph节点都先关闭掉防火墙,以免出现不可思议的问题。

4)OpenStack节点和Ceph节点的时间都应该准确,尽可能时间同步。

1.2  创建存储池

ceph osd pool create volumes 128

ceph osd pool create images 128

ceph osd pool create backups 128

ceph osd pool create vms 128

1.3  安装Ceph客户端包

在运行着glance-api、cinder-volume、nova-compute或cinder-backup的主机上进行安装:

最好别使用 yum -y install python-rbd ceph这种方式,因为这种方式取得的都是最新版本的发布包,可能跟你ceph集群的ceph服务版本不一致,可以使用命令ceph --version查看ceph的版本。

OpenStack节点和Ceph节点安装的Ceph包都是使用我自己之前编译好的rpm包进行安装的,所以版本肯定是一致的。

<3>生成配置文件

Ceph存储的管理节点上(有mon的其中一个节点即可,这里我们是使用compute1节点),将配置文件同步到OpenStack节点上。

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

1.4  配置ceph客户端认证

如果ceph启用了客户端认证,则需要为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的节点,其进程需要密钥环文件:

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

还得把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)

保留密钥的 uuid ,稍后配置 nova-compute 时要用。

 

2  配置Ceph为glance镜像的后端存储

编辑/etc/glance/glance-api.conf

[glance_store]

stores = rbd

default_store = rbd

rbd_store_pool = images

rbd_store_user = glance

rbd_store_ceph_conf = /etc/ceph/ceph.conf

rbd_store_chunk_size = 8

如果你想允许用image的写时复制克隆,再添加下列内容到[DEFAULT]段下:

show_image_direct_url = True

建议把如下属性也加上,加到[default]下:

hw_scsi_model=virtio-scsi    #添加 virtio-scsi 控制器以获得更好的性能、并支持 discard 操作

hw_disk_bus=scsi             #把所有 cinder 块设备都连到这个控制器;

hw_qemu_guest_agent=yes      #启用 QEMU guest agent (访客代理)

os_require_quiesce=yes       #通过 QEMU guest agent 发送fs-freeze/thaw调用

重启glance API服务:

systemctl restart openstack-glance-api.service openstack-glance-registry.service

测试下上传镜像:

如果镜像cirros-0.3.5-x86_64-disk.img是qcow2格式的,可以先将它转换成raw格式的,因为如果要使用ceph作为后端存储,就应该将它的镜像格式转为raw:

可以使用命令qemu-img info cirros-0.3.5-x86_64-disk.img查看它是什么格式的,使用命令将它从qcow2格式转换成raw格式并保存成另外一个镜像文件:

qemu-img convert -f qcow2 -O raw cirros-0.3.5-x86_64-disk.img image.img

以下进行上传镜像操作:

. admin-openrc.sh

glance image-create --name "imagetest" --file image.img --disk-format raw --container-format bare --visibility public --progress

使用如下命令验证是否创建成功:

openstack image list

 

3  配置Ceph为Cinder卷的后端存储

OpenStack需要一个驱动和Ceph块设备交互。还得指定块设备所在的存储池名。编辑OpenStack节点上的/etc/cinder/cinder.conf,添加如下内容:

[DEFAULT]

enabled_backends = ceph

[ceph]

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

rbd_user = cinder

rbd_secret_uuid = 43f7430d-cce0-46eb-a0fc-a593e27878c2

配置cinder backup:

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

rbd_user = cinder rbd_secret_uuid = 457eb676-33da-42ec-9a8c-9293d545c337

在控制节点上重启服务:

systemctl restart openstack-glance-api.service

systemctl restart openstack-cinder-volume.service

systemctl restart openstack-cinder-backup.service

在控制节点查看是否配置正常:

cinder-manage service list

以下为输出结果:

二进制 主机 状态 状态 已更新于 RPC 版本 对象版本 集群

cinder-backup controller nova enabled :-) 2017-11-14 01:46:36 3.5 1.21

cinder-scheduler controller nova enabled :-) 2017-11-14 01:46:36 3.5 1.21 

cinder-volume controller@ceph nova enabled :-) 2017-11-14 01:46:42 3.10 1.21

 

4 配置Ceph为Nova虚拟机boot disk的后端存储

注意修改rbd_secret_uuid为你自己上面创建的uuid,可以使用该命令查看:virsh secret-list

编辑所有计算节点上的/etc/nova/nova.conf文件的[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 disk_cachemodes="network=writeback"

inject_password = false

inject_key = false inject_partition = -2

live_migration_flag="VIR_MIGRATE_UNDEFINE_SOURCE,VIR_MIGRATE_PEER2PEER,VIR_MIGRATE_LIVE,VIR_MIGRATE_PERSIST_DEST,VIR_MIGRATE_TUNNELLED"

hw_disk_discard = unmap # 启用 discard 功能(注意性能)

编辑所有计算节点上的 Ceph 配置文件/etc/ceph/ceph.conf):

[client]

rbd cache = true

rbd cache writethrough until flush = true

rbd concurrent management ops = 20

在计算节点上重启服务:

systemctl restart openstack-nova-compute.service

原文地址:https://www.cnblogs.com/luohaixian/p/8082069.html