天天看點

redhat5.4虛拟化技術xen安裝

redhat5.4安裝xen虛拟化軟體。

1、安裝方式及說明:

本文檔采用rpm包安裝方式。需要的包有

在CD光牒Server裡有以下兩個包

kernel-xen-2.6.18-164.el5.x86_64.rpm

xen-libs-3.0.3-94.el5.x86_64.rpm libvirt-0.6.3-20.el5.x86_64.rpm

在CD光牒VT目錄有以下10個包

libvirt-devel-0.6.3-20.el5.x86_64.rpm

libvirt-python-0.6.3-20.el5.x86_64.rpm

python-virtinst-0.400.3-5.el5.noarch.rpm

virt-manager-0.6.1-8.el5.x86_64.rpm

Virtualization-en-US-5.2-11.noarch.rpm

Virtualization-zh-CN-5.2-11.noarch.rpm

xen-3.0.3-94.el5.x86_64.rpm

xen-devel-3.0.3-94.el5.x86_64.rpm

gnome-python2-gnomekeyring-2.16.0-3.el5.x86_64.rpm

gnome-applet-vm-0.1.2-1.el5.x86_64.rpm

建意制做一個yum源直接用yum來安裝這些包(因為用yum不需要考慮這些包的依賴關系)。接下來我會用yum來安裝這些包

首先安裝kernel的rpm包

[root@localhost ~]#rpm -ivh kernel-xen-2.6.18-164.el5.x86_64.rpm

[root@localhost ~]#rpm -ivh xen-libs-3.0.3-94.el5.x86_64.rpm 

接下來修改引導核心的配置檔案/etc/grub.conf讓系統引導xen這個核心 

安裝好kernel-xen後在/etc/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/VolGroup00/LogVol00

# initrd /initrd-version.img

#boot=/dev/hda

default=1

timeout=5

splashimage=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

title Red Hat Enterprise Linux Server (2.6.18-8.el5xen)

root (hd0,0)

kernel /xen.gz-2.6.18-8.el5

module /vmlinuz-2.6.18-8.el5xen ro root=/dev/VolGroup00/LogVol00 rhgb quiet

module /initrd-2.6.18-8.el5xen.img 

title Red Hat Enterprise Linux Server (2.6.18-8.el5)

kernel /vmlinuz-2.6.18-8.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet

initrd /initrd-2.6.18-8.el5.img

找到"default=1"改成"default=0"

重新開機計算機

[root@localhost ~]#reboot

重新開機系統完成後,安裝管理虛拟機包。我采用yum安裝(yum源是redhat5.4)

[root@localhost ~]#yum -y install libvirt*

安裝xen服務

[root@localhost ~]#rpm -ivh xen-3.0.3-94.el5.x86_64.rpm

[root@localhost ~]#rpm -ivh xen-devel-3.0.3-94.el5.x86_64.rpm

把xen服務加入到自啟動腳本

[root@localhost ~]#chkconfig --add xend

[root@localhost ~]#chkconfig --level 345 xend on

啟動xen服務

[root@localhost ~]#/etc/init.d/xend start

Starting xend: [ OK ]

2、配置啟動一個虛拟機:

   2.1、制作安裝源

Xen中安裝domain的方式比較特别,必須将安裝檔案放在NFS檔案服務或HTTP檔案伺服器上來安裝,下面我來配置基于是http服務的一個安裝源。

安裝apache

[root@localhost ~]# yum -y install httpd

啟動

[root@localhost ~]# /etc/init.d/httpd start

複制CD光牒檔案到/var/www/html目錄中,首先挂載CD光牒(redhat5.4dvdCD光牒)

[root@localhost ~]# mkdir /mnt/cdrom

[root@localhost ~]# mount -t iso9660 /dev/cdrom /mnt/cdrom

[root@localhost ~]# cd /mnt/cdrom

[root@localhost ~]# /bin/cp -Rf * /var/www/html/

這樣http安裝源就做好了。接下來就可以建立一個虛拟機了。

   2.2、用virt-install指令建立虛拟機

[root@localhost ~]# mkdir /data 存放虛拟機磁盤檔案的目錄

[root@localhost ~]# virt-install -n test -r 128 --vcpus=1 -f /data/test -s 8 -p -l http://127.0.0.1 --nographics

各參數解釋如下:

-n test ,名稱

-r 128 ,配置設定128MB記憶體給domain

--vcpu=1 ,配置設定一個虛拟CPU

-f /data/test ,指定虛拟磁盤檔案為/data/test

-s 8 ,磁盤size是8GB

-p ,使用para半虛拟化模式(因為本測試機CPU不支援VT技術)

-l http://192.168.7.101 ,指定安裝鏡像的位置

--nographics ,不啟動圖形模式,隻啟動字元模式

指令運作會進入一個安裝系統的界面,一步一步裝完就可以了。

至此一個虛拟機就裝好了。

2、啟動一個虛拟機

    在指令行下執行 xm create ,即可啟動domain。例如執行如下指令,即可将剛才安裝好系統的domain引導起來。

[root@localhost ~]# xm create test

關于xm指令讀者可以參數其他的技術文檔。

3、讓domain随伺服器啟動而自動啟動 

    在伺服器重新開機的時候,所有domain會自動的停止。當伺服器完成重新開機後,domain還會繼續保持關閉的狀态,而不是自動啟動。如果需要讓domain自動啟動,需要做如下操作,這裡以test為例:

[root@localhost ~]# ln -s /etc/xen/test /etc/xen/auto/test

這一步操作的作用是,将domain的配置檔案用link連結到auto目錄下。凡是在auto目錄下的domain,都會随着伺服器啟動而自動啟動。

完畢後還要将xendomains設定為随機啟動的背景服務。

[root@localhost ~]# chkconfig --add xendomains

現在重新開機伺服器,就會發現名為test的domain也随着伺服器啟動而啟動了。

    本文轉自yuangang_love 51CTO部落格,原文連結:http://blog.51cto.com/linux008/544223,如需轉載請自行聯系原作者

繼續閱讀