设为首页 收藏本站
查看: 1469|回复: 0

[经验分享] Xen虚拟机的安装

[复制链接]

尚未签到

发表于 2015-4-13 11:39:13 | 显示全部楼层 |阅读模式
  虚拟化技术是云计算实现弹性计算的核心技术。在构建云计算平台中,虚拟机的安装是基础。常用的虚拟机工具很多,如VMware、XEN、KVM、Virtual PC等,这些工具使得用户可以在单台物理PC上(称为宿主机)虚拟出多个虚拟机VM(Virtual machine),由于在每个VM上可以安装与宿主机不同的操作系统。因而可以实现在一台物理PC上模拟出多台安装有不同操作系统的“PC”。在云计算中,用户可以向云平台申请租用虚拟机,虚拟机的配置,如CPU的核数、主频,内存,存储容量等可以根据需要自己设定,并可动态修改。现有虚拟机工具多支持这些功能,然而很多工具如VMware、XEN-Server等提供的免费测试工具多只提供GUI接口,用户只能通过图形界面实现虚拟机的创建和配置,无法实现动态的配置,以至于构建的云平台退化为不具有弹性的“虚拟机平台”。
  Xen 是由剑桥大学开发的一款开放源代码虚拟机工具软件,支持虚拟机的各种配置和动态创建,最重要的是提供了丰富的用户管理接口。
  本文根据马博士的安装方法,给出详细的安装流程,并对安装细节做进一步的补充说明。更多的安装方法请关注马博士的个人主页:   
  http://www.cse.ust.hk/~zma/
  http://www.zhiqiangma.com/homepage/
  http://fclose.com/zma/#
  下面为安装过程。

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 update
  The Xen and libvirt packages in Fedora should not be installed to avoid conflict.

# yum erase xen* libvirt
【版本
title Fedora (2.6.32.26-175.fc12.x86_64) 经过update后的版本
title Fedora (2.6.31.5-127.fc12.x86_64)   安装光盘版本
重启系统,从title Fedora (2.6.32.26-175.fc12.x86_64)登录,然后继续下面的任务】
1.2 Build and install Xen hypervisor and tools

1.2.1 Download Xen3.4.3
  

$ wget http://bits.xensource.com/oss-xen/release/3.4.3/xen-3.4.3.tar.gz
$ tar xf xen-3.4.3.tar.gz
  

1.2.2 Build Xen and tools
  You may need to install packages depended by this. You can try this for solving the dependencies:

# yum install make gcc -y;
yum groupinstall "Development Libraries" -y;
yum groupinstall "Development Tools" -y;
yum install transfig texi2html
dev86 glibc-devel
e2fsprogs-devel gitk mkinitrd
iasl xz-devel bzip2-devel
pciutils-libs pciutils-devel
SDL-devel libX11-devel gtk2-devel
bridge-utils PyXML qemu-common
qemu-img mercurial -y
  The we can make Xen and Xen tools: (xen-3.4.3目录下)

$ make xen
$ make tools
1.2.3 Install Xen and tools (xen-3.4.3目录下)

$ make install-xen
$ make install-tools
1.3 Build and install xenified Linux kernel

1.3.1 Download Linux kernel2.6.32.13

$ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.13.tar.bz2
$ tar xf linux-2.6.32.13.tar.bz2

1.3.2 Download2.6.32Xen patches v2

$ wget http://gentoo-xen-kernel.googlecode.com/files/xen-patches-2.6.32-2.tar.bz2
$ mkdir xen-patches-2.6.32-2
$ tar xf xen-patches-2.6.32-2.tar.bz2 -C xen-patches-2.6.32-2

1.3.3 Apply Xen patches
  Apply all the patches downloaded above following the patch number.
  You may need to install patch if it isn’t installed:

# yum install patch
  This patch.sh script can be used (we assume the patch and the kernel are in the same directory):
  patch.sh:

#!/bin/bash
for P in `ls ../xen-patches-2.6.32-2/6*.patch1 | sort`
do
    patch -p1 -s -i $P
    if [ $? = 0 ]; then
        echo $P applied
    else
        echo "Error processing "$P
        exit 1
    fi
