准備工作
- CentOS 6.0, Minimal安裝, SELINUX=disabled, 配置好SRPM的repo地址
操作步驟
1. 安裝基本軟件包
- yum -y install openssh-clients gcc g++ make automake autoconf wget glibc-devel glibc-devel.i686 libaio rpm-build yum-utils transfig libidn-devel zlib-devel texi2html SDL-devel curl-devel libX11-devel python-devel ghostscript tetex-latex ncurses-devel gtk2-devel libaio-devel texinfo dev86 gettext gnutls-devel openssl-devel pciutils-devel libuuid-devel iasl bzip2-devel xz-devel e2fsprogs-devel PyXML kpartx bridge-utils libsysfs-devel libsysfs libnl-devel libtool nfs-utils libxml2-devel xhtml1-dtds readline-devel libudev-devel libpciaccess-devel yajl-devel libpcap-devel avahi-devel dnsmasq cyrus-sasl-devel polkit lvm2 iscsi-initiator-utils parted-devel device-mapper-devel numactl-devel libcap-ng-devel netcf-devel ebtables lzop nc cyrus-sasl-md5 python-virtinst
2. 安裝qemu
- wget http://mirrors.ustc.edu.cn/Fedora/linux/updates/13/x86_64/qemu-common-0.13.0-1.fc13.x86_64.rpm
- wget http://mirrors.ustc.edu.cn/fedora/linux/updates/13/x86_64/qemu-img-0.13.0-1.fc13.x86_64.rpm
- rpm -Uvh qemu-*.rpm
3. 通過srpm編譯安裝Xen
- wget http://mirrors.ustc.edu.cn/fedora/linux/updates/15/SRPMS/xen-4.1.1-3.fc15.src.rpm
- rpm -i xen-4.1.1-3.fc15.src.rpm
- cd ~/rpmbuild/SPECS/
- rpmbuild -bb xen.spec
- cd ~/rpmbuild/RPMS/x86_64/
- rpm -Uvh xen-*4.1.1-*.rpm
4. 修改bridge-utils, CentOS 6.0的默認內核被加了IGMP的patch, 其自帶的bridge-utils也打了這個patch, 在非rhel6的內核上運行會出現很多沒用的提示。
- yumdownloader --source bridge-utils
- rpm -i bridge-utils-1.2-9.el6.src.rpm # 版本可能不同
- cd ~/rpmbuild/SPECS/
- vi bridge-utils.spec
- # 去除兩行有patch4的地方, 也即有IGMP的patch的行
- rpmbuild -bb bridge-utils.spec
- cd ~/rpmbuild/RPMS/x86_64/
- rpm -Uvh --force bridge-utils-1.2-9.el6.x86_64.rpm
提供一個patch
- --- bridge-utils.spec.orig 2010-04-30 00:29:16.000000000 +0800
- +++ bridge-utils.spec 2011-09-30 23:27:19.090747706 +0800
- @@ -10,7 +10,6 @@
- Patch1: bridge-utils-1.2-show-ports.patch
- Patch2: bridge-utils-1.2-foreach.patch
- Patch3: bridge-utils-1.2-params.patch
- -Patch4: bridge-utils-1.2-Add_IGMP_snooping_support.patch
-
- BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
- BuildRequires: libsysfs-devel autoconf
- @@ -32,7 +31,6 @@
- %patch1 -p1
- %patch2 -p1
- %patch3 -p1
- -%patch4 -p1 -b .Add_IGMP_snooping_support
-
- %build
- autoconf
5. 安裝libvirt, CentOS6自帶的不支持xen, 需要打開xen的選項重新編譯
- yumdownloader --source libvirt
- rpm -i libvirt-0.8.1-27.el6_0.6.src.rpm # 版本可能不同
- cd ~/rpmbuild/SPECS/
- vi libvirt.spec # 按下面的patch修改
- rpmbuild -bb libvirt.spec
- cd ~/rpmbuild/RPMS/x86_64/
- rpm -Uvh libvirt-*0.8.1*.rpm
Patch:
- --- libvirt.spec.orig 2010-08-18 15:02:53.000000000 +0300
- +++ libvirt.spec 2010-11-15 14:17:36.388996162 +0200
- @@ -104,7 +104,7 @@
- %ifnarch x86_64
- %define with_qemu 0
- %endif
- -%define with_xen 0
- +%define with_xen 1
- %endif
-
- # If Xen isn't turned on, we shouldn't build the xen proxy either
6. 安裝python-virtinst,舊的版本不支持的參數太多了
- # 從RedHat網站下載srpm
- wget http://ftp.redhat.com/redhat/linux/enterprise/6Server/en/os/SRPMS/python-virtinst-0.500.5-3.el6.src.rpm
-
- rpm -i python-virtinst-0.500.5-3.el6.src.rpm
-
- cd ~/rpmbuild/SPECS/
- rpmbuild -bb python-virtinst.spec
-
- cd ~/rpmbuild/RPMS/noarch/
- rpm -Uvh --force python-virtinst-*.rpm
7. 編譯安裝內核
- # 從github下載內核
- wget https://github.com/jsgf/linux-xen/tarball/xen-2.6.32.46 -O kernel-xen-2.6.32.46.tar.gz
- # 下載config
- wget http://pasik.reaktio.net/xen/kernel-config/config-2.6.32.43-pvops-dom0-xen-stable-x86_64
-
- # 可以先修改config裡面的CONFIG_LOCALVERSION項, 給這個內核起個別名, 比如-dom0-xen, 以下為沒有修改的情況
- tar xzf kernel-xen-2.6.32.46.tar.gz
- cp config-2.6.32.43-pvops-dom0-xen-stable-x86_64 jsgf-linux-xen-1c3f03c/.config
- cd jsgf-linux-xen-1c3f03c
- make oldconfig
- make -j4 bzImage
- make -j4 modules
- make modules_install
- depmod -a 2.6.32.46
- cp -a arch/x86/boot/bzImage /boot/vmlinuz-2.6.32.46
- cp -a System.map /boot/System.map-2.6.32.46
- cp -a .config /boot/config-2.6.32.46
- cd /boot/
- dracut --force initramfs-2.6.32.46.img 2.6.32.46
-
- # 關閉ksm, 跟xen不兼容
- chkconfig ksm off
- chkconfig ksmtuned off
8. 編輯/boot/grub/menu.lst, 添加
- title Xen 4.0 with Linux 2.6.32.46
- root (hd0,0)
- kernel /xen.gz dom0_mem=2048M loglvl=all guest_loglvl=all
- module /vmlinuz-2.6.32.46 ro root=/dev/sda2 rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM KEYBO
- ARDTYPE=pc KEYTABLE=us SYSFONT=latarcyrheb-sun16 LANG=en_US.UTF-8 nomodeset
- module /initramfs-2.6.32.46.img
9. 編輯/etc/xen/xend-config.sxp, 按自己的需求修改
- ......
- (xend-http-server yes)
- (xend-unix-server yes)
- (xend-tcp-xmlrpc-server yes)
- ......
- (xend-relocation-server yes)
- ......
- (xend-tcp-xmlrpc-server-address '0.0.0.0')
- (xend-tcp-xmlrpc-server-port 8006)
- ......
- (xend-relocation-port 8002)
- ......
- (xend-address localhost)
- ......
- (xend-relocation-address '0.0.0.0')
- ......
- ......
- ......
10. 配置libvirtd
- groupadd libvirt
- vi /etc/libvirt/libvirtd.conf
- unix_sock_group = "libvirt"
- unix_sock_ro_perms = "0777"
- unix_sock_rw_perms = "0770"
11. 重啟, 啟動Xen的內核
12. 把上面做的事情, 寫成一套腳本