linux学习记录
分类:
2010-08-25 15:27:18
关于linux下面中Xen虚拟化的讨论,
Xen虚拟化的介绍
Xen虚拟化可以提供完全虚拟化和半虚拟化,一些其它的虚拟化,比如说Vmware VPC这些都是完全虚拟化,而半虚拟化可以修改操作系统的内核,半虚拟化更加的优化,大大的节约了系统的开销。
下面我们就开始安装Xen虚拟机
在安装Xen虚拟机之前,一定要确保虚拟化这个服务是安装了的。而且必须系统运行在支持Xen虚拟化的内核上面。
现在来看下我的计算机
[root@localhost ~]#
[root@localhost ~]# uname -r
[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 (
root (hd0,0)
kernel /vmlinuz-
initrd /initrd-
[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:
--> Processing Dependency: xen-libs =
--> 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:
---> Package bridge-utils.i386 0:1.1-2 set to be updated
---> Package kernel-xen.i686 0:
---> Package python-virtinst.noarch 0:0.400.3-5.el5 set to be updated
--> Processing Dependency: libvirt-python >=
---> Package xen-libs.i386 0:
--> Running transaction check
---> Package libvirt-python.i386 0:
--> Processing Dependency: libvirt =
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0 for package: libvirt-python
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Processing Dependency: libvirt.so.0(LIBVIRT_
--> Running transaction check
---> Package libvirt.i386 0:
--> 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:
---> Package iscsi-initiator-utils.i386 0:
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
xen i386
Installing for dependencies:
SDL i386
bridge-utils i386 1.1-2 Server 28 k
cyrus-sasl-md5 i386
iscsi-initiator-utils i386
kernel-xen i686
libvirt i386 0.6.3-20.el5 VT
libvirt-python i386
python-virtinst noarch 0.400.3-5.el5 VT 378 k
xen-libs i386
Transaction Summary
================================================================================
Install 10 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size:
Downloading Packages:
(1/10): iscsi-initiator-utils-
(2/10): kernel-xen-
(3/10): SDL-
(4/10): bridge-utils-1.1-2.i386.rpm | 28 kB 00:00
(5/10): xen-libs-
(6/10): cyrus-sasl-md5-
(7/10): xen-
(8/10): libvirt-python-
(9/10): libvirt-
(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:
Dependency Installed:
SDL.i386 0:
bridge-utils.i386 0:1.1-2
cyrus-sasl-md5.i386 0:
iscsi-initiator-utils.i386 0:
kernel-xen.i686 0:
libvirt.i386 0:
libvirt-python.i386 0:
python-virtinst.noarch 0:0.400.3-5.el5
xen-libs.i386 0:
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 (
root (hd0,0)
kernel /xen.gz-
module /vmlinuz-
module /initrd-
title Red Hat Enterprise Linux Server (
root (hd0,0)
kernel /vmlinuz-
initrd /initrd-
[root@localhost ~]#
可以看到,我们的grub.conf文件中就已经有了Xen的内核,现在我们重启计算机,选择Xen的内核启动。
现在我们来查看一下我们是不是运行在Xen的内核上面呢
[root@localhost ~]#
[root@localhost ~]# uname -r
[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:
--> Processing Dependency: gnome-python2-gnomekeyring >=
--> Processing Dependency: gtk-vnc-python >=
--> Running transaction check
---> Package gnome-python2-gnomekeyring.i386 0:
---> Package gtk-vnc-python.i386 0:
--> Processing Dependency: gtk-vnc =
--> Processing Dependency: libgtk-vnc-1.0.so.0 for package: gtk-vnc-python
--> Running transaction check
---> Package gtk-vnc.i386 0:
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
virt-manager i386
Installing for dependencies:
gnome-python2-gnomekeyring i386
gtk-vnc i386
gtk-vnc-python i386
Transaction Summary
================================================================================
Install 4 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size:
Downloading Packages:
(1/4): gtk-vnc-
(2/4): gtk-vnc-python-
(3/4): gnome-python2-gnomekeyring-
(4/4): virt-manager-
--------------------------------------------------------------------------------
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:
Dependency Installed:
gnome-python2-gnomekeyring.i386 0:
gtk-vnc-python.i386 0:
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虚拟化得讨论就到这里了。