1.       安装 Xen

Red Hat 公司在 RHEL5 版本的 Linux 操作系统中正式加入了对 Xen 虚拟技术的支持。而在RHEL5 之前的 Linux 系统中安装 Xen 需要进行编译内核的工作,安装过程较为繁琐和复杂。
在 RHEL5 中安装 Xen 有多种方式:
方法一:在 RHEL5 安装时输入包含支持 virtualization 的功能的安装号,系统默认会自动安装Xen 相关软件包。
方法二:在 RHEL5 的安装光盘中已包含全部 Xen 的软件包,所以完全可以手动安装 RHEL5安装光盘中的 Xen 相关软件包,由于需要安装软件包较多,此方法比较繁琐,不建议初学者使用。
方法三:在能连入互联网的前提下,使用 RHEL5 订阅号,利用 yum 工具安装 Xen 内核补丁、Xen 虚拟机、virt-manager 虚拟化管理工具。
方法四:利用 RHEL5 的 DVD 安装光盘构建本地 yum 安装源,利用 yum 工具安装 Xen 内核补丁、Xen 虚拟机、virt-manager 虚拟化管理工具。
这里推荐使用第四种方法进行安装。
现在以一个已安装 GNOME 图形桌面,已安装 Apache,但没有安装任何 Xen 软件的 RHEL5系统为例讲解如何安装 Xen 虚拟化软件。
首先参照 http://jiayf.blog.51cto.com/1659430/342416 构建本地 yum 安装源,过程这里不再赘述。构建完成后执行以下命令安装 Xen 内核补丁、Xen 虚拟机、virt-manager 虚拟化管理工具

[root@xen ~]# yum install kernel-xen xen virt-manager
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Cluster                                                  | 1.3 kB     00:00    
Cluster/primary                                          | 6.5 kB     00:00    
Cluster                                                                   32/32
ClusterStorage                                           | 1.3 kB     00:00    
ClusterStorage/primary                                   | 8.8 kB     00:00    
ClusterStorage                                                            39/39
VT                                                       | 1.3 kB     00:00    
VT/primary                                               | 9.0 kB     00:00    
VT                                                                        36/36
Setting up Install Process
Package kernel-xen-2.6.18-164.el5.i686 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package virt-manager.i386 0:0.6.1-8.el5 set to be updated
--> Processing Dependency: gnome-python2-gnomekeyring >= 2.15.4 for package: virt-manager
--> Processing Dependency: gtk-vnc-python >= 0.3.8 for package: virt-manager
--> Processing Dependency: libvirt-python >= 0.3.3 for package: virt-manager
--> Processing Dependency: python-virtinst >= 0.400.3 for package: virt-manager
---> Package xen.i386 0:3.0.3-94.el5 set to be updated
--> Processing Dependency: xen-libs = 3.0.3-94.el5 for package: xen
--> Processing Dependency: libxenctrl.so.3.0 for package: xen
--> Processing Dependency: libfsp_w_picpath.so.1.0 for package: xen
--> Processing Dependency: libxenguest.so.3.0 for package: xen
--> Processing Dependency: libxenstore.so.3.0 for package: xen
--> Processing Dependency: bridge-utils for package: xen
--> Processing Dependency: libblktap.so.3.0 for package: xen
--> Processing Dependency: libfsp_w_picpath.so.1.0(libfsp_w_picpath.so.1.0) for package: xen
--> Running transaction check
---> Package bridge-utils.i386 0:1.1-2 set to be updated
---> Package gnome-python2-gnomekeyring.i386 0:2.16.0-3.el5 set to be updated
---> Package gtk-vnc-python.i386 0:0.3.8-3.el5 set to be updated
--> Processing Dependency: gtk-vnc = 0.3.8-3.el5 for package: gtk-vnc-python
--> Processing Dependency: libgtk-vnc-1.0.so.0 for package: gtk-vnc-python
---> Package libvirt-python.i386 0:0.6.3-20.el5 set to be updated
--> Processing Dependency: libvirt = 0.6.3-20.el5 for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.6.1) for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.2.3) for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.1.1) for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.1.9) for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.2.1) for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.4.5) for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.2.0) for package: libvirt-python
--> Processing Dependency: libvirt.so.0 for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.1.5) for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.4.1) for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.1.0) for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.3.3) for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.6.3) for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.6.0) for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.4.0) for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.5.0) for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.1.4) for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.3.0) for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.3.2) for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.0.3) for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_0.0.5) for package: libvirt-python
---> Package python-virtinst.noarch 0:0.400.3-5.el5 set to be updated
---> Package xen-libs.i386 0:3.0.3-94.el5 set to be updated
--> Running transaction check
---> Package gtk-vnc.i386 0:0.3.8-3.el5 set to be updated
---> Package libvirt.i386 0:0.6.3-20.el5 set to be updated
--> Processing Dependency: cyrus-sasl-md5 for package: libvirt
--> Processing Dependency: iscsi-initiator-utils for package: libvirt
--> Running transaction check
---> Package cyrus-sasl-md5.i386 0:2.1.22-5.el5 set to be updated
---> Package iscsi-initiator-utils.i386 0:6.2.0.871-0.10.el5 set to be updated
--> Finished Dependency Resolution
 
Dependencies Resolved
 
================================================================================
 Package                       Arch      Version                Repository
                                                                           Size
