1. 程式人生 > >centos6.0 安裝KVM虛擬化環境

centos6.0 安裝KVM虛擬化環境

一、 kvm安裝

  簡單的方法:yum install kvm

二、libvirt安裝及升級

(1) yum install libvirt libvirt-python -y

(2)預設版本是0.8.1,功能很少,可升級到最新

       cd libvirt-0.9.4

       ./configure

以下是大部分可能出現的情況,如果已有安裝某些包,可能不需要操作

1 gcc編譯器沒有安裝

   yum -y install gcc gcc-c++

2 libxml2 xml2-config >= 2.6.0 ... configure: error: Could not find libxml2 anywhere (see config.log for details). 
    yum install libxml2-devel
   //yum install xml2-*  這個不一定需要  

3 configure: error: You must install the GnuTLS library in order to compile and run libvirt

  yum install gnutls-devel

4 configure: error: You must install device-mapper-devel/libdevmapper >= 1.0.0 to compile libvirt
   yum install device-mapper-devel

5 You must install python-devel to build Python bindings

    yum install python-devel

6 configure: error: libnl-devel >= 1.1 is required for macvtap support

   yum install libnl-devel

至此./configure應該可以通過。懶人就用這個 yum install libxml2-devel gnutls-devel device-mapper-devel python-devel libnl-devel -y

(3)make && make install

         重啟libvirtd

         service libvirtd restart

可能會報錯:

1 error: Failed to connect socket to '/usr/local/var/run/libvirt/libvirt-sock': No such file or directory
做個連結:
ln -s /var/run/libvirt/libvirt-sock /usr/local/var/run/libvirt/libvirt-sock

2 libvirt: Remote error : unable to connect to '/usr/local/var/run/libvirt/libvirt-sock-ro': No such file or directory”

再做個連結
ln -s /var/run/libvirt/libvirt-sock-ro /usr/local/var/run/libvirt/libvirt-sock-ro

三、伺服器網路配置-橋接,目的是使虛擬機器通訊方便

使用橋接模式,以centos上執行ubuntu虛擬機器的網路配置為例

  cd /etc/sysconfig/network-scripts

  cp ifcfg-eth0 ifcfg-br0  //複製後修改

  修改 ifcfg-eth0為如下內容

 DEVICE=eth0

HWADDR=00:E0:81:D2:7A:F1   //視具體情況定

ONBOOT=yes

BRIDGE=br0

 修改ifcfg-br0為如下內容

 DEVICE=br0

TYPE=Bridge

BOOTPROTO=static

IPADDR=10.88.0.27

NETMASK=255.255.255.0

GATEWAY=10.88.0.1

ONBOOT=yes

 重啟網路服務  service network restart
如果有雙網絡卡,並且需要配置兩個IP,則可以使用同樣地方法為eth1建一個Bridge。