系統:CentOS6.0  安裝的Xen版本:4.1.2

在centos下安裝xen不是很順利,遇到很多問題。安裝過程主要參考了以下兩個文檔:

http://wiki.xen.org/xenwiki/RHEL6Xen4Tutorial?action=fullsearch&value=linkto%3A%22RHEL6Xen4Tutorial%22&context=180

這個方法可以正常安裝xen,并指出RedHat 6 下安裝xen 會遇到的問題,只是安裝過程復雜,不是源碼安裝。

http://www.cnblogs.com/feisky/archive/2012/04/10/2441307.html

這個是xen的源碼編譯安裝,也是centos下,安裝xen 4.1.2,但是經過實踐,這樣安裝出來存在一些問題,很意外的。解決起來很頭痛。

在上面這個方法上,具體的描述我的安裝過程。

系統和安裝的xen版本上面有介紹,開始著手安裝xen了。

1.下載Xen的源碼

1 wget http://bits.xensource.com/oss-xen/release/4.1.2/xen-4.1.2.tar.gz

 

2.安裝必備軟件包

復制代碼
1 yum groupinstall "Development Libraries" 2 yum groupinstall "Development Tools" 3 yum install transfig wget texi2html libaio-devel dev86 glibc-devel e2fsprogs-devel gitk mkinitrd iasl xz-devel 4 bzip2-devel pciutils-libs pciutils-devel SDL-devel libX11-devel gtk2-devel bridge-utils PyXML qemu-common qemu-img mercurial libidn-devel 5 yum -y install glibc-devel.i686texinfo libuuid-devel iasl python-lxml 6 yum -y install openssl openssl-devel 7 yum -y install ncurses ncurses-* 8 yum -y install python-devel
復制代碼

 

3.編譯安裝Xen hypervisor

1 tar zxvf xen-4.1.2.tar.gz 2 cd xen-4.1.2 3 make world

在此可能會遇到如下問題:

解決辦法:yum –y install texinfo

1 make install

4.將Xen加入到啟動腳本:

1 /sbin/chkconfig --add xend 2 /sbin/chkconfig --add xencommons 3 /sbin/chkconfig --add xendomains 4 /sbin/chkconfig xend on 5 /sbin/chkconfig xendomains on 6 /sbin/chkconfig xencommons on

5.編譯安裝Linux3.1.2內核

復制代碼
 1 wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.1.2.tar.bz2  2 tar -jxvf linux-3.1.3.tar.bz2  3 make menuconfig  4   5 Processor type and features --- >  6      選中Paravirtualized Guest Support  7   Device Drivers --->   8       Xen driver support --->   9         全部選* 10  11 修改:CONFIG_XEN_DEV_EVTCHN=y(如果是m,開機時無法啟動xencommons)
復制代碼

 注意:僅僅上面的是不夠的,還需要修改:否則在創建虛擬機的過程中遇到這樣的問題:

注意:Device 0 (vif) could not be connected. HotPlug scripts not working.

在.config文件中做如下修改,就可以解決問題了

 

1 CONFIG_XEN_BLKDEV_BACKEND=m 2 CONFIG_XEN_NETDEV_BACKEND=m

接下來開始編譯安裝了:

1 make 2 make modules 3 make modules_install 4 make install  5 depmod 3.1.2 6 mkinitrd -v -f --with=aacraid --with=sd_mod --with=scsi_mod initramfs-3.1.2.img 3.1.2

6.配置grub:

復制代碼
1 title Xen (3.1.2-xen) 2         root (hd0,0) 3         kernel /xen-4.1.2.gz dom0_mem=512M 4         module /vmlinuz-3.1.2 ro root=UUID=3f920108-b74b-46b9-81c2-aff834494381   5 rd_DM_UUID=ddf1_4c5349202020202010000055000000004711471100001450 rd_NO_LUKS rd_NO_LVM rd_NO_MD LANG=en_US.UTF-8   6 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto rhgb quiet 7         module /initramfs-3.1.2.img
復制代碼

