本帖最后由 bob007 于 2015-5-18 19:15 编辑
导言很多cepher都会使用RBD块存储功能,下面介绍qemu-kvm访问RBD的方法。 操作目前Ubuntu 14.04.x和CentOS 7.1 (如使用CentOS 7建议升级到7.1, CentOS 6.x需要升级Qemu-kvm包) 内置的qemu-kvm包已经支持RBD块设备。这里以CentOS 7.1为例描述: [mw_shl_code=bash,true][root@performance ~]# uname -a
Linux performance 3.10.0-229.1.2.el7.x86_64 #1 SMP Fri Mar 27 03:04:26 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@performance ~]# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
[root@performance ~]# qemu-img --help | grep rbd
Supported formats: vvfat vpc vmdk vhdx vdi sheepdog rbd raw host_cdrom host_floppy host_device file qed qcow2 qcow parallels nbd iscsi gluster dmg cloop bochs blkverify blkdebug
[root@performance ~]# ldd /usr/libexec/qemu-kvm | grep rbd
librbd.so.1 => /lib64/librbd.so.1 (0x00007fc8c00e6000)[/mw_shl_code] 这里看到qemu-img支持rbd块设备,qemu-kvm动态链接到librbd.so.1 。如上述所示,qemu-kvm具备访问RBD的能力。 首先对Ceph建立一个Pool,并且vmimages的pool访问权限key: [mw_shl_code=bash,true]ceph osd pool create vmimages 100 100
ceph auth get-or-create client.vmimages mon 'allow r' osd 'allow rwx pool=vmimages'[/mw_shl_code] 上述步骤会返回一个访问key值,请留意下面使用。然后创建一个secret.xml文件,加载到libvirt内部: [mw_shl_code=bash,true]echo "
<secret ephemeral='no' private='no'>
<usage type='ceph'>
<name>client.vmimages secret</name>
</usage>
</secret>" > secret.xml
virsh secret-define --file secret.xml[/mw_shl_code] 上述步骤创建一个密钥,并返回uuid值。请把上述两个步骤的输出值对应更换一下命令: [mw_shl_code=bash,true]virsh secret-set-value 76e3a541-b997-58ac-f7bd-77dd7d4347cb AQAREH1QkNDNCBaac03ZICi/CePnRDS+vGyrqQ==[/mw_shl_code] 接下来要创建一个块设备。可以通过rbd命令进行创建: [mw_shl_code=bash,true]rbd create vmimages/ubuntu-newdrive --size=2048[/mw_shl_code] 也可以通过qemu-img命令创建块设备: [mw_shl_code=bash,true]qemu-img create -f rbd rbd:vmimages/ubuntu-newdrive 2G[/mw_shl_code] 如果在计算节点上使用qemu-img创建块设备,要完整指定key信息: [mw_shl_code=bash,true]qemu-img create -f rbd rbd:vmimages/ubuntu-newdrive:id=vmimages:key=AQAREH1QkNDNCBaac03ZICi/CePnRDS+vGyrqQ==:auth_supported=cephx\;none:mon_host=192.168.0.100\:6789 2G[/mw_shl_code] 最后就是把这个块设备动态添加到虚拟机: [mw_shl_code=bash,true]echo "
<disk type='network' device='disk'>
<driver name='qemu' type='raw'/>
<auth username='vmimages'>
<secret type='ceph' uuid='76e3a541-b997-58ac-f7bd-77dd7d4347cb'/>
</auth>
<source protocol='rbd' name='vmimages/ubuntu-newdrive'>
<host name='192.168.0.100' port='6789'/>
</source>
<target dev='vdc' bus='virtio'/>
</disk>
" > device.xml
virsh attach-device ubuntu device.xml --persistent[/mw_shl_code] 这样做好之后,在虚拟机即可见到vdc的磁盘裸设备,此时对裸设备分区格式化便可使用。 参考来源:来源:http://bbs.ceph.org.cn/
|