二、需求分析及參考網頁
首先,企業想架設XEN在服務器,且不影響其它服務的性能的前提下,所以在配置虛擬機時domain0應該設置一定的MEMORY;二編譯新的內核以支持XEN的半虛擬化的支持;三創建或克隆SLAVEWRE的XEN的鏡像,並能夠進行像LINUX文本命令的執行;
http://www.tek-life.org/2010/05/20/centos5-4%E5%AE%89%E8%A3%85xen/
http://blog.csdn.net/handw/archive/2010/04/22/5515164.aspx
三、安裝配置及錯誤分析
內核的升級與補丁安裝
安裝需要的軟件包
首先最小化安裝 CentOS,然後安裝編譯 Xen 和 Linux xen kernel 所需要的軟件包:
# yum groupinstall "Development Tools"
# yum install hmaccalc ncurses-devel zlib-devel openssl-devel python-devel \
bridge-utils libtool-ltdl iasl xorg-x11-drv-evdev xorg-x11-drv-fbdev \
xorg-x11-drv-i810-devel xorg-x11-drv-via-devel xorg-x11-proto-devel \
xorg-x11-server-sdk xorg-x11-xtrans-devel
安裝完以上軟件包後,剩下的操作就和在 Debian 上編譯和安裝 Xen 差不多了。
安裝 Xen hypervisor 和 tools
到 http://www.xen.org/products/xen_source.html 下載最新的 Xen 源代碼,然後解開、編譯、安裝,標準的 Linux 軟件源碼安裝動作:
$ tar zxvf xen-4.0.0.tar.gz
$ cd xen-4.0.0/
$ make xen tools stubdom
# make install-xen install-tools install-stubdom
上面 make stubdom 的時候會從網上自動下載一些東西
# /sbin/chkconfig --add xend
# /sbin/chkconfig --add xendomains
# /sbin/chkconfig xend on
# /sbin/chkconfig xendomains on
安裝 Xen 內核
下載 Linux 內核後給內核打 xen 補丁:
$ cd
$ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.8.tar.bz2
$ tar -xjf linux-2.6.31.8.tar.bz2
$ wget http://gentoo-xen-kernel.googlecode.com/files/
xen-patches-2.6.31-10.tar.bz2
$ mkdir xenpatch-2.6.31.8
$ cd xenpatch-2.6.31.8
$ tar -xjf ../xen-patches-2.6.31-10.tar.bz2
$ cd ..
$ cd linux-2.6.31.8
$ for i in `ls ../xenpatch-2.6.31.8/`; \
do patch -p1 < ../xenpatch-2.6.31.8/"$i"; done
配置帶 xen 的 Linux 內核:
$ make menuconfig
Processor type and features --->
[*] Enable Xen compatible kernel
Networking support --->
Networking options --->
<*> 802.1d Ethernet Bridging
Device Drivers --->
XEN --->
[*] Privileged Guest (domain 0)
Backend driver support
Block-device backend driver
Block-device tap backend driver
Block-device tap backend driver 2
Network-device backend driver
PCI-device backend driver
SCSI backend driver
USB backend driver
<*> Block-device frontend driver
<*> Network-device frontend driver
SCSI frontend driver
USB frontend driver
<*> Framebuffer-device frontend driver
<*> Keyboard-device frontend driver
[*] Disable serial port drivers
<*> Export Xen attributes in sysfs
Xen version compatibility (3.3.0 and later) --->
3.3.0 and later
配置好內核參數以後,保存並退出,開始編譯 Linux 內核:
$ make
$ make modules
# make modules_install
# make install
# /sbin/depmod 2.6.31.8
更新 grub:
# vi /boot/grub/menu.lst
...
title CentOS (2.6.31.8-xen)
root (hd0,0)
kernel /xen-4.0.0.gz
module /vmlinuz-2.6.31.8 ro root=/dev/VolGroup00/LogVol00
module /initrd-2.6.31.8.img
...
重啓系統,確認 Xen 安裝成功:
# reboot
# uname -a
Linux localhost.localdomain 2.6.31.8 #2 SMP Tue Apr 20 11:19:19 SAST 2010 x86_64 GNU/Linux
# xm list
Name ID Mem VCPUs State Time(s)
Domain-0 0 3713 4 r----- 36.0
安裝錯誤分析如下
make[8]: *** [iasl] Error 1
make[8]: Leaving directory `/source/xen-4.0.0/tools/firmware/hvmloader/acpi’
make[7]: *** [subdir-all-acpi] Error 2
make[7]: Leaving directory `/source/xen-4.0.0/tools/firmware/hvmloader’
make[6]: *** [subdirs-all] Error 2
make[6]: Leaving directory `/source/xen-4.0.0/tools/firmware/hvmloader’
make[5]: *** [subdir-all-hvmloader] Error 2
make[5]: Leaving directory `/source/xen-4.0.0/tools/firmware’
make[4]: *** [subdirs-all] Error 2
make[4]: Leaving directory `/source/xen-4.0.0/tools/firmware’
make[3]: *** [all] Error 2
make[3]: Leaving directory `/source/xen-4.0.0/tools/firmware’
make[2]: *** [subdir-install-firmware] Error 2
make[2]: Leaving directory `/source/xen-4.0.0/tools’
make[1]: *** [subdirs-install] Error 2
make[1]: Leaving directory `/source/xen-4.0.0/tools’
make: *** [install-tools] Error 2
我們注意到,前面其實已經將iasl複製到usr/local/bin下了,在G.cn上搜索了一下,複製後需要改變其權限:
cd compiler ——>make——>cp iasl /usr/local/bin
chown root:root /usr/local/bin/iasl
XEN 安裝完成重啓不存在XEN的TITLE
因爲對grub 2.0的不兼容
只能安裝grub0.7
然後grub-install –recheck /dev/sda
RROR: /bin/lvm exited abnormally (pid 326)
mount: error 6 mounting ext3
mount: error 2 mounting none
switchroot: mount failed: 22
umount: /initrd/dev failed: 2
Kernel panic - not syncing: Attempted to kill init!
硬件的問題
install error: No module ehci-hcd found for kernel 2.6.18.8-xen0 (I added the module "EHCI HCD" in buildin Xen0-Kernel)
I looked at the configuration file for my current kernel and found that it had the line:
CONFIG_USB_EHCI_HCD=m
mkinitrd -v -f --with=sd_mod --with=scsi_mod
CONFIG_SCSI_BUSLOGIC=M
CONFIG_USB_HCD_UHCI=M
CONFIG_USB_EHCI_HCD=M
CONFIG_USB_OHCI_HCD=M
CONFIG_ATA_PIIX=M
CONFIG_SYSFS_DEPRECATED=y
CONFIG_SYSFS_DEPRECATED_V2=y
No module dm-mem-cache found for kernel 2.6.18-92.1.13.el5, aborting.
--without-dmraid
make
> sh> make modules
> sh> make modules_install
mount: could not find filesystem '/dev/root'
mkinitrd --with=xennet --preload=xenblk initrd.img $(uname -r)
kernel引導結束後,init切換跟分區的時候使用了設備文件/dev/root, 而這個設備文件沒有被包含在新生成的initrd文件內,也沒有存放在磁盤上.導致切換跟分區失敗。
make ARCH=arm menuconfig
ernel Features --->
[*] Use the ARM EABI to compile the kernel
[*] Allow old ABI binaries to run with this kernel (EXPERIMENTA)
把這個選上就可以了
xend is not starting
The PVOPS changed how the /proc/xen is exported to user-space. Now it is considered an XenFS filesystem that has to be mounted to be usable. Make sure you have this in /etc/fstab:
xenfs /proc/xen xenfs defaults 0 0
xm list Unable to connect to xend
/var/log/xen/xend.log
[2007-10-11 16:08:05 6461] INFO (SrvDaemon:226) Xend stopped due to
signal 15.
[2007-10-11 16:10:42 6702] INFO (SrvDaemon:331) Xend Daemon started
[2007-10-11 16:10:42 6702] INFO (SrvDaemon:335) Xend changeset:
unavailable.
[2007-10-11 16:10:42 6702] INFO (SrvDaemon:342) Xend version: Unknown.
[2007-10-11 16:10:42 6702] ERROR (SrvDaemon:353) Exception starting
xend (no element found: line 1, column 0)
Traceback (most recent call last):
File "usr/lib/python2.4/site-packages/xen/xend/server/SrvDaemon.py",
line 345, in run
servers = SrvServer.create()
File "usr/lib/python2.4/site-packages/xen/xend/server/SrvServer.py",
line 254, in create
root.putChild('xend', SrvRoot())
File "usr/lib/python2.4/site-packages/xen/xend/server/SrvRoot.py",
line 40, in __init__
self.get(name)
File "usr/lib/python2.4/site-packages/xen/web/SrvDir.py", line 82,
in get
val = val.getobj()
File "usr/lib/python2.4/site-packages/xen/web/SrvDir.py", line 52,
in getobj
self.obj = klassobj()
File "usr/lib/python2.4/site-packages/xen/xend/server/SrvNode.py",
line 30, in __init__
self.xn = XendNode.instance()
File "usr/lib/python2.4/site-packages/xen/xend/XendNode.py", line
658, in instance
inst = XendNode()
File "usr/lib/python2.4/site-packages/xen/xend/XendNode.py", line
60, in __init__
saved_host = self.state_store.load_state('host')
File "usr/lib/python2.4/site-packages/xen/xend/XendStateStore.py",
line 104, in load_state
dom = minidom.parse(xml_path)
File "/usr/lib/python2.4/xml/dom/minidom.py", line 1915, in parse
return expatbuilder.parse(file)
File "/usr/lib/python2.4/xml/dom/expatbuilder.py", line 924, in
parse
result = builder.parseFile(fp)
File "/usr/lib/python2.4/xml/dom/expatbuilder.py", line 211, in
parseFile
parser.Parse("", True)
ExpatError: no element found: line 1, column 0
安裝libvir
./autogen.sh --prefix=$HOME/usr
make
make install
安裝完成後執行 hg debuginstall 時出現了錯誤:
hg --version
abort: couldn't find mercurial libraries in [/usr/local/bin /usr/lib/python2.6 /usr/lib/python2.6/plat-linux2 /usr/lib/python2.6/lib-tk /usr/lib/python2.6/lib-old /usr/lib/python2.6/lib-dynload /usr/lib/python2.6/dist-packages /usr/lib/python2.6/dist-packages/PIL /usr/lib/python2.6/dist-packages/gst-0.10 /var/lib/python-support/python2.6 /usr/lib/python2.6/dist-packages/gtk-2.0 /var/lib/python-support/python2.6/gtk-2.0 /usr/local/lib/python2.6/dist-packages]
(check your install and PYTHONPATH)
解決方法:
export PYTHONPATH=/usr/local/lib/python2.6/site-packages
或者:
把上面的加到這兩個文件中的一個: .bashrc、/etc/profile。
四.注意問題彙總
1,版本問題是linux的最頭疼的問題
2,務必使用最新版本(包括:Fedora, Xen, 及各種軟件)
3,堅決使用root權限安裝
4,深刻理解linux的標準文件系統目錄結構
5,高版本的內核環境中不能編譯低版本的內核,即使編譯成功,也不能啓動
6,Fedora Core 6 切忌不要選擇virtualization,否則就被安裝爲FC6-XEN
7,劃分分區時,一定要預先估算可能佔用的容量,尤其是編譯時可能產生大量中間結果
8,安裝FC時務必關閉防火牆,包括iptables和SELinux
xen 的配置
Pre-requisites
- python >= 2.4 - virt-manager is written in Python!
- pygtk2 >= 1.99.12-6 - the Python GTK2 bindings are used for the UI
- gnome-python2-gconf >= 1.99.11-7 - GConf stores application preferences
- libvirt-python >= 0.4.0 - libVirt is for talking to Xen, QEMU, KVM and other virtualization backensd
- dbus-python >= 0.61 - optionally expose a service on the bus for control of the UI
- gnome-python-desktop >= 2.15.4 - optionally store VNC server passwords in GNOME keyring
- libxml2-python >= 2.6.23 - used to parse XML from libvirt
- vte >= 0.12.2 - for displaying / interacting with the serial console
- virtinst >= 0.300.3 - python library for assisting in creating VMs
- gtk-vnc-python >= 0.3.4 - GTK widget for displaying VNC sessions
配置
打開 Xen 的配置文件,註釋掉 (network-script network-bridge) 一行,然後加上下面一行:
# vi /etc/xen/xend-config.sxp #(network-script network-bridge) (network-script network-multi-bridge)
然後創建一個 network-multi-bridge 腳本,用來2次執行 network-bridge 腳本:
# vi etc/xen/scripts/network-multi-bridge #!/bin/sh dir=$(dirname "$0") "$dir/network-bridge" "$@" vifnum=0 bridge=xenbr0 netdev=eth0 "$dir/network-bridge" "$@" vifnum=1 bridge=xenbr1 netdev=eth1
重啓 Xen 服務使配置生效:
# /etc/init.d/xend restart
"Unable to open a connection to the Xen hypervisor/daemon. Verify that
- a xen host kernel was booted
- the xen service has been started
When you install Xen. You will need to configure xend using the file /etc/xen/xend-config.sxp
In this file search for the following line:
#(xend-unix-server no)
uncomment it and change it to: (xend-unix-server yes)
If you want to connect to xend through http then you should uncomment and change the (xend-http-server no) to 'yes'. (This has security concerns and its not safe)
http://imcsx.com/archives/104.html
· 如果你裝好的 Xen 不能正常啓動,提示:
Panic on CPU 0:
IO-APIC : timer doesn't work!
或者卡在 “qc timeout”、“failed to IDENTIFY” 類似這種消息:
scsi0 : sata_sil
sata1: SATA link up 1.5 Gbps (SStatus 113 SControl 310)
sata1.00: qc timeout (cmd 0xec)
sata1.00: failed to IDENTIFY (I/O error, err_mask=0x4)
時,那麼可以參考一下我的 grub.conf:
kernel /boot/xen.gz noapic
module /boot/kernel-2.6.18-xen0 root=/dev/md2 console=tty1 pci=noacpi
· 在建立好一個 domU 的配置文件後,需要按照把 stage3 安裝包解壓到配置中指定的 root 分區中,否則會出現類似如下的錯誤:
VFS: Mounted root (ext2 filesystem) readonly.
Freeing unused kernel memory: 136k freed
Warning: unable to open an initial console.
Kernel panic - not syncing: No init found. Try passing init= option to kernel.
extra = "TERM=xterm xencons=tty console=tty1"
否則你會發現 domU 啓動到一定階段後會停滯不動的假死現象:
kjournald starting. Commit interval 5 seconds
EXT3-fs: mounted filesystem with ordered data mode.
VFS: Mounted root (ext3 filesystem) readonly.
Freeing unused kernel memory: 136k freed
(以下不再輸出)
slaveware 的配置文件如下
kernel = “/boot/vmlinuz-2.6.18.8-xen”
kernek =128
name = “slackware”
vif = [‘ip=192.168.122.3’]
netmask = “255.255.255.0”
hostname = “slackname”
disk = [‘file:/root/xen/slackware.11-0.img.sda,w’,’file:/rootxen/slackware.swap,sda2,w’]
root = “/dev/sda1 rw”
extra =” TERM=xterm xencons=tty console=tty1”
對/boot/grub/grub.conf的配置文件的如下
Title Xen3.4.0 (2.6.18.8)
Root (hd0,2)
kernel /boot/xen-3.4.0.gz dom0_mem=512M loglvl=all guest_loglvl=all
module /boot/vmlinuz-2.6.18.8-xen ro root=/de/sda3 console=ttyS0 console=tty0 pci=noacpi
module /boot/initrd=2.6.18.8-xen.img
升級python-lib .因爲我安裝的 virtul-manager是0.8.4