系统环境:CentOS 5.4_64
一、安装所需包
#for i in kvm kvm-qemu-img libvirt kmod-kvm Python-virtinst bridge-utils tunctl virt-manager;do yum install $i -y;done
二、创建桥
#!/bin/sh
if /sbin/ifconfig vSwitch0 down > /etc/null 2>&1 &
then
/usr/sbin/brctl delbr vSwitch0 > /etc/null 2>&1 &
/sbin/ifconfig eth0 0.0.0.0 promisc up
/usr/sbin/brctl addbr vSwitch0
/usr/sbin/brctl addif vSwitch0 eth0
/sbin/ifconfig vSwitch0 192.168.1.19 netmask 255.255.255.0 up
/sbin/route add default gw 192.168.1.1 dev vSwitch0
else
/sbin/ifconfig eth0 0.0.0.0 promisc up
/usr/sbin/brctl addbr vSwitch0
/usr/sbin/brctl addif vSwitch0 eth0
/sbin/ifconfig vSwitch0 192.168.1.19 netmask 255.255.255.0 up
/sbin/route add default gw 192.168.1.1 dev vSwitch0
fi
把上述保存为一个脚本,然后添加到系统启动项
三、创建虚机
1、定义xml文件
<domain type='kvm'>
<name>tony-1</name>
<uuid>0111310a-ff1a-bfb5-7cd8-5b2b22ad8de1</uuid>
<memory>524288</memory>
<currentMemory>524288</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='x86_64' machine='pc'>hvm</type>
<boot dev='cdrom'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='localtime'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator> 注意此处的qemu-kvm路径
<disk type='file' device='disk'>
<source file='/opt/datastore/tony-1.qcow2'/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='cdrom'>
<target dev='hdc' bus='ide'/>
<source file='/opt/datastore/deepin-9.iso'/>
<readonly/>
</disk>
<interface type='bridge'>
<mac address='00:e0:4c:f0:e0:11'/>
<source bridge='vSwitch0'/>
<target dev='vnet0'/>
</interface>
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='5900' autoport='yes' listen='0.0.0.0' keymap='en-us'/>
<!-- <sound model='es1370'/> --> 注释掉声卡,如果不存在sound驱动,启动会报错,所以最好注释
<video>
<model type='cirrus' vram='9216' heads='1'/>
</video>
</devices>
</domain>
2、如果报什么错,查看日志
# tail -f 10 /var/log/libvirt/qemu/