KVM是kernel-based Virtual Machine的简称,目前已成为学术界的主流VMM之一。KVM的虚拟化需要硬件支持(如Intel VT技术或者AMD V技术),是基于硬件的完全虚拟化。KVM的安装和使用相对于XEN来说十分的简单和方便,并且功能强大,比较适用于高性能计算服务的云计算环境中作为IAAS层的虚拟化部署工作。不得不提的是甲骨文公司的VirtualBox也很强大,各方面与KVM可以相媲美,但是现在不开源比较昂贵一般的云计算平台很少使用。至于完全虚拟化和半虚拟化我觉得这是一个很模糊的概念。
KVM提供了图像界面的管理接口(Virtual Machine Manager)和命令行式的管理接口(virsh)。可以根据使用的场景采用不同的方式,当然也可以使用Libvirt库进行管理虚拟机,并且使用libvirt库进行虚拟机的管理是业界很推崇的做法,这都源于libvirt库良好的移植性和强大的API,并且提供了多种语言接口(如C语言,python语言,JAVA语言,C#语言和PHP语言)能对Xen,KVM以及QEMU等多类虚拟机进行管理管理
实验环境
centos release 6.5
软件安装
yum install -y tigervnc*
yum install -y qemu-kvm.x86_64* qemu-kvm-tools.x86_64* qemu-img.x86_64*
yum install -y python-virtinst.noarch* bridge-utils.x86_64*
yum install -y libvirt* virt-manager*
vim /etc/sysconfig/vncservers
#VNCSERVERS="2:myusername"
#VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost" 找到
VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 1024x768" 改为
vncpasswd
Password:
Verify:
/etc/rc.d/init.d/vncserver restart
vim ~/.vnc/xstartup
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & 找到
twm &
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & 改为
#twm &
gnome-session &
netstat -tuplna | grep 5901
tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 12740/Xvnc
lsmod | grep kvm
kvm_amd 40333 0
kvm 345038 1 kvm_amd 出现这个提示说明kvm安装成功
/etc/rc.d/init.d/libvirtd start
virsh list
Id Name State
ps -aux | grep libvirtd
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root 5001 0.0 0.1 698280 7544 ? Sl 11:56 0:00 libvirtd --daemon
root 5196 0.0 0.0 103312 864 pts/0 S+ 12:01 0:00 grep libvirtd
网卡桥接
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.bak
vim ifcfg-eth0
DEVICE=eth0
BRIDGE=br0
HWADDR=00:0C:29:68:A5:06
TYPE=Ethernet
UUID=e945a666-c323-4967-8d58-f76110fbb68f
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
IPADDR=192.168.1.104
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-br0
vim ifcfg-br0
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
IPADDR=192.168.1.104
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
/etc/rc.d/init.d/NetworkManager stop
service network restart
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
Bringing up interface br0: Determining if ip address 192.168.1.104 is already in use for device br0...
[ OK ]
如果没有error等提示就说明配置正确
ifconfig
br0 Link encap:Ethernet HWaddr 00:0C:29:68:A5:06
inet addr:192.168.1.104 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe68:a506/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:68 errors:0 dropped:0 overruns:0 frame:0
TX packets:82 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:7465 (7.2 KiB) TX bytes:11102 (10.8 KiB)
virbr0 Link encap:Ethernet HWaddr 52:54:00:C4:19:73
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
brctl show 查看桥接情况
bridge name bridge id STP enabled interfaces
br0 8000.50e549d0b1f5 no eth0
vnet0
virbr0 8000.525400d39002 yes virbr0-nic
route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 0 0 0 br0
192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0
link-local * 255.255.0.0 U 1006 0 0 br0
default localhost 0.0.0.0 UG 0 0 0 br0
mv CentOS-6.5-x86_64-bin-DVD1.iso /var/lib/libvirt/images/ 复制安装镜像到系统
cd /var/lib/libvirt/images/
CentOS-6.5-x86_64-bin-DVD1.iso
安装虚拟机
本文转自 mailfile 51CTO博客,原文链接:http://blog.51cto.com/mailfile/1752929,如需转载请自行联系原作者