這個是 Folsom 的隱藏新功能, 之前要做這件事都要做偷天換日的行為把 volume 的內容換掉, 但現在不必了, 這個功能已經整合進去 Folsom. 設定及操作都是參考以下這篇
http://ceph.com/docs/master/rbd/rbd-openstack/
Cinder Configuration
主要的安裝及設定請參考 openstack-folsom-installation-of-cinder/etc/cinder/cinder.conf
這邊因為 cinder 要和 glance 拿到 image template, 所以要在設定檔內加入 glance host 的 ip[DEFAULT] rootwrap_config = /etc/cinder/rootwrap.conf api_paste_confg = /etc/cinder/api-paste.ini sql_connection = mysql://cinder:password@localhost:3306/cinder iscsi_helper = tgtadm volume_name_template = volume-%s volume_group = cinder-volumes verbose = True auth_strategy = keystone state_path = /var/lib/cinder volume_driver=cinder.volume.driver.RBDDriver rabbit_host=rabbitmq rabbit_password = password my_ip = 172.17.123.12 glance_host = 172.17.123.16
Glance Configuration
主要的安裝及設定請參考 openstack-folsom-installation-of-glance/etc/glance/glance-api.conf
需要 glance 把 rbd url 傳送出去, 所以把這個隱藏選項打開show_image_direct_url = True
Upload Image
如果要直接從 Block Device 開機, 那原來的 image 的格式目前必須要是 raw image, 而不能用 qcow2. 所以我們先把 qcow2 轉成 raw image, 然後上傳到 glanceroot@glance:~$ wget http://uec-images.ubuntu.com/precise/current/precise-server-cloudimg-amd64-disk1.img root@glance:~$ kvm-img convert -f qcow2 -O raw precise-server-cloudimg-amd64-disk1.img precise-server-cloudimg-amd64-disk1.raw root@glance:~$ glance image-create --name Ubuntu-Precise-Raw --is-public true --container-format bare --disk-format raw < ./precise-server-cloudimg-amd64-disk1.raw root@glance:~$ glance image-list +--------------------------------------+---------------------+-------------+------------------+------------+--------+ | ID | Name | Disk Format | Container Format | Size | Status | +--------------------------------------+---------------------+-------------+------------------+------------+--------+ | cad779fc-c851-4581-ac4d-474c3773bf89 | Ubuntu-Precise-Raw | raw | bare | 2147483648 | active | +--------------------------------------+---------------------+-------------+------------------+------------+--------+
Create Volume from Image Template
接下來從 cinder 生成一個新的 volume, 但多加一個參數指定從 Image Template 產生root@cinder:~# cinder create --image-id cad779fc-c851-4581-ac4d-474c3773bf89 10 +---------------------+--------------------------------------+ | Property | Value | +---------------------+--------------------------------------+ | attachments | [] | | availability_zone | nova | | created_at | 2012-10-29T03:12:59.504616 | | display_description | None | | display_name | None | | id | 4e8527a9-eb01-44f1-8fed-fc831c4134f4 | | image_id | cad779fc-c851-4581-ac4d-474c3773bf89 | | metadata | {} | | size | 10 | | snapshot_id | None | | status | creating | | volume_type | None | +---------------------+--------------------------------------+ root@cinder:~# cinder list +--------------------------------------+-----------+----------------+------+-------------+--------------------------------------+ | ID | Status | Display Name | Size | Volume Type | Attached to | +--------------------------------------+-----------+----------------+------+-------------+--------------------------------------+ | 4e8527a9-eb01-44f1-8fed-fc831c4134f4 | available | None | 10 | None | | +--------------------------------------+-----------+----------------+------+-------------+--------------------------------------+ root@cinder:~# rbd info volume-4e8527a9-eb01-44f1-8fed-fc831c4134f4 rbd image 'volume-4e8527a9-eb01-44f1-8fed-fc831c4134f4': size 10240 MB in 1280 objects order 23 (8192 KB objects) block_name_prefix: rbd_data.2f8e5262f5ff format: 2 features: layering parent: images/cad779fc-c851-4581-ac4d-474c3773bf89@snap overlap: 2048 MB觀察 /var/log/cinder/cinder-volume.log
# 拿到 image location 2012-10-29 11:12:59 DEBUG cinder.volume.manager [req-eed17d93-f2da-479b-b04c-4418ca4948b3 fafd0583de8a4a1b93b924a6b2cb7e b5 eefa301a6a424e7da3d582649ad0e59e] image_location: rbd://77e083f7-de88-4f9e-b654-8ce6949a3039/images/cad779fc-c851-458 1-ac4d-474c3773bf89/snap create_volume /usr/lib/python2.7/dist-packages/cinder/volume/manager.py:151 2012-10-29 11:12:59 DEBUG cinder.utils [req-eed17d93-f2da-479b-b04c-4418ca4948b3 fafd0583de8a4a1b93b924a6b2cb7eb5 eefa30 1a6a424e7da3d582649ad0e59e] Running cmd (subprocess): ceph fsid execute /usr/lib/python2.7/dist-packages/cinder/utils.py :163 # 檢查一下 image 的 snapshot 2012-10-29 11:12:59 DEBUG cinder.utils [req-eed17d93-f2da-479b-b04c-4418ca4948b3 fafd0583de8a4a1b93b924a6b2cb7eb5 eefa30 1a6a424e7da3d582649ad0e59e] Running cmd (subprocess): rbd info --pool images --image cad779fc-c851-4581-ac4d-474c3773bf8 9 --snap snap execute /usr/lib/python2.7/dist-packages/cinder/utils.py:163 # 使用 ceph clone 功能 (COW) 2012-10-29 11:13:00 DEBUG cinder.utils [req-eed17d93-f2da-479b-b04c-4418ca4948b3 fafd0583de8a4a1b93b924a6b2cb7eb5 eefa30 1a6a424e7da3d582649ad0e59e] Running cmd (subprocess): rbd clone --pool images --image cad779fc-c851-4581-ac4d-474c3773bf 89 --snap snap --dest-pool rbd --dest volume-4e8527a9-eb01-44f1-8fed-fc831c4134f4 execute /usr/lib/python2.7/dist-packag es/cinder/utils.py:163 # 最後 resize 大小 2012-10-29 11:13:00 DEBUG cinder.utils [req-eed17d93-f2da-479b-b04c-4418ca4948b3 fafd0583de8a4a1b93b924a6b2cb7eb5 eefa301a6a424e7da3d582649ad0e59e] Running cmd (subprocess): rbd resize --pool rbd --image volume-4e8527a9-eb01-44f1-8fed-fc831c4134f4 --size 10240 execute /usr/lib/python2.7/dist-packages/cinder/utils.py:163
Create VM
選擇剛剛上傳的 Raw Image
觀察 computer node 上面的 VM, 發現他的 block device 直接從 rbd protocol 連到 Ceph.
root@nova:~$ virsh list Id Name State ---------------------------------- 1 instance-00000023 running 4 instance-0000002b running root@nova:~$ virsh domblklist 4 Target Source ------------------------------------------------ vda rbd/volume-4e8527a9-eb01-44f1-8fed-fc831c4134f4
補充
如果遇到 Glance 出問題, 有可能是介接的部份出問題, 但問題不大, 主要是要把 unicode 轉 str/usr/lib/python2.7/dist-packages/glance/store/rbd.py
with rados.Rados(conffile=self.conf_file, rados_id=self.user) as conn: with conn.open_ioctx(self.pool) as ioctx: if loc.snapshot: # 修改這行 with rbd.Image(ioctx, str(loc.image)) as image: try: # 修改這行 image.unprotect_snap(str(loc.snapshot)) except rbd.ImageBusy: log_msg = _("snapshot %s@%s could not be " "unprotected because it is in use") LOG.error(log_msg % (loc.image, loc.snapshot)) raise exception.InUseByStore() # 修改這行 image.remove_snap(str(loc.snapshot)) try: # 修改這行 rbd.RBD().remove(ioctx, str(loc.image)) except rbd.ImageNotFound: raise exception.NotFound( _('RBD image %s does not exist') % loc.image) except rbd.ImageBusy: log_msg = _("image %s could not be removed" "because it is in use") LOG.error(log_msg % loc.image) raise exception.InUseByStore()
沒有留言:
張貼留言