小編給大家分享一下如何配置sheepdog作為openstack Cinder的存儲(chǔ)后端,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
在慶元等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作按需求定制設(shè)計(jì),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計(jì),全網(wǎng)整合營(yíng)銷推廣,外貿(mào)網(wǎng)站建設(shè),慶元網(wǎng)站建設(shè)費(fèi)用合理。
Cinder是Openstack的Software Defined Storage(SDS)開源方案,支持多種存儲(chǔ)后端。其中就包括sheepdog,一種分布式的開源塊設(shè)備。具有具有零配置、Thin-Provision、高可靠、智能節(jié)點(diǎn)管理、容量線性擴(kuò)展、虛擬機(jī)感知(底層支持冷熱遷移和快照、克隆等)、支持計(jì)算與存儲(chǔ)混合架構(gòu)的特點(diǎn)等,可擴(kuò)展到上千級(jí)別的物理節(jié)點(diǎn)。
1. Openstack環(huán)境說(shuō)明
開始研究openstack的第一步當(dāng)然是安裝openstack。 對(duì)于一般用戶來(lái)說(shuō),最方便的獲取openstack環(huán)境就是直接使用各大linux 發(fā)行版的openstack package。Ubuntu,F(xiàn)edora/Centos/RHEL, SUSE都已經(jīng)作了大量打包工作。
例如 Redhat的PDO: http://openstack.redhat.com/Quickstart
http://docs.openstack.org/trunk/install-guide/install/yum/content/
對(duì)于開發(fā)者開說(shuō),最好是使用devstack,它是一整套的BASH腳本,從源碼一步步的部署好openstack 開發(fā)環(huán)境,因此升級(jí)到最新代碼相當(dāng)方便。
2. 安裝sheepdog
參考官方wiki: https://github.com/sheepdog/sheepdog/wiki/Getting-Started
sheepdog和qemu項(xiàng)目高度集成,可以直接支持qemu的后端存儲(chǔ)。
例如:
qemu-system-x86_64 -drive file=sheepdog:192.168.10.2:7000:Alice
意思是啟動(dòng)一個(gè)虛擬機(jī),后端的文件位于192.168.10.2這臺(tái)sheepdog cluster node上的Alice VDI
因?yàn)閟heepdog沒(méi)有自己開發(fā)集群管理,依賴的是corosync。所以務(wù)必安裝wiki的說(shuō)明源碼安裝,并保證服務(wù)啟動(dòng)。
否則sheepdog daemon會(huì)啟動(dòng)不了
[root@fedora ~]# cat /var/log/sheepdog/sheep.log Mar 25 22:56:53 INFO [main] md_add_disk(337) /var/log/sheepdog/obj, vdisk nr 68, total disk 1 Mar 25 22:56:55 ERROR [main] corosync_init(733) failed to initialize cpg (6) - is corosync running? Mar 25 22:56:55 ERROR [main] main(867) failed to create sheepdog cluster
3. Congiure Cinder use sheepdog as back-end storage driver
修改Cinder的配置文件,默認(rèn)的比如“/etc/cinder/cinder.conf”
volume_driver=cinder.volume.drivers.sheepdog.SheepdogDriver
修改后,重啟cinder服務(wù) openstack-service restart cinder
4. 創(chuàng)建一個(gè)Cinder volume
我這里測(cè)試的是把一個(gè)glance image轉(zhuǎn)化成bootable volume
[ray@fedora cinder]$ cinder create --image-id 285ac2bf-e2d4-4bbd-b438-f2fa4f24bb27 --display-name CirrosBootVol 2 +---------------------+--------------------------------------+ | Property | Value | +---------------------+--------------------------------------+ | attachments | [] | | availability_zone | nova | | bootable | false | | created_at | 2014-03-26T14:55:50.631075 | | display_description | None | | display_name | CirrosBootVol | | id | 1e3eb4f2-c60c-4eeb-9bc0-41f1afe7c911 | | image_id | 285ac2bf-e2d4-4bbd-b438-f2fa4f24bb27 | | metadata | {} | | size | 2 | | snapshot_id | None | | source_volid | None | | status | creating | | volume_type | None | +---------------------+--------------------------------------+ [ray@fedora post]$ cinder list +--------------------------------------+----------------+-----------------+------+-------------+----------+--------------------------------------+ | ID | Status | Display Name | Size | Volume Type | Bootable | Attached to | +--------------------------------------+----------------+-----------------+------+-------------+----------+--------------------------------------+ | 1e3eb4f2-c60c-4eeb-9bc0-41f1afe7c911 | available | CirrosBootVol | 2 | None | true | | | c1dfc42c-32c1-4104-a7cc-effc4ce86385 | in-use | Vdisk3G | 3 | None | false | b358aa2e-a8e9-4cb8-9f2a-e7c6e4d4f477 | +--------------------------------------+----------------+-----------------+------+-------------+----------+--------------------------------------+ # use dog or collie command to show [ray@fedora post]$ collie vdi list Name Id Size Used Shared Creation time VDI id Copies Tag volume-c1dfc42c-32c1-4104-a7cc-effc4ce86385 0 3.0 GB 1.2 GB 0.0 MB 2014-03-25 23:28 31433a 1 volume-1e3eb4f2-c60c-4eeb-9bc0-41f1afe7c911 0 2.0 GB 32 MB 0.0 MB 2014-03-26 22:55 cd4679 1
以上步驟結(jié)束之后,我們就可以在系統(tǒng)中看到創(chuàng)建好的cinder volume。 我在操作過(guò)程實(shí)際上碰到一個(gè)問(wèn)題。
從glance image創(chuàng)建volume沒(méi)有成功,打開cinder的log文件,會(huì)看到具體的錯(cuò)誤信息:
2014-03-26 22:51:14.335 5821 DEBUG cinder.openstack.common.processutils [req-1e55cd8c-d4b4-45d4-9f2b-9bf535d5446b 44d5eb0d5b1d4c4189affed764b24c60 b738ad4284ed466f91e677af13e71815] Running cmd (subprocess): sudo cinder-rootwrap /etc/cinder/rootwrap.conf env LC_ALL=C qemu-img info /var/log/conversion/tmpqXIy_Y execute /usr/lib/python2.7/site-packages/cinder/openstack/common/processutils.py:142 2014-03-26 22:51:14.414 5821 DEBUG cinder.openstack.common.processutils [req-1e55cd8c-d4b4-45d4-9f2b-9bf535d5446b 44d5eb0d5b1d4c4189affed764b24c60 b738ad4284ed466f91e677af13e71815] Running cmd (subprocess): collie vdi delete volume-c1cb8b40-82fa-4722-9424-2368ac5dc187 execute /usr/lib/python2.7/site-packages/cinder/openstack/common/processutils.py:142 2014-03-26 22:51:14.597 5821 DEBUG cinder.openstack.common.processutils [req-1e55cd8c-d4b4-45d4-9f2b-9bf535d5446b 44d5eb0d5b1d4c4189affed764b24c60 b738ad4284ed466f91e677af13e71815] Running cmd (subprocess): sudo cinder-rootwrap /etc/cinder/rootwrap.conf qemu-img convert -O raw', mode 'w+b' at 0x341c7a0> sheepdog:volume-c1cb8b40-82fa-4722-9424-2368ac5dc187 execute /usr/lib/python2.7/site-packages/cinder/openstack/common/processutils.py:142 2014-03-26 22:51:14.682 5821 DEBUG cinder.openstack.common.processutils [req-1e55cd8c-d4b4-45d4-9f2b-9bf535d5446b 44d5eb0d5b1d4c4189affed764b24c60 b738ad4284ed466f91e677af13e71815] Result was 1 execute /usr/lib/python2.7/site-packages/cinder/openstack/common/processutils.py:167 2014-03-26 22:51:14.686 5821 ERROR cinder.volume.flows.create_volume [req-1e55cd8c-d4b4-45d4-9f2b-9bf535d5446b 44d5eb0d5b1d4c4189affed764b24c60 b738ad4284ed466f91e677af13e71815] Failed to copy image 285ac2bf-e2d4-4bbd-b438-f2fa4f24bb27 to volume: c1cb8b40-82fa-4722-9424-2368ac5dc187, error: qemu-img: Unknown protocol qemu-img: Could not open ' ', mode 'w+b' at 0x341c7a0>': No such file or directory qemu-img: Could not open ' ', mode 'w+b' at 0x341c7a0>'
從log顯示來(lái)看,cinder創(chuàng)建volume的過(guò)程對(duì)應(yīng)的代碼位于 volume/drivers/sheepdog.py 中的 copy_image_to_volume函數(shù)。
102 def copy_image_to_volume(self, context, volume, image_service, image_id): 103 # use the image_conversion_dir as a temporary place to save the image 104 conversion_dir = CONF.image_conversion_dir 105 self._ensure_dir_exists(conversion_dir) 106 with tempfile.NamedTemporaryFile(dir=conversion_dir) as tmp: 107 # (wenhao): we don't need to convert to raw for sheepdog. 108 image_utils.fetch_verify_image(context, image_service, 109 image_id, tmp.name) 110 111 # remove the image created by import before this function. 112 # see volume/drivers/manager.py:_create_volume 113 self._delete(volume) 114 # convert and store into sheepdog 115 image_utils.convert_image(tmp, 'sheepdog:%s' % volume['name'], 116 'raw') 117 self._resize(volume)
解釋下就是這么寫步驟:
1. 從glance 下載image到本地目錄。cinder有對(duì)應(yīng)的下載目錄配置:
486 # 487 # Options defined in cinder.image.image_utils 488 # 489 490 # Directory used for temporary storage during image conversion 491 # (string value) 492 image_conversion_dir=/var/log/conversion
2. 下載到目錄之后,用qemu-img info 命令取回image disk的信息,主要是檢查cinder輸入的volume szie參數(shù),應(yīng)當(dāng)不能小于image disk的大小。這你懂的,不然不能夠。。。
image/image_utils.py:fetch_verify_image
238 # NOTE(xqueralt): If the image virtual size doesn't fit in the 239 # requested volume there is no point on resizing it because it will 240 # generate an unusable image. 241 if size is not None and data.virtual_size > size: 242 params = {'image_size': data.virtual_size, 'volume_size': size} 243 reason = _("Size is %(image_size)dGB and doesn't fit in a " 244 "volume of size %(volume_size)dGB.") % params 245 raise exception.ImageUnacceptable(image_id=image_id, reason=reason)
3. 到了這一步就要用qemu-img convert 把image 轉(zhuǎn)化成sheepdog VDI。 正確的命令是:
qemu-img convert -O raw /var/log/conversion/tmpf9sUFs sheepdog:volume-1e3eb4f2-c60c-4eeb-9bc0-41f1afe7c911
成功的話,就會(huì)在sheepdog系統(tǒng)中create一個(gè)名字是“volume-1e3eb4f2-c60c-4eeb-9bc0-41f1afe7c911”的VDI。 結(jié)果代碼有個(gè)bug,實(shí)際生成的命令如上面錯(cuò)誤log顯示:
qemu-img convert -O raw', mode 'w+b' at 0x341c7a0> sheepdog:volume-c1cb8b40-82fa-4722-9424-2368ac5dc187
這里明顯是參數(shù)傳錯(cuò)了,應(yīng)該傳入的是下載到本地目錄的image 文件名。在tempfile.NamedTemporaryFile 這個(gè)context中,tmp就是tempfile的object instance。 改成tmp.name就ok了。
115 image_utils.convert_image(tmp.name, 'sheepdog:%s' % volume['name'], 116 'raw'
修改后,重新操作,成功后的log:
2014-03-26 22:55:51.628 10137 DEBUG cinder.openstack.common.processutils [req-2e51dcbc-af6a-4a5f-9a92-008b230acb45 44d5eb0d5b1d4c4189affed764b24c60 b738ad4284ed466f91e677af13e71815] Running cmd (subprocess): sudo cinder-rootwrap /etc/cinder/rootwrap.conf env LC_ALL=C qemu-img info /var/log/conversion/tmpf9sUFs execute /usr/lib/python2.7/site-packages/cinder/openstack/common/processutils.py:142 2014-03-26 22:55:51.710 10137 DEBUG cinder.openstack.common.processutils [req-2e51dcbc-af6a-4a5f-9a92-008b230acb45 44d5eb0d5b1d4c4189affed764b24c60 b738ad4284ed466f91e677af13e71815] Running cmd (subprocess): collie vdi delete volume-1e3eb4f2-c60c-4eeb-9bc0-41f1afe7c911 execute /usr/lib/python2.7/site-packages/cinder/openstack/common/processutils.py:142 2014-03-26 22:55:52.036 10137 DEBUG cinder.openstack.common.processutils [req-2e51dcbc-af6a-4a5f-9a92-008b230acb45 44d5eb0d5b1d4c4189affed764b24c60 b738ad4284ed466f91e677af13e71815] Running cmd (subprocess): sudo cinder-rootwrap /etc/cinder/rootwrap.conf qemu-img convert -O raw /var/log/conversion/tmpf9sUFs sheepdog:volume-1e3eb4f2-c60c-4eeb-9bc0-41f1afe7c911 execute /usr/lib/python2.7/site-packages/cinder/openstack/common/processutils.py:142 2014-03-26 22:55:53.729 10137 DEBUG cinder.openstack.common.processutils [req-2e51dcbc-af6a-4a5f-9a92-008b230acb45 44d5eb0d5b1d4c4189affed764b24c60 b738ad4284ed466f91e677af13e71815] Running cmd (subprocess): collie vdi resize volume-1e3eb4f2-c60c-4eeb-9bc0-41f1afe7c911 2147483648 execute /usr/lib/python2.7/site-packages/cinder/openstack/common/processutils.py:142 2014-03-26 22:55:53.751 10137 DEBUG cinder.volume.flows.create_volume [req-2e51dcbc-af6a-4a5f-9a92-008b230acb45 44d5eb0d5b1d4c4189affed764b24c60 b738ad4284ed466f91e677af13e71815] Downloaded image 285ac2bf-e2d4-4bbd-b438-f2fa4f24bb27 ((None, None)) to volume 1e3eb4f2-c60c-4eeb-9bc0-41f1afe7c911 successfully _copy_image_to_volume /usr/lib/python2.7/site-packages/cinder/volume/flows/create_volume/__init__.py:1383 2014-03-26 22:55:53.752 10137 DEBUG cinder.volume.flows.create_volume [req-2e51dcbc-af6a-4a5f-9a92-008b230acb45 44d5eb0d5b1d4c4189affed764b24c60 b738ad4284ed466f91e677af13e71815] Marking volume 1e3eb4f2-c60c-4eeb-9bc0-41f1afe7c911 as bootable _enable_bootable_flag /usr/lib/python2.7/site-packages/cinder/volume/flows/create_volume/__init__.py:1323 2014-03-26 22:55:53.839 10137 DEBUG cinder.volume.flows.create_volume [req-2e51dcbc-af6a-4a5f-9a92-008b230acb45 44d5eb0d5b1d4c4189affed764b24c60 b738ad4284ed466f91e677af13e71815] Copying metadata from image 285ac2bf-e2d4-4bbd-b438-f2fa4f24bb27 to 1e3eb4f2-c60c-4eeb-9bc0-41f1afe7c911 _handle_bootable_volume_glance_meta /usr/lib/python2.7/site-packages/cinder/volume/flows/create_volume/__init__.py:1286 2014-03-26 22:55:53.840 10137 DEBUG cinder.volume.flows.create_volume [req-2e51dcbc-af6a-4a5f-9a92-008b230acb45 44d5eb0d5b1d4c4189affed764b24c60 b738ad4284ed466f91e677af13e71815] Creating volume glance metadata for volume 1e3eb4f2-c60c-4eeb-9bc0-41f1afe7c911 backed by image 285ac2bf-e2d4-4bbd-b438-f2fa4f24bb27 with: {'container_format': u'bare', 'min_ram': 0, 'disk_format': u'qcow2', 'image_name': u'CirrOS 0.3.1', 'image_id': u'285ac2bf-e2d4-4bbd-b438-f2fa4f24bb27', 'checksum': u'd972013792949d0d3ba628fbe8685bce', 'min_disk': 0, 'size': 13147648} _capture_volume_image_metadata /usr/lib/python2.7/site-packages/cinder/volume/flows/create_volume/__init__.py:1420 2014-03-26 22:55:54.441 10137 DEBUG cinder.volume.flows.create_volume [req-2e51dcbc-af6a-4a5f-9a92-008b230acb45 44d5eb0d5b1d4c4189affed764b24c60 b738ad4284ed466f91e677af13e71815] Volume 1e3eb4f2-c60c-4eeb-9bc0-41f1afe7c911: creating export __call__ /usr/lib/python2.7/site-packages/cinder/volume/flows/create_volume/__init__.py:1519
至于為什么tempfile.NamedTemporaryFile 拋出來(lái)的異常顯示是
以上是“如何配置sheepdog作為openstack Cinder的存儲(chǔ)后端”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!