1.安装环境
DELL R710 *2
Centos 6.4
Centos 6.0(VM)
libvirt 1.1.1
qemu 0.13.50
2.安装libvirt
通过源码安装libvirt,安装libvirt依赖包
yum install libxml2-devel device-mapper-devel libdevmapper python-devel libpciaccess-devel libnl-devel
安装libvirtd
tar -zxvf libvirt-1.1.1.tar.gz
./configure --with-storage-sheepdog
make
make install
设置libvirtd
mkdir -p /usr/local/var/lock/subsys
cp /etc/rc.d/init.d/functions /usr/local/etc/rc.d/init.d/
cp /usr/local/sbin/libvirtd /usr/sbin/
cp /usr/local/etc/rc.d/init.d/libvirt* /etc/init.d/
启动libvirtd
service libvirtd start
编写libvirtd.xml文件
<domain type='qemu'>
<name>centos6</name>
<uuid>c7a5fdbd-cdaf-9455-926a-d65c16db1809</uuid>
<memory>219200</memory>
<currentMemory>219200</currentMemory>
<vcpu>2</vcpu>
<os>
<type arch='x86_64' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<devices>
<emulator>/usr/local/bin/qemu-system-x86_64</emulator>
<disk type='file' device='disk'>
<source file='/tmp/images/centos6.img'/>
<target dev='hda'/>
</disk>
<disk type='network'>
<driver name="qemu" type="raw" io="threads" />
<source protocol="sheepdog" name="myvol">
<host name="10.10.200.228" port="7000"/>
</source>
<target dev="hdb" bus="ide"/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<interface type='bridge'>
<source bridge='br0'/>
<model type='rtl8139'/>
</interface>
<graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'/>
</devices>
</domain>
3.sheepdog创建vdi
有两种方式创建vdi,一种是通过qemu-img来创建
qemu-img create sheepdog:test 40G
另外一种,通过编写libvirtd的xml文件进行创建volume
首先创建pool,编写pool.xml
vi pool.xml
<pool type="sheepdog">
<name>mysheeppool</name>
<source>
<name>mysheeppool</name>
<host name='10.10.200.228' port='7000'/>
</source>
</pool>
创建pool
virsh pool-create pool.xml
创建volume,编写volume.xml
<volume>
<name>myvol</name>
<key>sheep/myvol</key>
<source>
</source>
<capacity unit='bytes'>53687091200</capacity>
<allocation unit='bytes'>53687091200</allocation>
<target>
<path>sheepdog:myvol</path>
<format type='unknown'/>
<permissions>
<mode>00</mode>
<owner>0</owner>
<group>0</group>
</permissions>
</target>
</volume>
创建volume
virsh vol-create mysheeppool vol.xml
查看sheepdog vdi
[root@euca-clc images]# dog vdi list
Name Id Size Used Shared Creation time VDI id Copies Tag
10.10.200.228:7000:test1.img 0 10 GB 0.0 MB 0.0 MB 2013-08-21 13:32 24baa2 2
test 0 40 GB 0.0 MB 0.0 MB 2013-08-21 13:18 7c2b25 2
myvol 0 50 GB 0.0 MB 0.0 MB 2013-08-21 13:55 b54274 2
4.启动VM
启动vm
virsh create libvirtd.xml
在这里sheepdog是作为vm的数据盘使用,通过vnc可以查看到新添加磁盘sdb