centos6.2 kvm安装详解

    kernel-based Virtual Machine的简称,是一个开源的系统虚拟化模块,自Linux 2.6.20之后集成在Linux的各个主要发行版本中。它使用Linux自身的调度器进行管理,所以相对于Xen,其核心源码很少。KVM目前已成为学术界的主流VMM之一。 
  KVM的虚拟化需要硬件支持(如Intel VT技术或者AMD V技术)。是基于硬件的完全虚拟化。而Xen早期则是基于软件模拟的Para-Virtualization,新版本则是基于硬件支持的完全虚拟化。但Xen本身有自己到进程调度器,存储管理模块等,所以代码较为庞大。广为流传的商业系统虚拟化软件VMware ESX系列也是基于软件模拟的Para-Virtualization。
1、 环境
CentOS6.2 X86_64 最小化安装
系统环境初始化(个人习惯) 
[root@duyunlong ~]# yum install wget vim-enhanced which screen make setuptool system-config-network* xorg-x11-xauth && yum groupinstall“development tools” && yum update
备注:关闭SeLinux
检查CPU
[root@duyunlong ~]# egrep 'vmx|svm' /proc/cpuinfo --color=auto
flags                     : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm xsave lahf_lm dts tpr_shadow vnmi flexpriority
flags                     : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm xsave lahf_lm dts tpr_shadow vnmi flexpriority
备注:如果能正常返回结果,就说明支持,VMX代表intel CPU,SVM代表AMD CPU。
安装KVM
[root@duyunlong ~]# yum groupinstall Virtualization 'Virtualization Client'
[root@duyunlong ~]# yum install dejavu-lgc-sans-fonts
备注:不安装这个字体,virt-manager界面会出现“口”乱码
安装API支持
[root@duyunlong ~]# yum install avahi dmidecode libvirt
[root@duyunlong ~]# yum -y install qemu-kvm libvirt python-virtinst bridge-utils
[root@duyunlong ~]# /etc/init.d/messagebus restart
[root@duyunlong ~]# /etc/init.d/avahi-daemon restart
[root@duyunlong ~]# service libvirtd restart
备注:不安装avahi,dmidecode,并成功启动相关服务的话,libvirtd无法启动,
详细报错查看tail -f /var/log/libvirt/libvirtd.log
6、网络桥接(下面这个,是DHCP获取的IP地址)
[root@duyunlong ~]# cd /etc/sysconfig/network-scripts/
[root@duyunlong network-scripts]# cp ifcfg-eth0 ifcfg-br0
[root@duyunlong network-scripts]# ls
ifcfg-br0                ifdown-post                ifup-ippp                ifup-tunnel
ifcfg-eth0         ifdown-ppp                 ifup-ipv6                ifup-wireless
ifcfg-lo                 ifdown-routes        ifup-isdn                init.ipv6-global
ifdown                         ifdown-sit                 ifup-plip                net.hotplug
ifdown-bnep        ifdown-tunnel        ifup-plusb         network-functions
ifdown-eth         ifup                                         ifup-post                network-functions-ipv6
ifdown-ippp        ifup-aliases         ifup-ppp
ifdown-ipv6        ifup-bnep                        ifup-routes
ifdown-isdn        ifup-eth                         ifup-sit
[root@duyunlong network-scripts]# vim ifcfg-br0 
DEVICE="br0"
TYPE=Bridge
BOOTPROTO=dhcp
HWADDR="44:87:FC:43:62:54"
NM_CONTROLLED="yes"
ONBOOT="yes"
[root@duyunlong network-scripts]# vim ifcfg-eth0 
DEVICE="eth0"
BRIDGE=br0
#BOOTPROTO=dhcp
HWADDR="44:87:FC:43:62:54"
NM_CONTROLLED="yes"
ONBOOT="yes"
红帽6发行版虚拟化系统一改以往的Xen,而是使用KVM(Kernel Virtual Machine) 。
下面是设置桥接简单的方法。从而能是虚拟机有一个独立的IP地址。  
[root@duyunlong ~]# ifdown eth0
[root@duyunlong ~]# cd /etc/sysconfig/network-scrips/eth0
[root@duyunlong network-scripts]# cp eth0 br0
[root@duyunlong network-scripts]# vim br0
DEVICE=br0
NM_CONTROLLDE=yes
NOBOOT=yes
HWADDR="44:87:FC:43:62:54"
BOOTPROTO=static
TYPE=Brige
I PADDR=192.168.8.223                             
NETMASK=255.255.255.0
GATEWAY=192.168.8.1
[root@duyunlong network-scripts]# vim eth0        
DEVICE="eth0"
BRIDGE=br0
HWADDR="44:87:FC:43:62:54"
NM_CONTROLLED="yes"
ONBOOT="yes"

#保存后重启网络:
[root@duyunlong network-scripts]# service network restart
而KVM默认为NAT接入网络,不能定义虚拟机的IP地址,
验证是否有KVM模块
[root@duyunlong network-scripts]# lsmod | grep kvm
kvm_intel                                                        52762        6
kvm                                                                         312245        1 kvm_intel
9、安装过程中遇到的问题及解决方法
A:service libvirtd restart 启动失败,查看/var/log/libvirt/libvirtd.log
        日志显示:
        2012-04-18 13:51:03.032+0000: 18149:
        error : virNetServerMDNSStart:460 : internal
        error Failed tocreate mDNS client: Daemon not running
         解决方法:
        [root@duyunlong ~]# #yum install avahi            
        [root@duyunlong ~]# /etc/init.d/messagebus restart
        [root@duyunlong ~]# /etc/init.d/avahi-daemon restart
        [root@duyunlong ~]# service libvirtd restart
        此时如果仍然启动失败,继续查看/var/log/libvirt/libvirtd.log
        日志显示:
        012-04-18 13:54:54.654+0000: 18320:
        error : virSysinfoRead:465 :
        internal error Failed to find path for dmidecode binary
        解决方法:
        [root@duyunlong ~]# yum install dmidecode
        [root@duyunlong ~]# service libvirtd restart
        启动成功
B:virt-manager启动报错
        [root@duyunlong ~]# virt-manager
        Xlib: extension "RANDR" missing on display "localhost:10.0".process 1869:D-Bus library appears to be incorrectly set up; failed to read machine uuid: Failed to open "/var/lib/dbus/machine-id": No such file or directory See the manual page for dbus-uuidgen to correct this issue.D-Bus not built with -rdynamic so unable to print a backtrace Aborted
        解决方法:
        运行如下命令生成必要的machine-id文件:
        [root@duyunlong ~]# #dbus-uuidgen > /var/lib/dbus/machine-idC:virt-manager界面出现"口口"乱码
C:virt-manager界面出现"口口"乱码
        解决方法:
        [root@duyunlong ~]# yum install dejavu-lgc-sans-fonts
        [root@duyunlong ~]# yum –y install *vnc-server*
10、用命令方式安装:  
[root@duyunlong ~]# virt-install --name linux2 --ram 256 --vcpus=1 --disk path=/virtul/linux2.img,size=50 --accelerate --cdrom=/root/CentOS-6.2-x86_64-bin-DVD1.iso --network bridge=br0 --os-type=linux --os-type=linux --vnc --vncport=6901
    在服务器安装,我们没有图形界面,只能借助VNC连过去安装。所以在给虚拟机安装系统前,我们的先安装配置VNC,下面是,具体步骤:
10-1 安装配置VNC
[root@duyunlong ~]# yum groupinstall "Chinese Support"
[root@duyunlong ~]# yum groupinstall "Desktop"
1)打开配置文件的目录: 
[root@duyunlong ~]# cd /etc/sysconfig        
[root@duyunlong ~]# vi i18n            #编辑配置文件:
#用#号把第一行(LANG="en_US.UTF-8")注释掉,其实直接在这行改也是可以的,不过保险做法,还是先注释掉,等成功后再删除不迟。在第一行下添加一行新行,输入(LANG="zh_CN.UTF-8"),然后保存文件,重启系统,就能见到亲切的中文啦。
好像 6.0 以后VNC名字 由 vnc 改成    tigervnc
[root@duyunlong ~]# rpm -qa|grep tigervnc
tigervnc-1.0.90-0.17.20110314svn4359.el6.x86_64
tigervnc-server-1.0.90-0.17.20110314svn4359.el6.x86_64
如果没有就安装下了
[root@duyunlong ~]# yum install tigervnc tigervnc-server
添加启动项
[root@duyunlong ~]# chkconfig --add vncserver
[root@duyunlong ~]# chkconfig vncserver on
设置 VNC 密码 
[root@duyunlong ~]# vncserver
Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/xen:1.log
会在当前用户主目录下 生成 .vnc    目录和配置文件
[root@duyunlong ~]# vncpasswd
Password:
Verify:
设置的密码保存在    /root/.vnc/passwd
VNC 配置 
修改 xstartup 文件 把最后的 twm & 删掉 加上 gnome-session &
[root@duyunlong ~]# cd /root/.vnc/
[root@duyunlong .vnc]#    tail -n 3 xstartup
xsetroot -solid grey
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
gnome-session &
如果直接启动
[root@duyunlong .vnc]# /etc/init.d/vncserver start
正在启动 VNC 服务器:no displays configured                                [ 失败]
所以要修改    /etc/sysconfig/vncservers 文件添加以下内容
VNCSERVERS="2:root"
# 桌面号:用户        监听 590* 端口
VNCSERVERARGS[2]="-geometry 800x600"
这样修改后,就算 /etc/inittab 启动模式为 3    也可以正常进入图形界面
启动 vncserver
[root@duyunlong ~]# /etc/init.d/vncserver start
正在启动 VNC 服务器:2:root xauth: (stdin):1:    bad display name "xen:2" in "add" command New'xen:2 (root)' desktop is xen:2 Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/xen:2.log
 
 
 

你可能感兴趣的:(kvm安装)