温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Paravirtualization在Xen CentOS 5.6上

发布时间:2020-05-15 08:01:39 来源:网络 阅读:566 作者:liugaoyang119 栏目:web开发

         这边教程提供的是循序渐进告诉你如何在何安装在说明XenXen(version 3.0.3)  在一个CentOS 5.6(x86_64)系统说明。

        Xen让你创建一个开源系统 (比如开源系统Linux 和FreeBSD),所以就叫做“虚拟机”或者宿主系统,使用Xen可以分成不同的虚拟机,而且虚拟机是彼此互相独立(例如一个邮件服务器;一个高流量web 网站;一个客户的虚拟网站;一个DNS服务器),但是使用的是相同的硬件,这样可以节省钱,更重要的是这也很安全,如果你的dns服务器被黑了,但他不会影响别的虚拟服务器的使用。正好你把虚拟机从  Xen移动到下一位置。

  我将用CentOS 5.6(x86_64)做两个主机操作系统,一个主一个从。

  这是基本的使用指导,他不覆盖所有环境,如果你想在学习请从其他页面找。 

  这边指导没有任何保证,我意思说这不是唯一的编辑内核的方法,有许多的其他方法都可以达到这个目标,但我不敢保证这个方法对你也适用。

  1第一步

 这个说明是指导我们怎样建立虚拟映象和虚拟逻辑管理等相关技术。

 确认SELinux是开启的:

vi /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted

如果已经修改了 /etc/sysconfig/selinux,请重启系统:

reboot

2 安装Xen

安装Xen,我们现在就运行:

yum install kernel-xen xen

这个安装是Xen和一个Xen内核已经在系统上的。

现在我们能进入系统kernelxen,检查你的GRUB配置,打开/boot/grub/menu.lst:

vi /boot/grub/menu.lst

第一个应该是你Xen刚刚安装的内核:

[...]
title CentOS (2.6.18-238.9.1.el5xen)
        root (hd0,0)
        kernel /xen.gz-2.6.18-238.9.1.el5
        module /vmlinuz-2.6.18-238.9.1.el5xen ro root=/dev/VolGroup00/LogVol00
        module /initrd-2.6.18-238.9.1.el5xen.img
[...]

改变值为default to 0,

[...]
default=0
[...]

完整的看起来应该是这样:

# 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/VolGroup00/LogVol00
#          initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashp_w_picpath=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-238.9.1.el5xen)
        root (hd0,0)
        kernel /xen.gz-2.6.18-238.9.1.el5
        module /vmlinuz-2.6.18-238.9.1.el5xen ro root=/dev/VolGroup00/LogVol00
        module /initrd-2.6.18-238.9.1.el5xen.img
title CentOS (2.6.18-238.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-238.el5 ro root=/dev/VolGroup00/LogVol00
        initrd /initrd-2.6.18-238.el5.img

在后我们重启系统:

reboot

这个系统应该是自动启动新的内核,我们来检查它的运行:

 

 

uname -r

[root@server1 ~]# uname -r
2.6.18-238.9.1.el5xen
[root@server1 ~]#

现在我们应该适用新的内核,

我们现在运行它:

xm list

去检查如果Xen已经启动,它因该列出Domain-0 (dom0):

[root@server1 ~]# xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0     3343     2 r-----     18.1
[root@server1 ~]#

3 创建一个映象虚拟机:

  我想存入的映象在我的映象虚拟机 /vm目录下,当然你可以适用其他目录空间,只要它有足够的空间,如果你使用了令一个目录,请你使用你的目录.

   如果你想保存你的虚拟机目录,但这个目录又没有给虚拟机创建好空间,你可以这样创建:

mkdir /vm

CentOS 有一个不错的工具virt-install ,用它可以直接创建Xen虚拟机,现在我们就运行它:

virt-install --prompt

 在这之前我创建了一个虚拟机,我想告诉我第一个虚拟机是vm01, 521M的内存和4G的硬盘,我想存入/vm/vm01.img:

Would you like a fully virtualized guest (yes or no)? This will allow you to run unmodified operating systems. <-- no
 What is the name of your virtual machine? <-- vm01
 How much RAM should be allocated (in megabytes)? <-- 512
 What would you like to use as the disk (file path)? <-- /vm/vm01.img
 How large would you like the disk (/vm/vm01.img) to be (in gigabytes)? <-- 4
 What is the install URL? <-- http://wftp.tu-chemnitz.de/pub/linux/centos/5.6/os/x86_64

第一个关于虚拟客户端的问题必须回答NO,否则你将不会看到CentOS 5.6在我们的虚拟机的安装.

     As install URL你 因该指定CentOS 5.6在虚拟机上的安装路径和文件,你能找到的映像路径在:http://www.centos.org/modules/tinycontent/index.php?id=13

安装完后,我们暂停在vm01 console,要离开请按CTRL+] ,如果你在控制台,如果你正在使用PuTTY.按CTRL + 5,你将回到控制台。

