CentOS6.2系统上部署Xen4.1.2虚拟机

一,简介

操作系统:CentOS6.2版本,内核2.6.32-220.el6.x86_64

[root@bogon ~]#uname -r

2.6.32-220.el6.x86_64

主要参考VirtualizationWith Xen On CentOS 6.2 (x86_64) (Paravirtualization & HardwareVirtualization) ,来源http://www.howtoforge.com/virtualization-with-xen-on-centos-6.2-x86_64-paravirtualization-and-hardware-virtualization

现在回想起来,第一次按照这个步骤安装下去后,xen已经安装好,可以正常启动和使用了。但是CentOS自带的虚拟机管理器VirtualMachine Manager 无法连接到xendom0上。老是提示这个错误:

Unableto open a connection to the libvirt management daemon.

LibvirtURI is: xen+ssh://[email protected]/

Verifythat:

- The'libvirtd' daemon has been started

首先检查了libvirtd服务,是正常启动的。

[root@bogon ~]#service libvirtd status

libvirtd (pid 2056)正在运行...

CentOS6.2自带的libvirtXen4.1.2是不兼容的。如果按照VirtualizationWith Xen On CentOS 6.2 (x86_64)指导的安装是没有问题的。已经重建libvirt了。但是不能对系统做yumupdate,这样libvirt又更新到最新的版本,对xen4.1.2又不支持了。


二,安装和部署

1)安装操作系统CentOS6.2

安装前先启动了BIOS对虚拟化技术的支持,所以需要查看CPU是否支持虚拟化,Intel-VT或者AMD-V,否则安装xen后发现只能支持半虚拟化(paravirtualization),支持不了全虚拟化(fullvirtualization)。CentOS6.2安装的时候,我已经选择了大部分软件包,因为是测试机,把能安装的看起来有用的软件都选择上了。

2)安装之前把selinux关闭

关闭有几个办法,一个办法就是采用命令setup进行配置:

[root@bogon ~]#setup

做设置界面中选择防火墙配置,不起用防火墙功能。当然,这是不安全到做法,如果启用selinux需要对安全规则进行部署,为了方便,先直接关闭了。

另外一个办法就是直接修改配置文件,SELINUX=disabled

[root@bogon ~]#vim /etc/sysconfig/selinux


# This filecontrols the state of SELinux on the system.

# SELINUX= cantake one of these three values:

# enforcing- SELinux security policy is enforced.

# permissive - SELinux prints warnings instead of enforcing.

# disabled- No SELinux policy is loaded.

SELINUX=disabled

# SELINUXTYPE=can take one of these two values:

# targeted- Targeted processes are protected,

# mls -Multi Level Security protection.

SELINUXTYPE=targeted

修改完后,重启系统。

3)创建网桥。因为系统安装时已有虚拟网桥,所以这一步就省去了。

[root@bogon ~]#ifconfig

eth0 Linkencap:Ethernet HWaddr 54:04:A6:99:95:2F

inetaddr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0

inet6addr: fe80::5604:a6ff:fe99:952f/64 Scope:Link

UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RXpackets:6914 errors:0 dropped:0 overruns:0 frame:0

TXpackets:7618 errors:0 dropped:0 overruns:0 carrier:0

collisions:0txqueuelen:1000

RXbytes:4342862 (4.1 MiB) TX bytes:1371168 (1.3 MiB)

Interrupt:34Base address:0x2000


lo Linkencap:Local Loopback

inetaddr:127.0.0.1 Mask:255.0.0.0

inet6addr: ::1/128 Scope:Host

UPLOOPBACK RUNNING MTU:16436 Metric:1

RXpackets:132 errors:0 dropped:0 overruns:0 frame:0

TXpackets:132 errors:0 dropped:0 overruns:0 carrier:0

collisions:0txqueuelen:0

RXbytes:16190 (15.8 KiB) TX bytes:16190 (15.8 KiB)


virbr0 Link encap:Ethernet HWaddr 52:54:00:FD:CB:99

inetaddr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0

UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RXpackets:0 errors:0 dropped:0 overruns:0 frame:0

TXpackets:81 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RXbytes:0 (0.0 b) TX bytes:8031 (7.8 KiB)

4)安装Xen

首先要确定CPU是否支持虚拟化,因为做安装系统前已经启动了bios的虚拟化,所以这个不用担心了。如果在安装系统前未启动bios的虚拟化支持,这里需要检查一下cpu是否支持vmx或者svm


root@bogon ~]#cat /proc/cpuinfo | grep flags

flags: fpuvme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscplm constant_tsc arch_perfmon pebs bts rep_good xtopologynonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmxest tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 popcnt xsave lahf_lmarat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority eptvpid

flags: fpuvme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscplm constant_tsc arch_perfmon pebs bts rep_good xtopologynonstop_tsc pni pclmulqdq dtes64 monitor ds_cpl vmxest tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 popcnt xsave lahf_lmtpr_shadow vnmi flexpriority ept vpid


采用yum安装,下载yum安装源:

[root@bogon ~]#cd /etc/yum.repos.d/

[[email protected]]# wget http://www.crc.id.au/repo/kernel-xen.repo

然后安装xen

yuminstall kernel-xen xen