done
  Put this script into Linux source directory(linux-2.6.32.13目录下) and execute:

$ sh ./patch.sh
  The structure of these directories are as follows:
DSC0000.jpg
  ▲注:结构如上图。按照patch脚本,Linux-2.6.32.13 和xen=patches-2.6.32-2放在同一个目录。

1.3.4 Configure Xenified Linux kernel
  A 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  --->

  • Symmetric multi-processing support

  • Support sparse irq numbering

  • Enable Xen compatible kernel

    Device Drivers  --->
    XEN  --->

  • Privileged Guest (domain 0)
      Backend driver support (NEW)
        Block-device backend driver (NEW)
        Block-device tap backend driver (NEW)
    < >   Block-device tap backend driver 2 (NEW)
        Network-device backend driver (NEW)
    (8)     Maximum simultaneous transmit requests (as a power of 2) (NEW)
    [ ]     Pipelined transmitter (DANGEROUS) (NEW)
    < >     Network-device loopback driver (NEW)
    < >   PCI-device backend driver (NEW)
    < >   TPM-device backend driver (NEW)
        SCSI backend driver (NEW)
        USB backend driver (NEW)
      Block-device frontend driver
      Network-device frontend driver
        Network-device frontend driver acceleration for Solarflare NICs (NEW)
      SCSI frontend driver (NEW)
      USB frontend driver (NEW)

  •    Taking the HCD statistics (for debug) (NEW)
    [ ]   HCD suspend/resume support (DO NOT USE) (NEW)
      User-space granted page access driver (NEW)
      Framebuffer-device frontend driver (NEW)
        Keyboard-device frontend driver (NEW)

  • Disable serial port drivers (NEW)
      Export Xen attributes in sysfs (NEW)
    (256) Number of guest devices (NEW)
    Xen version compatibility (no compatibility code)  --->

  • Place shared vCPU info in per-CPU storage (NEW)
    1.3.5 Build kernel (linux-2.6.32.13目录下)

    $ make -jX
      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目录下)

    # make modules_install install
    【这一步执行时间很长,中间有停顿现象】
    1.4 Configure grub
      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
      

      

    1.5 Make Xend and Xendomains services automatically start when system boots

    # cd /etc/init.d/
    # chkconfig --add xend
    # chkconfig --add xendomains
      Check whether Xend and Xendomains services are automatically started in level 3-5:

    # chkconfig --list | grep xend
      It should be like this:

    xend               0:off    1:off    2:off    3:on    4:on    5:on    6:off
    xendomains         0:off    1:off    2:off    3:on    4:on    5:on    6:off

    注:XEN的安装到此即可,然后重启,选择【Xen 3.4.3 - Xenified Linux 2.6.32.13】启动项。启动过程会提示某些部件失败,不用理会,登陆Fedora即可。

    1.6 Enjoy the fun now!
      After booting the system, you can try to use xm to check xen info

    # xm info
      Then xm command can be used to start up DomUs.

      [iyunv@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
      [iyunv@czm003fedora12 czm]#

      #xm list

      [iyunv@czm003fedora12 czm]# xm list
      Name                          ID   Mem  VCPUs      State   Time(s)
      Domain-0                      0    1824     4          r-----     80.2
      [iyunv@czm003fedora12 czm]#

      至此,只是在物理PC上安装完XEN虚拟机监控器(可理解为宿主环境),要创建虚拟机还需要在宿主环境上上安装操作系统。详细见
      http://www.iyunv.com/caizm/archive/2012/11/26/2788875.html
      
      
      
      
      
      

  • 运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
    2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
    3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
    4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
    5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
    6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
    7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
    8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

    所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-56630-1-1.html 上篇帖子: 利用 Serial Over Lan(SOL)搭建 XEN 的调试信息输出环境 下篇帖子: xen bootloader
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    扫码加入运维网微信交流群X

    扫码加入运维网微信交流群

    扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

    扫描微信二维码查看详情

    客服E-mail:kefu@iyunv.com 客服QQ:1061981298


    QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


    提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


    本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



    合作伙伴: 青云cloud

    快速回复 返回顶部 返回列表