virt-install要创建的文件在vm01配置文件在 /etc/xen/vm01 ,其实就像这样:

cat /etc/xen/vm01

name = "vm01"
uuid = "809dd76e-f48e-8a3d-343b-1dd8b1d585ea"
maxmem = 512
memory = 512
vcpus = 1
bootloader = "/usr/bin/pygrub"
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
disk = [ "tap:aio:/vm/vm01.img,xvda,w" ]
vif = [ "mac=00:16:36:33:80:b7,bridge=xenbr0,script=vif-bridge" ]

继续:

xm console vm01

登陆虚拟机使用SSH 进行连接:

去找到一个虚拟机列表:

xm list

输出信息应该是这样:

[root@server1 ~]# xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0     2702     2 r-----     83.4
vm01                                       3      512     1 -b----     18.2
[root@server1 ~]#

去关闭vm01,这样做:

xm shutdown vm01

开启vm01,这样做:

xm create /etc/xen/vm01

如果你想下次可以自动启动:

ln -s /etc/xen/vm01 /etc/xen/auto

这些是Xen命令:

xm create -c /path/to/config - Start a virtual machine.
xm shutdown <name> - Stop a virtual machine.
xm destroy <name> - Stop a virtual machine immediately without shutting it down. It's as if you switch off the power button.
xm list - List all running systems.
xm console <name> - Log in on a virtual machine.
xm help - List of all commands.

 4.创建虚拟机逻辑管理:

本节主要告诉怎么用逻辑虚拟机代替映像虚拟机。

在本例中我使用CentOS 5.6 LVM 主机群/dev/VolGroup00 和465GB 磁盘, /dev/VolGroup00 包含两个磁盘,/dev/VolGroup00/LogVol00 和 /dev/VolGroup00/LogVol01 消耗104GB空间,其余不能拿来分配,用来创建逻辑卷为虚拟机。

vgdisplay

vgdisplay

[root@server1 ~]# vgdisplay
  /dev/hda: open failed: No medium found
  --- Volume group ---
  VG Name               VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               465.66 GB
  PE Size               32.00 MB
  Total PE              14901
  Alloc PE / Size       3303 / 103.22 GB
  Free  PE / Size       11598 / 362.44 GB
  VG UUID               veUbuN-BNGq-BP3S-H3mP-bWOF-tbAX-GeIhy6
 

lvdisplay

[root@server1 ~]# lvdisplay
  /dev/hda: open failed: No medium found
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                5tEz3i-YlR7-rdQB-VCPK-xHlB-GsWU-4Rijqk
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                97.66 GB
  Current LE             3125
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                3qp5ia-uBJl-eeNZ-JOkH-4E6o-ZAbf-HvdNms
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                5.56 GB
  Current LE             178
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

[root@server1 ~]#

我想创建一个不同的虚拟机vm02 ,使用逻辑分区 /dev/VolGroup00/vm02,所以我创建了符合逻辑的dev/VolGroup00/vm02 :

lvcreate -L10G -n vm02 VolGroup00

然后我们运行:

virt-install --prompt

again:

Would you like a fully virtualized guest (yes or no)? This will allow you to run unmodified operating systems. <-- no
 What is the name of your virtual machine? <-- vm02
 How much RAM should be allocated (in megabytes)? <-- 512
 What would you like to use as the disk (file path)? <-- /dev/VolGroup00/vm02
 What is the install URL? <-- http://wftp.tu-chemnitz.de/pub/linux/centos/5.6/os/x86_64

做为磁盘文件路径,我们将指定新的 /dev/VolGroup00/vm02.请不要在调磁盘空间,因为我们磁盘空间是合乎逻辑的10GB;

5 链接:

  • Xen: http://www.xen.org/
  • CentOS: http://www.centos.org/



 

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI