Cnfan.net中国网络
IT网络技术专家
虚拟技术
 最新专题: 专题 | 分类 | 投稿 | 搜索
 虚拟技术首页 | 虚拟机新闻 | 虚拟机技术 | vmware | Virtual PC | Virtuozzo | xen

Xen v2.0 for x86安装及运行手册

简介:安装及运行手册 Xen v2.0 for x86

关键字: Xen

安装及运行手册

Xen v2.0 for x86

by Jianghao

2006-11-23  v1.0


目录

Part 1. 3

1 安装... 3

1.1 安装的先决条件... 3

1.2 下载... 3

1.3 编译安装... 4

1.3.1 下载内核... 4

2 配置... 8

2.1 GRUB配置... 8

2.2 TLS... 9

part2. 10

1 domain 配置文件... 10

1.1 示例配置文件... 10

1.2 ttylinux. 12

2 domainU简单操控... 14

2.1 Xen守护进程... 14

2.2 创建ttylinux domainU.. 14

2.3 查看domain信息... 14

2.4 domain的save(保存)和restore(恢复)... 15

2.5 新连接到ttyLinux终端... 16

3 其他信息... 16

 


Part 1

1 安装

   Xen的组件由三个主要部分组成:Xen自身,修改版的Linux2.4Linux2.6NetBSD操作系统内核,用户空间管理工具。我们在这里讨论使用的是Linux2.6内核,Xen下载源码后自己编译,完成安装。

1.1 安装的先决条件

·使用GRUB bootloaderP6级或更新的CPU,运行Linux的电脑。

以下为使用xend必备:

+ iproute2

  + Linux bridge-utils

  + Twisted v1.3

  以下为下载Xen源码,自行编译必备:

  * build tools gcc v3.2或者v3.3.xbinutils,GNU make

  * libcurl开发版

  * zlib开发版

  * Python v2.2或更高开发版

1.2 下载

   www.xensource.com/download页面可以下载最新的Xen版本,目前最新的是v3.0。我们使用原来的v2.0.7版。

进入到v2.0的下载页面。下载v2.0.7的源码包。

1.3 编译安装

我们在RedHat 9.0内进行编译,上面提到的安装条件,除了内核,XenRedHat都已提供,如果没有的我们可以自行下载安装。内核我们采用的是Linux2.6.11Xen在编译时如果找不到内核,会尝试从网上直接下载,为了节约时间,我们可以把Linux2.6.11的内核预先下载下来,放到Xen的目录下。

1.3.1 下载内核

www.kernel.org/pub/linux/kernel/v2.6/ 处下载文件 linux-2.6.11.tar.bz2

1.3.2 下载并安装前置条件

1.3.2.1 iproute2

该包很小,可以在Xen内有命令可以直接在网上下载安装。详见后面的Xen安装。

1.3.2.2 bridge-utils

可预先到 http://bridge.sourceforge.net 下载 bridge-utils-1.2.tar.gz 源码包安装。下载后解压到/root下,进入解压后目录,进行自动配置,执行如下命令序列:

#autoconf

#./configure

编译并安装,执行如下命令序列:

#make

#make install

即可完成bridge-utils的安装。

1.3.2.3 Twisted

Xen内有到网上下载并安装的命令,但地址已经失效,所以我们自行下载安装。

下载地址为 www.twistedmatrix.com ,目前最新版已经到v2.4。我们下载较早的版本twisted-1.3.0.tar.bz2

将压缩文件解压到/root,进入该目录,执行如下命令序列:

#python setup.py install

即可完成Twisted的安装。

1.3.3 解压缩Xen源码

将先前下载的Xen源码文件xen-2.0.7-src.tgz解压,本例是解压到/root。得到/root/xen-2.0目录。该目录下包含了Xen安装的必要文件,如内核补丁等。

将下载的内核linux-2.6.11.tar.bz2复制到/root/xen-2.0下。这样我们就完成了编译前的准备工作,接下来就可以开始编译了。