现在已经安装了xenxen内核。现在需要对grub引导进行配置:

# grub.confgenerated by anaconda

#

# Note that youdo not have to rerun grub after making changes to this file

# NOTICE: Youhave a /boot partition. This means that

# allkernel and initrd paths are relative to /boot/, eg.

# root(hd0,0)

# kernel /vmlinuz-version ro root=/dev/mapper/vg00-lvroot

# initrd /initrd-[generic-]version.img

#boot=/dev/sda

default=1

timeout=10

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

#hiddenmenu


titleCentOS (2.6.32.57-1.el6xen.x86_64)

root(hd0,0)

kernel/xen.gz dom0_mem=2048M cpufreq=xen dom0_max_vcpus=2 dom0_vcpus_pin

module/vmlinuz-2.6.32.57-1.el6xen.x86_64 ro root=/dev/mapper/vg00-lvrootrd_NO_LUKS rd_LVM_LV=vg00/lvroot rd_NO_MD quietrd_LVM_LV=vg00/lvswap rhgb LANG=zh_CN.UTF-8 KEYBOARDTYPE=pcKEYTABLE=us rd_NO_DM crashkernel=auto

module/initramfs-2.6.32.57-1.el6xen.x86_64.img


title CentOS(2.6.32-220.el6.x86_64)

root (hd0,0)

kernel/vmlinuz-2.6.32-220.el6.x86_64 ro root=/dev/mapper/vg00-lvrootrd_NO_LUKS rd_LVM_LV=vg00/lvroot rd_NO_MD quietrd_LVM_LV=vg00/lvswap rhgb LANG=zh_CN.UTF-8 KEYBOARDTYPE=pcKEYTABLE=us rd_NO_DM

initrd/initramfs-2.6.32-220.el6.x86_64.img

5)重新编译libvirt虚拟机管理器。主要参考VirtualizationWith Xen On CentOS 6.2 (x86_64) (Paravirtualization & HardwareVirtualization) ,没有问题。

安装libvirtpychon-virtinstvirt-install工具在创建虚拟机的时候用到。

yum installlibvirt python-virtinst

重建libvirt

yumgroupinstall 'Development Tools'

yum installpython-devel xen-devel libxml2-devel xhtml1-dtds readline-develncurses-devel libtasn1-devel gnutls-devel augeas libudev-devellibpciaccess-devel yajl-devel sanlock-devel libpcap-devellibnl-devel avahi-devel libselinux-devel cyrus-sasl-develparted-devel device-mapper-devel numactl-devel libcap-ng-develnetcf-devel libcurl-devel audit-libs-devel systemtap-sdt-devel

rpm -qa | greplibvirt

[root@server1~]# rpm -qa | greplibvirt
libvirt-client-0.9.4-23.el6_2.4.x86_64
libvirt-0.9.4-23.el6_2.4.x86_64
libvirt-python-0.9.4-23.el6_2.4.x86_64
[root@server1~]#

mkdir/root/src
cd /root/src
wgethttp://vault.centos.org/6.2/os/Source/SPackages/libvirt-0.9.4-23.el6.src.rpm
rpm-i libvirt-0.9.4-23.el6.src.rpm

wgethttp://pasik.reaktio.net/xen/patches/libvirt-spec-rhel6-enable-xen.patch
cd/root/rpmbuild/SPECS
cp -a libvirt.spec libvirt.spec.orig
patch-p0 < ~/src/libvirt-spec-rhel6-enable-xen.patch

rpmbuild -bblibvirt.spec

cd/root/rpmbuild/RPMS/x86_64/

rpm -Uvh--force libvirt-0.9.4-23.el6.x86_64.rpmlibvirt-client-0.9.4-23.el6.x86_64.rpmlibvirt-python-0.9.4-23.el6.x86_64.rpm

reboot系统

以上过程就不详细叙述。重启进入xen内核的系统。

[root@bogon ~]#uname -r

2.6.32.57-1.el6xen.x86_64

[root@bogon ~]#xl list

Name ID Mem VCPUs State Time(s)

Domain-0 0 2048 2 r----- 88.5

[root@bogon ~]#

安装成功。

三,创建虚拟机,安装gustos

1)使用virt-install工具安装

创建虚拟镜像:

lvdisplay

lvcreate-L 10G -n ubuntu vg00

[root@localhost~]# virt-install --prompt --network bridge=virbr0--virt-type=xen
您想要一个全虚拟客户端吗(yes/no)?这将允许您运行未修改的操作系统。
yes
您的虚拟机的名称是什么?
ubuntu
要分配多少RAM( MB为单位)
1024
您希望使用什么作为该磁盘(文件路径)
/dev/vg00/ubuntu
什么是安装光盘/映像或者URL
/var/www/html/ubuntu/ubuntu-11.04-desktop-i386.iso

开始安装......
创建域......


安装成功后可以使用virtmanager查看gustos安装过程了。

2)使用虚拟机管理器创建虚拟机及安装客户操作系统。

3)主要安装了ubuntuxp作为测试,一切正常。

同时运行2个虚拟机,一个是xp,一个是ubuntu。由于只是一台主机,无法做迁移测试。安装后的截屏:





你可能感兴趣的:(云计算)