這個配置在第4行后面root=UUID隨自己的系統

7.安裝virt-manager

1 yum install libvirt virt-manager xorg-x11-xauth

 8. 重新編譯libvirt

  在文章前面第一個鏈接中,說明了,redhat6系統中,默認的libvirt是不支持xen的,如果直接使用默認的這會出現如下的問題:

  注意virt-manager & 這個命令中的'&' 代表該進程后臺運行

復制代碼
 1 [root@el6 ~]# virt-manager &  2 [1] 2867  3 Unable to open connection to hypervisor URI 'xen:///':  4 no connection driver available for xen:///  5 Traceback (most recent call last):  6   File "/usr/share/virt-manager/virtManager/connection.py", line 992, in _try_open  7     None], flags)  8   File "/usr/lib64/python2.6/site-packages/libvirt.py", line 111, in openAuth  9     if ret is None:raise libvirtError('virConnectOpenAuth() failed') 10 libvirtError: no connection driver available for xen:///
復制代碼

 開始重新編譯libvirt解決以上的問題。

以下的操作都在非xen系統中進行:

沒個系統遇到的缺的包不一樣,我的系統中還缺失xen-devel包,并且在yum

復制代碼
 1 [root@el6 ~]# cd /root/src  2 [root@el6 src]# wget ftp://ftp.redhat.com/pub/redhat/linux/enterprise/6Server/en/os/SRPMS/libvirt-0.8.1-27.el6.src.rpm  3 [root@el6 src]# rpm -i libvirt-0.8.1-27.el6.src.rpm  4 [root@el6 src]# wget http://pasik.reaktio.net/xen/patches/libvirt-spec-rhel6-enable-xen.patch  5 [root@el6 src]# cd /root/rpmbuild/SPECS  6 [root@el6 SPECS]# cp -a libvirt.spec libvirt.spec.orig  7 [root@el6 SPECS]# patch -p0 < ~/src/libvirt-spec-rhel6-enable-xen.patch  8 patching file libvirt.spec  9  10 [root@el6 SPECS]# rpmbuild -bb libvirt.spec 11 error: Failed build dependencies: 12         libnl-devel >= 1.1 is needed by libvirt-0.8.1-27.el6.x86_64 13         xhtml1-dtds is needed by libvirt-0.8.1-27.el6.x86_64 14         libudev-devel >= 145 is needed by libvirt-0.8.1-27.el6.x86_64 15         libpciaccess-devel >= 0.10.9 is needed by libvirt-0.8.1-27.el6.x86_64 16         yajl-devel is needed by libvirt-0.8.1-27.el6.x86_64 17         libpcap-devel is needed by libvirt-0.8.1-27.el6.x86_64 18         avahi-devel is needed by libvirt-0.8.1-27.el6.x86_64 19         parted-devel is needed by libvirt-0.8.1-27.el6.x86_64 20         device-mapper-devel is needed by libvirt-0.8.1-27.el6.x86_64 21         numactl-devel is needed by libvirt-0.8.1-27.el6.x86_64 22         netcf-devel >= 0.1.4 is needed by libvirt-0.8.1-27.el6.x86_64 23  [root@el6 SPECS]# yum install libnl-devel xhtml1-dtds libudev-devel libpciaccess-devel yajl-devel libpcap-devel avahi-devel parted-devel device-mapper-devel numactl-devel netcf-devel
復制代碼

安裝的時候,提示No packages xen-devel available 。

在多次替換yum源之后,依然無法解決這個xen-devel包缺失的問題。

隨后的解決方案如下:

在網上下載xen-devel rpm 包,安裝遇到依賴問題,接著下載xen-libs rpm 包,接著還有其他的依賴問題,同樣查找。

具體鏈接: 搜索xen-devel,找到符合系統版本的

1 http://rpm.pbone.net/index.php3

我下載的版本是:
xen-devel-4.1.2_03-1.1.x86_64.rpm

