虚拟化技术是云计算实现弹性计算的核心技术。在构建云计算平台中,虚拟机的安装是基础。常用的虚拟机工具很多,如VMware、XEN、KVM、Virtual PC等,这些工具使得用户可以在单台物理PC上(称为宿主机)虚拟出多个虚拟机VM(Virtual machine),由于在每个VM上可以安装与宿主机不同的操作系统。因而可以实现在一台物理PC上模拟出多台安装有不同操作系统的“PC”。在云计算中,用户可以向云平台申请租用虚拟机,虚拟机的配置,如CPU的核数、主频,内存,存储容量等可以根据需要自己设定,并可动态修改。现有虚拟机工具多支持这些功能,然而很多工具如VMware、XEN-Server等提供的免费测试工具多只提供GUI接口,用户只能通过图形界面实现虚拟机的创建和配置,无法实现动态的配置,以至于构建的云平台退化为不具有弹性的“虚拟机平台”。
Xen 是由剑桥大学开发的一款开放源代码虚拟机工具软件,支持虚拟机的各种配置和动态创建,最重要的是提供了丰富的用户管理接口。
下面为安装过程。
1.1 Linux system:Fedora 12 x86_64
测试PC:HP4321S联想笔记本电脑
SELinux is disabled. Please refer here for detail: Disabled SELinux on Fedora.
Disable SELINUX using your favorite editor to open the SELINUX configuration file. For example: $:su 切换到root用户 vi /etc/selinux/config Edit the configuration file so that SELINUX has the value of "disabled". It should look like the following: SELINUX=disabled |
ext3 is recommended for the file system of disk partition for /boot.
Update the system:
# yum updateThe Xen and libvirt packages in Fedora should not be installed to avoid conflict.
# yum erase xen* libvirtYou may need to install packages depended by this. You can try this for solving the dependencies:
# yum install make gcc -y;The we can make Xen and Xen tools: (xen-3.4.3目录下)
$ make xenApply all the patches downloaded above following the patch number.
You may need to install patch if it isn’t installed:
# yum install patchThis patch.sh script can be used (we assume the patch and the kernel are in the same directory):
patch.sh:
#!/bin/bashPut this script into Linux source directory(linux-2.6.32.13目录下) and execute:
$ sh ./patch.shThe structure of these directories are as follows:
▲注:结构如上图。按照patch脚本,Linux-2.6.32.13 和xen=patches-2.6.32-2放在同一个目录。
1.3.4 Configure Xenified Linux kernelA working configuration file that I used can be downloaded directly from here:
config-for-xenified-linux-2.6.32.13
Just download this file, put it into the kernel source code file directory(linux-2.6.32.13目录下) and rename it to .config.
Other than use my configuration file, you can also configure it by yourself by using “make menuconfig”.
Make sure you build the kernel with these components enabled:
Processor type and features --->X can be two times of the number of the processor. We use this to let make invoke compilation work in X-wayparallel.
1.3.6 Install modules and kernel (linux-2.6.32.13目录下)Add one entry for Xen in /boot/grub/grub.conf. This is an example entry:
# vi /boot/grub/grub.conf
title Xen3.4.3- Xenified Linux 2.6.32.13 root (hd0,0) kernel /xen-3.4.3.gz cOnsole=vga vga=ask noreboot module /vmlinuz-2.6.32.13 ro root=/dev/mapper/VolGroup-LogVol_root noiswmd LANG=en_US.UTF-8 SYSFOnT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us module /initramfs-2.6.32.13.img |
The root and other parameters may be different depending on the configuration.
# 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,7) # kernel /vmlinuz-version ro root=/dev/sda11 # initrd /initrd-[generic-]version.img #boot=/dev/sda default=3 timeout=5 splashimage=(hd0,7)/grub/splash.xpm.gz hiddenmenu title Xen 3.4.3 -Xenified Linux 2.6.32.13 root (hd0,7) kernel /xen-3.4.3.gz cOnsole=vga vga=ask noreboot module /vmlinuz-2.6.32.13 ro root=UUID=7329a86e-6254-48ab-a084-69fed3fc6881 nomodeset LANG=en_US.UTF-8 SYSFOnT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us rhgb quiet module /initramfs-2.6.32.13.img title Fedora (2.6.32.26-175.fc12.x86_64) root (hd0,7) kernel /vmlinuz-2.6.32.26-175.fc12.x86_64 ro root=UUID=7329a86e-6254-48ab-a084-69fed3fc6881 nomodeset LANG=en_US.UTF-8 SYSFOnT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us rhgb quiet initrd /initramfs-2.6.32.26-175.fc12.x86_64.img title Fedora (2.6.31.5-127.fc12.x86_64) root (hd0,7) kernel /vmlinuz-2.6.31.5-127.fc12.x86_64 ro root=UUID=7329a86e-6254-48ab-a084-69fed3fc6881 nomodeset LANG=en_US.UTF-8 SYSFOnT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us rhgb quiet initrd /initramfs-2.6.31.5-127.fc12.x86_64.img title Other rootnoverify (hd0,0) chainloader +1 |
Check whether Xend and Xendomains services are automatically started in level 3-5:
# chkconfig --list | grep xendIt should be like this:
xend 0:off 1:off 2:off 3:on 4:on 5:on 6:offAfter booting the system, you can try to use xm to check xen info
# xm infoThen xm command can be used to start up DomUs.
[root@czm003fedora12 czm]# xm info host : czm003fedora12 release :2.6.32.13 version : #1 SMP Sun Oct 7 08:30:28 HKT 2012 machine : x86_64 nr_cpus : 4 nr_nodes : 1 cores_per_socket : 2 threads_per_core : 2 cpu_mhz : 2266 hw_caps : bfebfbff:28000800:00000000:00000740:0098e3bd:00000000:00000001:00000000 virt_caps : hvm total_memory : 1970 free_memory : 121 node_to_cpu : node0:0-3 node_to_memory : node0:121 xen_major : 3 xen_minor : 4 xen_extra : .3 xen_caps : xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64 xen_scheduler : credit xen_pagesize : 4096 platform_params : virt_start=0xffff800000000000 xen_changeset : unavailable cc_compiler : gcc version 4.4.4 20100630 (Red Hat4.4.4-10) (GCC) cc_compile_by : czm cc_compile_domain : cc_compile_date : Sun Oct 7 08:04:56 HKT 2012 xend_config_format : 4 [root@czm003fedora12 czm]# |
#xm list
[root@czm003fedora12 czm]# xm list Name ID Mem VCPUs State Time(s) Domain-0 0 1824 4 r----- 80.2 [root@czm003fedora12 czm]# |
至此,只是在物理PC上安装完XEN虚拟机监控器(可理解为宿主环境),要创建虚拟机还需要在宿主环境上上安装操作系统。