1.3.4 Xen

1.3.4.1 安装iproute2

     开启终端,进入到/root/xen-2.0,在命令提示符下输入:

      #make install-iptables

     make程序自动连接到网络下载安装包,完成安装。

1.3.4.2 编译Xen

#make world

该命令将会编译Xen,管理控制工具(如xend),Linux 2.6.11内核并打补丁,同时生成两个Linxu内核domain0domainU

编译完成后的收到了一个警告信息,可能是编译文档的条件未得到满足(缺少latex包)。我们是在vmware内编译的,文档资料可以在Windows下察看,而且不影响Xen的使用,所以不必管它。

1.3.4.3 安装Xen

     执行如下指令序列:

#sh install.sh

将完成Xen的安装。我们可以查看在/boot目录下生成的domain镜像文件。到此,安装过程完成。

2 配置

2.1 GRUB配置

修改/boot/grub/下的grub.conf文件。添加条目如下:

title Xen 2.0 / Xenlinux 2.6

    kernel /xen-2.0.gz dom0_mem=131072

    module /vmlinuz-2.6-xen0 ro root=LABEL=/ console=tty0

        module /initrd-2.4.20-8.img

重起系统后,就可以看到我们的Xen/Xenlinux启动选项了。

2.2 TLS

   由于Thread Local StorageTLS)库内存访问的模式与Xen不符,使用TLS将使Xen的性能受到很大的影响。所以可以将/lib/tls目录重命名为/lib/tls.disabled来提高Xen的性能。


part2

1 domain 配置文件

   配置文件是 Xen启动客户OS必须的文件,它完成了硬件的配置。

1.1 示例配置文件

   Xen提供了两个示例配置文件,分别是/etc/xen/xmexample1/etc/xen/xmexample2

   xmexample1给出了单个虚拟机的配置模板,xmexample2给出了同时配置多个虚拟机的配置模板。

   xmexample1文件内容如下:

#  -*- mode: python; -*-

#============================================================================

# Python configuration setup for 'xm create'.

# This script sets the parameters used when a domain is created using 'xm create'.

# You use a separate script for each domain you want to create, or

# you can set the parameters for the domain on the xm command line.

#============================================================================

 

#----------------------------------------------------------------------------

# Kernel image file.

kernel = "/boot/vmlinuz-2.6.10-xenU"

 

# Optional ramdisk.

#ramdisk = "/boot/initrd.gz"

 

# The domain build function. Default is 'linux'.

#builder='linux'

 

# Initial memory allocation (in megabytes) for the new domain.

memory = 64

 

# A name for your domain. All domains must have different names.

name = "ExampleDomain"

 

# Which CPU to start domain on?

#cpu = -1   # leave to Xen to pick

 

#----------------------------------------------------------------------------

# Define network interfaces.

 

# Number of network interfaces. Default is 1.

#nics=1

 

# Optionally define mac and/or bridge for the network interfaces.

# Random MACs are assigned if not given.

#vif = [ 'mac=aa:00:00:00:00:11, bridge=xen-br0' ]

 

#----------------------------------------------------------------------------

# Define the disk devices you want the domain to have access to, and

# what you want them accessible as.

# Each disk entry is of the form phy:UNAME,DEV,MODE

# where UNAME is the device, DEV is the device name the domain will see,

# and MODE is r for read-only, w for read-write.

 

disk = [ 'phy:hda1,hda1,w' ]

 

#----------------------------------------------------------------------------

# Set the kernel command line for the new domain.

# You only need to define the IP parameters and hostname if the domain's

# IP config doesn't, e.g. in ifcfg-eth0 or via DHCP.

# You can use 'extra' to set the runlevel and custom environment

# variables used by custom rc scripts (e.g. VMID=, usr= ).

 

# Set if you want dhcp to allocate the IP address.

