本文可转载,但请声明出处。联系方式: [email protected]
Xen4CentOS 项目致力提供建基于 Xen-4.2 的 xen 堆栈、一个以 3.4 LTS 主流树为本的 Linux 内核、并在发行版本内以 libvirt 和 qemu 的相关工具来支持 Xen。它由 Xen 计划、Citrix Xen 开源小组、CentOS 开发者、GoDaddy 云端运作小组、Rackspace 网站讬管及 CentOS QA 小组共同参与,旨在为CentOS-5/Xen 的用户把他们的基本结构移植及升级至 CentOS-6,同一时间更引入较新的 Xen-4 工具链。
目前该项目有一些已知问题需要注意:
首先明确对机器的要求:拥有至少1.5GB内存,10GB以上的磁盘空间供根目录/使用。
其次运行Xen的主机应该是一台 CentOS-6/x86_64 的最少安装;CentOS 的 Xen4 堆栈只在 CentOS-6.4 及往后版本上进行测试及检验。
最后在进行下一步之先,请确保 yum 只启用了 CentOS 的软件库,而且你已采用了最新的更新。
CentOS6.5的最小安装ISO文件CentOS-6.5-x86_64-minimal.iso可以从搜狐镜像服务器上获取: http://mirrors.sohu.com/centos/6/isos/x86_64
CentOS6.5系统安装以后,关闭SELinux的功能(缺省为enforcing状态):
[root@centos ~]# getenforce Enforcing [root@centos ~]# vi /etc/sysconfig/selinux # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted [root@centos ~]# reboot更新系统,安装perl工具包(Xen工具需要使用Perl工具包,CentOS最小安装不支持Perl):
[root@centos ~]# yum install perl [root@centos ~]# yum update [root@centos ~]# reboot
[root@centos ~]# yum install centos-release-xen [root@centos ~]# yum install xen [root@centos ~]# /usr/bin/grub-bootxen.sh
Xen是在linux内核之上运行,所以我们必须告诉grub先引导Xen,然后顺序引导dom0的linux内核。要达至这个目的,centos-release-xen 的组件内已包含一个脚本grub-bootxen.sh,用来自动修改/boot/grub/grub.conf配置文件:
[root@centos ~]# more /usr/bin/grub-bootxen.sh #!/bin/bash # # (c) Simon Rowe, 2013 # (c) Karanbir Singh, 2013 default=$(grubby --default-kernel) kver=$(expr $default : '.*vmlinuz-\(.*\)') [ -n "$kver" ] || exit 0 initrd=$(grubby --info $default | sed -ne 's/^initrd=//p') new-kernel-pkg --install --package kernel --multiboot=/boot/xen.gz "--mbargs=dom0_mem=1024M,max:1024M loglvl=all guest_loglvl=all" - -initrdfile=$initrd $kver exit $?修改后的grub.conf文件:
[root@centos ~]# more /boot/grub/grub.conf # grub.conf generated by anaconda # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a /boot partition. This means that # all kernel and initrd paths are relative to /boot/, eg. # root (hd0,0) # kernel /vmlinuz-version ro root=/dev/mapper/vg_centos-LogVol01 # initrd /initrd-[generic-]version.img #boot=/dev/sda default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title CentOS (3.10.32-11.el6.centos.alt.x86_64) root (hd0,0) kernel /xen.gz dom0_mem=1024M,max:1024M loglvl=all guest_loglvl=all module /vmlinuz-3.10.32-11.el6.centos.alt.x86_64 ro root=/dev/mapper/vg_centos-LogVol01 rd_NO_LUKS rd_LVM_LV=vg_centos/LogVo l00 rd_LVM_LV=vg_centos/LogVol01 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM LANG=en_U S.UTF-8 rhgb quiet module /initramfs-3.10.32-11.el6.centos.alt.x86_64.img .....系统重启以后可以检查运行版本是否与grub.conf中配置一致及Xen是否在运行中:
[root@centos ~]# uname -r 3.10.32-11.el6.centos.alt.x86_64 [root@centos ~]# xm list Name ID Mem VCPUs State Time(s) Domain-0 0 1024 4 r----- 20.6
配置之前相关的网络配置:
[root@centos ~]# more /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 HWADDR=00:0C:29:FA:F3:90 TYPE=Ethernet UUID=c49a6cdc-44fc-4908-ad81-4df0d3984c65 ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=none IPADDR=10.220.33.79 PREFIX=24 GATEWAY=10.220.33.1 DNS1=10.220.32.12 DEFROUTE=yes NAME=eth0 [root@centos network-scripts]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:FA:F3:90 inet addr:10.220.33.79 Bcast:10.220.33.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fefa:f390/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1469 errors:0 dropped:0 overruns:0 frame:0 TX packets:486 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:257573 (251.5 KiB) TX bytes:59515 (58.1 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) [root@centos ~]# brctl show bridge name bridge id STP enabled interfaces
# To bridge network traffic, like this: # # dom0: ----------------- bridge -> real eth0 -> the network # | # domU: fake eth0 -> vifN.0 -+创建及修改过程log:
[root@centos ~]# brctl addbr xenbr0 [root@centos ~]# brctl show bridge name bridge id STP enabled interfaces xenbr0 8000.000000000000 no [root@centos ~]# cd /etc/sysconfig/network-scripts [root@centos network-scripts]# cp ifcfg-eth0 ifcfg-xenbr0 [root@centos network-scripts]# vi ifcfg-xenbr0 DEVICE=xenbr0 TYPE=Bridge ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=none IPADDR=10.220.33.79 PREFIX=24 GATEWAY=10.220.33.1 DNS1=10.220.32.12 DEFROUTE=yes NAME=xenbr0 [root@centos network-scripts]# vi ifcfg-eth DEVICE=eth0 HWADDR=00:0C:29:FA:F3:90 TYPE=Ethernet UUID=c49a6cdc-44fc-4908-ad81-4df0d3984c65 ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=none DEFROUTE=yes NAME=eth0 BRIDGE=xenbr0 [root@centos network-scripts]# service network restart查看实际生效的配置:
[root@centos ~]# brctl show bridge name bridge id STP enabled interfaces xenbr0 8000.000c29faf390 no eth0 [root@centos ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:FA:F3:90 inet6 addr: fe80::20c:29ff:fefa:f390/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:88988 errors:0 dropped:0 overruns:0 frame:0 TX packets:605 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:8708966 (8.3 MiB) TX bytes:94984 (92.7 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:10 errors:0 dropped:0 overruns:0 frame:0 TX packets:10 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1056 (1.0 KiB) TX bytes:1056 (1.0 KiB) xenbr0 Link encap:Ethernet HWaddr 00:0C:29:FA:F3:90 inet addr:10.220.33.79 Bcast:10.220.33.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fefa:f390/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:18463 errors:0 dropped:0 overruns:0 frame:0 TX packets:330 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1544430 (1.4 MiB) TX bytes:62200 (60.7 KiB)
[root@centos etc]# yum groupinstall Desktop [root@centos etc]# yum groupinstall "X Window System" [root@centos etc]# vi inittab # inittab is only used by upstart for the default runlevel. # # ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # # System initialization is started by /etc/init/rcS.conf # # Individual runlevels are started by /etc/init/rc.conf # # Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf # # Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf, # with configuration in /etc/sysconfig/init. # # For information on how to write upstart event handlers, or how # upstart works, see init(5), init(8), and initctl(8). # # Default runlevel. The runlevels used are: # 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this) # id:5:initdefault:
1. http://wiki.centos.org/zh/HowTos/Xen