================================================================================
Installing:
 virt-manager                  i386      0.6.1-8.el5            VT        1.5 M
 xen                           i386      3.0.3-94.el5           VT        1.9 M
Installing for dependencies:
 bridge-utils                  i386      1.1-2                  Server     28 k
 cyrus-sasl-md5                i386      2.1.22-5.el5           Server     45 k
 gnome-python2-gnomekeyring    i386      2.16.0-3.el5           Server     16 k
 gtk-vnc                       i386      0.3.8-3.el5            Server     80 k
 gtk-vnc-python                i386      0.3.8-3.el5            Server     12 k
 iscsi-initiator-utils         i386      6.2.0.871-0.10.el5     Server    773 k
 libvirt                       i386      0.6.3-20.el5           VT        1.9 M
 libvirt-python                i386      0.6.3-20.el5           VT        132 k
 python-virtinst               noarch    0.400.3-5.el5          VT        378 k
 xen-libs                      i386      3.0.3-94.el5           Server    154 k
 
Transaction Summary
================================================================================
Install     12 Package(s)        
Update       0 Package(s)        
Remove       0 Package(s)        
 
Total download size: 6.9 M
Is this ok [y/N]: y
Downloading Packages:
(1/12): iscsi-initiator-utils-6.2.0.871-0.10.el5.i386.rp | 773 kB     00:00    
(2/12): bridge-utils-1.1-2.i386.rpm                      | 28 kB     00:00    
(3/12): gtk-vnc-python-0.3.8-3.el5.i386.rpm              | 12 kB     00:00    
(4/12): xen-libs-3.0.3-94.el5.i386.rpm                   | 154 kB     00:00    
(5/12): cyrus-sasl-md5-2.1.22-5.el5.i386.rpm             | 45 kB     00:00    
(6/12): gtk-vnc-0.3.8-3.el5.i386.rpm                     | 80 kB     00:00    
(7/12): xen-3.0.3-94.el5.i386.rpm                        | 1.9 MB     00:00    
(8/12): gnome-python2-gnomekeyring-2.16.0-3.el5.i386.rpm | 16 kB     00:00    
(9/12): libvirt-python-0.6.3-20.el5.i386.rpm             | 132 kB     00:00    
(10/12): virt-manager-0.6.1-8.el5.i386.rpm               | 1.5 MB     00:00    
(11/12): libvirt-0.6.3-20.el5.i386.rpm                   | 1.9 MB     00:00    
(12/12): python-virtinst-0.400.3-5.el5.noarch.rpm        | 378 kB     00:00    
--------------------------------------------------------------------------------
Total                                           2.3 MB/s | 6.9 MB     00:02    
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
 Installing     : xen-libs                                                1/12
 Installing     : bridge-utils                                            2/12
 Installing     : gtk-vnc                                                 3/12
 Installing     : gtk-vnc-python                                          4/12
 Installing     : cyrus-sasl-md5                                          5/12
 Installing     : iscsi-initiator-utils                                   6/12
 Installing     : libvirt                                                 7/12
 Installing     : libvirt-python                                                               8/12
 Installing     : gnome-python2-gnomekeyring                                                   9/12
 Installing     : python-virtinst                                                             10/12
 Installing     : xen                                                                         11/12
 Installing     : virt-manager                                                                12/12
 
Installed:
 virt-manager.i386 0:0.6.1-8.el5                       xen.i386 0:3.0.3-94.el5                     
 
Dependency Installed:
 bridge-utils.i386 0:1.1-2                        cyrus-sasl-md5.i386 0:2.1.22-5.el5              
 gnome-python2-gnomekeyring.i386 0:2.16.0-3.el5   gtk-vnc.i386 0:0.3.8-3.el5                      
 gtk-vnc-python.i386 0:0.3.8-3.el5                iscsi-initiator-utils.i386 0:6.2.0.871-0.10.el5 
 libvirt.i386 0:0.6.3-20.el5                      libvirt-python.i386 0:0.6.3-20.el5              
 python-virtinst.noarch 0:0.400.3-5.el5           xen-libs.i386 0:3.0.3-94.el5                    
 
Complete!

   重新启动系统

[root@xen ~]# init 6

2.       Xen 服务控制命令
Xen 是由一个叫做 xend 后台守护进程维护,要运行虚拟系统,必须先将其启动。Xen 的配置文件是/etc/xen/xend-config.sxp,内容包括宿主系统的类型,网络的连接结构、宿主操作系统的资源使用设定,以及 vnc 连接的一些内容,一般不需要对其进行设置,如果要添加新的网络设备(比如新的虚拟网卡),则需要在 xend-config.sxp 文件中添加新的设备内容。
启动 xend 的命令

[root@xen ~]# /etc/init.d/xend start
启动 xend:                                                [确定]

   停止 xend 的命令

[root@xen ~]# /etc/init.d/xend stop
停止 xend:                                                [确定]

   重新启动 xend 的命令

[root@xen ~]# /etc/init.d/xend restart
restart xend:                                              [确定]

   将 xend 服务设置成开机自启动

[root@xen ~]# chkconfig --add xend
[root@xen ~]# chkconfig --add xendomains
[root@xen ~]# chkconfig --level 345 xend on
[root@xen ~]# chkconfig --level 345 xendomains on