#dhcp="dhcp"

# Set netmask.

#netmask=

# Set default gateway.

#gateway=

# Set the hostname.

#hostname= "vm%d" % vmid

 

# Set root device.

root = "/dev/hda1 ro"

 

# Root device for nfs.

#root = "/dev/nfs"

# The nfs server.

#nfs_server = '169.254.1.0' 

# Root directory on the nfs server.

#nfs_root   = '/full/path/to/root/directory'

 

# Sets runlevel 4.

extra = "4"

 

#----------------------------------------------------------------------------

# Set according to whether you want the domain restarted when it exits.

# The default is 'onreboot', which restarts the domain when it shuts down

# with exit code reboot.

# Other values are 'always', and 'never'.

 

#restart = 'onreboot'

 

#============================================================================

 

我们在这里演示一个domain的配置运行,所以xmexample2文件内容未列出,感兴趣可以到目录下查看。

1.2 ttylinux

   我们以ttylinux为例。ttylinux是一个很小的linux发行版,需要很少的资源。我们使用它来熟悉这个添加domain的过程。

1.2.1 下载ttylinux

   sourceforge.net/projects/xen的文件下载区可以下载ttylinux的压缩包。

1.2.2 建立工作目录

我们在/root下建立ttylinux的目录,并将下载的压缩包释放到目录内。这样我们就得到了ttylinux的根文件系统(rootfs)。

1.2.3 编写ttylinux配置文件

我们可以在示例文件的基础上改写配置文件。

建立名为ttylinuxconf的文件,填入以下内容:

kernel = “/boot/vmlinuz-2.6-xenU”

memory = 32

name = “ttyLinux

nics = 1

disk =[ ‘file:/root/ttylinux/ttylinux-xen,sda1,w’ ]

root = “/dev/sda1 ro”

2 domainU简单操控

2.1 Xen守护进程

   Xend Xen管理的必要进程,它为我们提供了查看,管理多个虚拟机的必要手段。所以我们在启动XenLinux后,就可以启动该守护进程。使用如下命令:

#xend start

2.2 创建ttylinux domainU

   在完成配置文件和准备好ttylinux根文件系统后,我们就可以创建ttylinux了。

   在终端窗口内,路径/root/ttylinux下使用以下命令:

#xm create ttylinuxconf –c

我们将看到ttylinux启动输出的不同信息。

当提示符再次出现时,我们可以以root/root或者guest/guest登录了。

2.3 查看domain信息

   domain0内新建终端,输入:

#xm list

我们就获得了现存domain的信息,他们分别是:

name 虚拟机

Id    虚拟机运行所在的domid

memory 分配的内存(MB

CPU  domain运行所在的CPU

state  包涵5个域

     r    running

     b    blocked

     p    paused

     s    shutdown

     c    crashed

cputime   domain运行的CPU时间(秒)

console    连接到该域的TCP端口

如上图所示,上面的窗口为domainU,下面的窗口为domain0

2.4 domainsave(保存)和restore(恢复)

   保存domain

   #xm save ttyLinux ttylinux.xen

   恢复domain

   #xm restore ttylinux.xen

   如上图,我们可以看到在save ttyLinux后,我们只能看到一个活动的domain0。而在restore时,ttyLinux的信息正在被调入。通过xm list 我们可以再次看到ttyLinux的出现。

2.5 重新连接到ttyLinux终端

   由于ttyLinux被保存,所以之前与之建立的终端连接已经丢失。

如上图,之前建立的终端窗口使用的TCP端口由9608变为了9609。我们需要重新建立终端连接,使用如下命令都可以:

#xencons localhost 9609

#xm console ttyLinux

#xm console 9

3 其他信息

  关于进一步的使用及Xen提供的命令参数,可以参考用户手册。


  <欢迎投稿>  <论坛讨论>
 »相关文章  »论坛新贴
精彩文章 活动资讯 今日头条