安裝xen-devel還依賴其他的包,如下:

xen-libs-4.1.2_03-1.1.x86_64.rpm

liblzma5-5.0.3-7.1.x86_64.rpm

glibc-common-2.14.90-14.x86_64.rpm

glibc-2.14.90-14.x86_64.rpm

強制安裝如上的包。

如果缺少依賴包,依次去下載對應版本,解決問題。這個過程很蛋疼。

如果所有的依賴包都安裝上后,接著下面的操作:

復制代碼
1 [root@gb31 SPECS]# rpmbuild -bb libvirt.spec 2 After a while you'll see:  3 Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-0.8.1-27.el6.x86_64.rpm 4 Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-client-0.8.1-27.el6.x86_64.rpm 5 Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-devel-0.8.1-27.el6.x86_64.rpm 6 Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-python-0.8.1-27.el6.x86_64.rpm 7 Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-debuginfo-0.8.1-27.el6.x86_64.rpm
復制代碼

如果有如上的顯示則安裝成功。

如果遇到屏幕顯示test 。。 一直卡住之后,卸載掉系統中已經安裝的libvirt包,再重新嘗試,即可。
接著如下:注意,可能版本不一樣

如果還顯示存在test失敗,make失敗,與libvirt版本相關,這個問題很蛋疼,多試下幾個版本吧。就可以解決。

復制代碼
1 [root@el6 ~]# cd /root/rpmbuild/RPMS/x86_64/ 2 [root@el6 x86_64]# rpm -Uvh --force libvirt-0.8.1-27.el6.x86_64.rpm libvirt-client-0.8.1-27.el6.x86_64.rpm libvirt-python-0.8.1-27.el6.x86_64.rpm 3 Preparing...                ########################################### [100%] 4    1:libvirt-client         ########################################### [ 33%] 5    2:libvirt                ########################################### [ 67%] 6    3:libvirt-python         ########################################### [100%]
復制代碼

9.進入xen系統

重啟系統,進入xen系統。

嘗試輸入如下命令:xm-list ,xm-info

再接著嘗試如下命令:virt-install,嘗試著安裝虛擬機

如果顯示的錯誤如下:

1 ERROR unable to connect to ‘localhost:8000′: Connection refused

則需要去做如下修改:

1 解決方案:查看libvirtd服務是否啟動,關閉防火墻,在/etc/xen/xend-config.sxp  2 (xend-http-server yes) 3 # Port xend should use for the HTTP interface, if xend-http-server is set. 4 (xend-port 8000) 5 去掉上面兩個括弧的注釋,ok

再重新啟動xend服務

1 service xend restart

 

至此,可以嘗試在桌面上氣筒virtual machine manager 去創建虛擬機。
創建過程如果如下問題:

可以系統路勁的問題,在usr/lib/xen/bin下找到qemu-dm放到lib64下對應的路徑。

就ok。

 

10.配置網橋橋接模式

修改ifcfg-eth0如下:

復制代碼
 1 DEVICE="eth0"  2 BOOTPROTO="static"  3 HWADDR="**********“  4 NM_CONTROLLED="no"  5 ONBOOT="yes"  6 IPADDR="*******”  7 NETMASK="255.255.0.0"  8 GATEWAY="********"  9 TYPE=Ethernet 10 DNS1="8.8.8.8" 11 DNS2="8.8.4.4" 12 BRIDGE=br100
復制代碼

創建ifcfg-br100文件,內容如下:

復制代碼
 1 DEVICE="br100"  2 BOOTPROTO="static"  3 HWADDR="*********"  4 NM_CONTROLLED="no"  5 ONBOOT="yes"  6 IPADDR="*******"  7 NETMASK="255.255.0.0"  8 GATEWAY="*******"  9 TYPE=Bridge 10 DEFROUTE=yes 11 DNS1="8.8.8.8" 12 DNS2="8.8.4.4"
復制代碼

11.ok,至此,xen的安裝結束了,可以放心大膽的創建虛擬機了。