1. 程式人生 > >通過libvirt使用ceph塊設備

通過libvirt使用ceph塊設備

spa mar ron mon virsh ceph protoc log image


1. 創建存儲池

[root@ceph1 ~]# ceph osd pool create libvirt-pool 128 128

查看剛剛創建的存儲池:

[root@ceph1 ~]# ceph osd lspools

0 rbd,1 .rgw.root,2 default.rgw.control,3 default.rgw.meta,4 default.rgw.log,5 default.rgw.buckets.index,6 default.rgw.buckets.data,7 default.rgw.buckets.non-ec,8 libvirt-pool,

2. 創建ceph用戶client.libvirt,權限限制到存儲池libvirt-pool

[root@ceph1 ~]# ceph auth get-or-create client.libvirt mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=libvirt-pool'

驗證:

[root@ceph1 ~]# ceph auth list

...

client.libvirt

key: AQBblU1b9FECCRAA4tW8qaBYtxTsDlaNJybZSQ==

caps: [mon] allow r

caps: [osd] allow class-read object_prefix rbd_children, allow rwx pool=libvirt-pool

...

3. 把虛擬機鏡像文件centos6864.qcow2.img導入存儲池libvirt-pool中

[root@ceph1 ~]# qemu-img convert -f qcow2 -O raw centos6864.qcow2.img rbd:libvirt-pool/centos6864.qcow2.img

驗證:

[root@ceph1 ~]# rbd -p libvirt-pool ls

centos6864.qcow2.img

4. 在libvirt中配置ceph認證需要的密鑰

a. 定義密鑰

[root@localhost ~]# cat > secret.xml <<EOF

<secret ephemeral='no' private='no'>

<usage type='ceph'>

<name>client.libvirt secret</name>

</usage>

</secret>

virsh secret-define --file secret.xml

b. 獲取密鑰uuid

[root@localhost ~]# virsh secret-list

UUID Usage

--------------------------------------------------------------------------------

fdcb5967-d3e5-4618-98f5-5919a723e414 ceph client.libvirt secret

c. 設置密鑰的值

virsh secret-set-value --secret fdcb5967-d3e5-4618-98f5-5919a723e414 --base64 AQBblU1b9FECCRAA4tW8qaBYtxTsDlaNJybZSQ==

其中“AQBblU1b9FECCRAA4tW8qaBYtxTsDlaNJybZSQ==”是從上面ceph auth list的client.libvirt的key字段中得到的

5. 修改虛擬機xml文件的disk部分

[root@localhost ~]# virsh edit test

...

<disk type='network' device='disk'>

<driver name='qemu'/>

<auth username='libvirt'>

<secret type='ceph' uuid='fdcb5967-d3e5-4618-98f5-5919a723e414'/>

</auth>

<source protocol='rbd' name='libvirt-pool/centos6864.qcow2.img'>

<host name='192.168.1.15' port='6789'/>

<host name='192.168.1.16' port='6789'/>

<host name='192.168.1.17' port='6789'/>

</source>

<target dev='vda' bus='virtio'/>

<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>

</disk>

...

其中secret的uuid就是上面創建密鑰的uuid;host配置的是ceph monitor的ip和端口,有幾個monitor就寫幾個。

6. 開啟虛擬機

[root@localhost ~]# virsh start test

技術分享圖片


通過libvirt使用ceph塊設備