分类: LINUX
2011-01-24 19:58:11
Xen虚拟化的介绍
Xen虚拟化可以提供完全虚拟化和半虚拟化,一些其它的虚拟化,比如说Vmware VPC这些都是完全虚拟化,而半虚拟化可以修改操作系统的内核,半虚拟化更加的优化,大大的节约了系统的开销。
下面我们就开始安装Xen虚拟机
在安装Xen虚拟机之前,一定要确保虚拟化这个服务是安装了的。而且必须系统运行在支持Xen虚拟化的内核上面。
现在来看下我的计算机
[root@localhost ~]#
[root@localhost ~]# uname -r
2.6.18-164.el5
[root@localhost ~]#
我的机器现在运行在常规的内核上面。
[root@localhost ~]#
[root@localhost ~]# cat /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/sda3
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux Server (2.6.18-164.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-164.el5 ro root=LABEL=/ rhgb quiet crashkernel=128M@16M
initrd /initrd-2.6.18-164.el5.img
[root@localhost ~]#
可以看到,我们的grub.conf文件中也没有关于Xen虚拟化的内核。
现在我们就来安装Xen虚拟化服务。
#yum -y install xen
[root@localhost ~]#
[root@localhost ~]# yum -y install xen
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> 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: xen-hypervisor-abi = 3.1 for package: xen
--> Processing Dependency: libxenctrl.so.3.0 for package: xen
--> Processing Dependency: libSDL-1.2.so.0 for package: xen
--> Processing Dependency: libfsimage.so.1.0 for package: xen
--> Processing Dependency: libxenguest.so.3.0 for package: xen
--> Processing Dependency: python-virtinst 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: libfsimage.so.1.0(libfsimage.so.1.0) for package: xen
--> Running transaction check
---> Package SDL.i386 0:1.2.10-8.el5 set to be updated
---> Package bridge-utils.i386 0:1.1-2 set to be updated
---> Package kernel-xen.i686 0:2.6.18-164.el5 set to be installed
---> Package python-virtinst.noarch 0:0.400.3-5.el5 set to be updated
--> Processing Dependency: libvirt-python >= 0.2.1 for package: python-virtinst
---> Package xen-libs.i386 0:3.0.3-94.el5 set to be updated
--> Running transaction check
---> 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
--> Running transaction check
---> 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:
xen i386 3.0.3-94.el5 VT 1.9 M
Installing for dependencies:
SDL i386 1.2.10-8.el5 Server 233 k
bridge-utils i386 1.1-2 Server 28 k
cyrus-sasl-md5 i386 2.1.22-5.el5 Server 45 k
iscsi-initiator-utils i386 6.2.0.871-0.10.el5 Server 773 k
kernel-xen i686 2.6.18-164.el5 Server 17 M
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 154k
Transaction Summary
================================================================================
Install 10 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 22 M
Downloading Packages:
(1/10): iscsi-initiator-utils-6.2.0.871-0.10.el5.i386.rp | 773 kB 00:00
(2/10): kernel-xen-2.6.18-164.el5.i686.rpm | 17 MB 00:01
(3/10): SDL-1.2.10-8.el5.i386.rpm | 233 kB 00:00
(4/10): bridge-utils-1.1-2.i386.rpm | 28 kB 00:00
(5/10): xen-libs-3.0.3-94.el5.i386.rpm | 154 kB 00:00
(6/10): cyrus-sasl-md5-2.1.22-5.el5.i386.rpm | 45 kB 00:00
(7/10): xen-3.0.3-94.el5.i386.rpm | 1.9 MB 00:00
(8/10): libvirt-python-0.6.3-20.el5.i386.rpm | 132 kB 00:00
(9/10): libvirt-0.6.3-20.el5.i386.rpm | 1.9 MB 00:00
(10/10): python-virtinst-0.400.3-5.el5.noarch.rpm |178kB 00:00
--------------------------------------------------------------------------------
Total 9.3 MB/s | 22 MB 00:02
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : xen-libs 1/10
Installing : bridge-utils 2/10
Installing : SDL 3/10
Installing : cyrus-sasl-md5 4/10
Installing : iscsi-initiator-utils 5/10
Installing : kernel-xen 5/10
Installing : libvirt 7/10
Installing : libvirt-python 8/10
Installing : python-virtinst 9/10
Installing : xen 10/10
Installed:
xen.i386 0:3.0.3-94.el5
Dependency Installed:
SDL.i386 0:1.2.10-8.el5
bridge-utils.i386 0:1.1-2
cyrus-sasl-md5.i386 0:2.1.22-5.el5
iscsi-initiator-utils.i386 0:6.2.0.871-0.10.el5
kernel-xen.i686 0:2.6.18-164.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@localhost ~]#
现在我们的虚拟化服务就安装成功了。
现在我们来看看grub.conf文件中是否有Xen虚拟化的内核。
[root@localhost ~]#
[root@localhost ~]# cat /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/sda3
# initrd /initrd-version.img
#boot=/dev/sda
default=1
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux Server (2.6.18-164.el5xen)
root (hd0,0)
kernel /xen.gz-2.6.18-164.el5
module /vmlinuz-2.6.18-164.el5xen ro root=LABEL=/ rhgb quiet crashkernel=128M@16M
module /initrd-2.6.18-164.el5xen.img
title Red Hat Enterprise Linux Server (2.6.18-164.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-164.el5 ro root=LABEL=/ rhgb quiet crashkernel=128M@16M
initrd /initrd-2.6.18-164.el5.img
[root@localhost ~]#
可以看到,我们的grub.conf文件中就已经有了Xen的内核,现在我们重启计算机,选择Xen的内核启动。
现在我们来查看一下我们是不是运行在Xen的内核上面呢
[root@localhost ~]#
[root@localhost ~]# uname -r
2.6.18-164.el5xen
[root@localhost ~]#
我们的确是运行在Xen的内核上面。
现在我们使用图形界面来管理我们的虚拟机。必须要安装virt-manager这个包
[root@localhost ~]#
[root@localhost ~]# yum -y install virt-manager
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
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
--> Running transaction check
---> 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
--> Running transaction check
---> Package gtk-vnc.i386 0:0.3.8-3.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
Installing for dependencies:
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
Transaction Summary
================================================================================
Install 4 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 1.6 M
Downloading Packages:
(1/4): gtk-vnc-0.3.8-3.el5.i386.rpm | 80 kB 00:00
(2/4): gtk-vnc-python-0.3.8-3.el5.i386.rpm | 12 kB 00:00
(3/4): gnome-python2-gnomekeyring-2.16.0-3.el5.i386.rpm | 16 kB 00:00
(4/4): virt-manager-0.6.1-8.el5.i386.rpm | 1.5 MB 00:00
--------------------------------------------------------------------------------
Total 3.4 MB/s | 1.6 MB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : gtk-vnc 1/4
Installing : gtk-vnc-python 2/4
Installing : gnome-python2-gnomekeyring 3/4
Installing : virt-manager 4/4
Installed:
virt-manager.i386 0:0.6.1-8.el5
Dependency Installed:
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
Complete!
[root@localhost ~]#
安装完成了虚拟机的图形管理工具以后,我们打开这个图形的管理工具。
利用图形界面安装虚拟机的过程如下:
打开虚拟机图形管理界面,
使用virt-manager命令,
点击新建按钮,新建一个虚拟机,
这个是开始新建的说明,点击下一步,
给虚拟机启一个名字,点击下一步,
选择半虚拟化,点击下一步,
选择要安装系统的类型,这里我们选择RHEL5,然后点击下一步,
指定安装介质的路径,并且还支持kickstart无人值守的安装脚本。点击下一步,
指定虚拟机存放在那里,/dev/vg01/lv01代表我把虚拟机存放在一个逻辑卷上面。点击下一步,
选择网卡的模式,选择桥接模式,点击下一步,
指定虚拟内存的大小和CPU的数量,点击下一步,
这里就是刚才定义的虚拟机的配置,确定没有问题后,点击完成。
在正在创建虚拟机,稍等,
下面系统就会根据刚才定义的kickstart脚本进行无人值守的安装了。
刚才是通过图形界面来安装xen虚拟机,同样也可以在字符界面下面来安装我们的xen虚拟机。
使用virt-install命令来进行字符界面安装虚拟机,
#virt-install
当我们安装完虚拟机以后,系统会自动的创建一个关于虚拟机的配置文件,
在/etc/xen下面就有关于虚拟机的配置文件,
[root@server1 ~]#
[root@server1 ~]# cd /etc/xen/
[root@server1 xen]# ls
auto virt1 xend-pci-quirks.sxp xmexample.hvm
qemu-ifup xend-config.sxp xmexample1 xmexample.vti
scripts xend-pci-permissive.sxp xmexample2
[root@server1 xen]#
下面我打开virt1这个配置文件看看,
Vim /etc/xen/virt1
name = "virt1"
uuid = "9e72edfa-939c-aa2b-f289-8d3ba8f49bb1"
maxmem = 512
memory = 512
vcpus = 1
bootloader = "/usr/bin/pygrub"
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
vfb = [ "type=vnc,vncunused=1,keymap=en-us" ]
disk = [ "phy:/dev/vg01/lv01,xvda,w" ]
vif = [ "mac=00:16:36:76:ad:ef,bridge=xenbr0,script=vif-bridge" ]
这里面就有虚拟机的名字,uuid,最大内存,虚拟内存,CPU的数量,引导程序,关机,重启,磁盘,虚拟的mac地址,网卡等等。
当我们安装完成虚拟机以后,通过virt-manager命令可以看到,
#virt-manager
这里面就可以看到Domain-0就是我们的物理机,virt1就是刚才创建的虚拟机,在这个节目里可以启动,删除,停止等等对虚拟机做一些操作。
如何去管理虚拟机呢?
可以使用XM工具来管理虚拟机,
#xm shutdown virt1
关闭虚拟机(正常关闭虚拟机)
#xm destroy virt1
强制关闭虚拟机(非正常关闭虚拟机,相当于拨出电源)
#xm create –c virt1
-c 代表查看启动过程,可以看到grub界面
启动虚拟机
#xm pauser virt1
暂停虚拟机
#xm unpauser virt1
取消暂停虚拟机
#xm save virt1 /var/ftp/pub/virt1.bak
将虚拟机的系统设置成休眠状态
#xm restore /var/ftp/pub/virt.bak
将处于休眠状态的虚拟机修复回来
#vm reboot virt1
重启虚拟机
#vm list
查看运行在后台的虚拟机
#vm console virt1
通过控制台的方式连接到虚拟机
退出虚拟机利用Ctrl+]方式退出虚拟机
关于Linux下面Xen虚拟化得讨论就到这里了。