配置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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM