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。
python

一、 環境
CentOS6.2 X86_64 最小化安裝
系統環境初始化(我的習慣) linux

[root@duyunlong ~]# yum install wget vim-enhanced which screen make setuptool system-config-network* xorg-x11-xauth && yum groupinstall“development tools” && yum updatees6

備註:關閉SeLinuxvim

檢查CPUapi

[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。網絡

安裝KVMsession

[root@duyunlong ~]# yum groupinstall Virtualization 'Virtualization Client'
[root@duyunlong ~]# yum install dejavu-lgc-sans-fontsapp

備註:不安裝這個字體,virt-manager界面會出現“口”亂碼less

安裝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

六、網絡橋接(下面這個,是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
IPADDR=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

九、安裝過程當中遇到的問題及解決方法

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*

十、用命令方式安裝: 

[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/xstartupLog file is /root/.vnc/xen:2.log

相關文章
相關標籤/搜索