sábado, 12 de diciembre de 2009

Instalar Xen en Ubuntu 8.04 LST

Pasos previos
Nos loguemos como root:

sudo su

Es buena idea deshabilitar AppArmor:(si existe)

/etc/init.d/apparmor stop
update-rc.d -f apparmor remove

Instalando Xen

Para Instalar Xen lo único que debemos hacer es ejecutar el comando:

aptitude install ubuntu-xen-server
mv /lib/tls /lib/tls.disabled

vim /etc/modules
[...]
loop max_loop=64
[...]

ls -l /boot/

total 36052
-rw-r--r-- 1 root root 420395 2009-04-01 21:41 abi-2.6.24-23-server
-rw-r--r-- 1 root root 74171 2009-04-01 21:41 config-2.6.24-23-server
-rw-r--r-- 1 root root 82847 2009-04-15 14:57 config-2.6.24-24-xen
drwxr-xr-x 2 root root 4096 2009-06-17 12:55 grub
-rw-r--r-- 1 root root 7496287 2009-06-17 12:42 initrd.img-2.6.24-23-server
-rw-r--r-- 1 root root 7218067 2009-06-16 15:39 initrd.img-2.6.24-23-server.bak
-rw-r--r-- 1 root root 7439996 2009-06-17 12:49 initrd.img-2.6.24-24-xen
-rw-r--r-- 1 root root 7439756 2009-06-17 12:49 initrd.img-2.6.24-24-xen.bak
-rw-r--r-- 1 root root 103204 2007-09-28 08:03 memtest86+.bin
-rw-r--r-- 1 root root 1163432 2009-04-01 21:41 System.map-2.6.24-23-server
-rw-r--r-- 1 root root 1128034 2009-04-15 14:57 System.map-2.6.24-24-xen
-rw-r--r-- 1 root root 1930136 2009-04-01 21:41 vmlinuz-2.6.24-23-server
-rw-r--r-- 1 root root 1894234 2009-04-15 14:57 vmlinuz-2.6.24-24-xen
-rw-r--r-- 1 root root 401328 2009-02-21 01:04 xen-3.2.gz

ls -l /usr/lib/xen-tools

total 36
drwxr-xr-x 2 root root 4096 2009-06-17 12:49 centos-4.d
drwxr-xr-x 2 root root 4096 2009-06-17 12:49 centos-5.d
-rwxr-xr-x 1 root root 4409 2008-04-05 22:12 common.sh
drwxr-xr-x 2 root root 4096 2009-06-17 12:49 dapper.d
drwxr-xr-x 2 root root 4096 2009-06-17 12:49 debian.d
drwxr-xr-x 2 root root 4096 2009-06-17 12:49 edgy.d
lrwxrwxrwx 1 root root 8 2009-06-17 12:49 etch.d -> debian.d
lrwxrwxrwx 1 root root 15 2009-06-17 12:49 fedora-core-4.d -> fedora-core-6.d
lrwxrwxrwx 1 root root 15 2009-06-17 12:49 fedora-core-5.d -> fedora-core-6.d
drwxr-xr-x 2 root root 4096 2009-06-17 12:49 fedora-core-6.d
lrwxrwxrwx 1 root root 15 2009-06-17 12:49 fedora-core-7.d -> fedora-core-6.d
lrwxrwxrwx 1 root root 6 2009-06-17 12:49 feisty.d -> edgy.d
drwxr-xr-x 2 root root 4096 2009-06-17 12:49 gentoo.d
lrwxrwxrwx 1 root root 6 2009-06-17 12:49 gutsy.d -> edgy.d
lrwxrwxrwx 1 root root 6 2009-06-17 12:49 hardy.d -> edgy.d
lrwxrwxrwx 1 root root 8 2009-06-17 12:49 lenny.d -> debian.d
lrwxrwxrwx 1 root root 8 2009-06-17 12:49 sarge.d -> debian.d
lrwxrwxrwx 1 root root 8 2009-06-17 12:49 sid.d -> debian.d


Como vemos podemos instalar cualquiera de las siguientes distribuciones:

* Debian: Lenny, Sid, Etch, Sarge
* Ubuntu: Dapper Drake, Edgy Eft, Feisty Fawn, Gutsy Gibbon, Hardy Heron
* CentOS 4, CentOS 5
* Fedora Core 4, 5, 6, Fedora 7
* Gentoo

Para mantener un orden vamos a guardar las maquinas virtuales en el directorio /home/xen:

mkdir /home/xen


Utilizaremos xen-tools para crear maquinas virtuales. El paquete xen-tools se instala junto con el paquete ubuntu-xen-server package

Ahora editamos el fichero /etc/xen-tools/xen-tools.conf. Este fichero contiene los valores por defecto con los que se creará la maquina virtual, a mones que en su momento especifiquemos un valor diferente, es decir, funciona como una plantilla.

dir = /home/xen
use-ide = 1
install-method = debootstrap
size = 4Gb # Disk image size.
memory = 512Mb # Memory size
swap = 256Mb # Swap size
# noswap = 1 # Don't use swap at all for the new system.
fs = ext3 # use the EXT3 filesystem for the disk image.
dist = hardy # Default distribution to install.
image = sparse # Specify sparse vs. full disk images.
gateway =
netmask =
passwd = 1
kernel = /boot/vmlinuz-`uname -r`
initrd = /boot/initrd.img-`uname -r`
mirror = http://archive.ubuntu.com/ubuntu/
ext3_options = noatime,nodiratime,errors=remount-ro
ext2_options = noatime,nodiratime,errors=remount-ro
xfs_options = defaults
reiser_options = defaults
disk_device = xvda #default


Ahora reiniciamos el sistema:

init 6


Si el sistema reinicia sin problemas, todo anduvo bien.
Ejecutamos:

uname -r

y nuestro nuevo Xen kernel debe mostrar algo así:

2.6.24-24-xen


Network Bridge a medida
La solucion con Puentes/bridge's es la mas comoda segun nuestro analisis.
consta de la interfaz fisica en si un puente a ella, y luego varias vif asociadas a la anterior .

ej: eth1 ---->peth1----->bridge_eth1{vif1 vif2 vif3}

Xen trae consigo las herramientas necesarias [lease scripts en bash] para poder crear puentes rapidamente. por esto, solo hay q tener en claro el numero de vif, la interfaz y el nombre q le deseamos dar dar al bridge. entonces:

vifnum=1 netdev=eth1 bridge=lan

este anterior, seria el argumento del script. Ya que esta dentro de los procesos de arranque de Xen es necesario colocarlo dentro del mismo para que funcione.

llamaremos al script "redes", [el que colocamos en xend-config.sxp para que sea invocado al momento del arranque de xen debe tener permisos de ejecucion]

el contenido del script seria el siguiente:

#!/bin/sh
dir=$(dirname "$0")
echo "$dir"
"$dir/network-bridge" "$1" vifnum=1 netdev=eth1 bridge=lan
ifconfig lan up
"$dir/network-bridge" "$1" vifnum=2 netdev=eth2 bridge=wan
ifconfig wan up


es bueno aclarar que los ifconfig***** se los coloca por precaucion ya que en ubuntu no suele funcionar el punte si no esta bringed up la interfaz.

Otro detalle problematico en ubuntu es q en algunos casos no suele funcionar bien el bridge.[perdida de paquetes] tomar la precaucion de corroborar si mii-tool pethx alerta un "link ok" solo. de ser este el caso, realizar ifdown/ifup a la interface hasta que mii-tool alerte "negotiated 100baseTx-FD flow-control, link ok"



Crear un Guest


xen-create-image --hostname NOMBRE --ip=


En Ubuntu debemos editar el archivo de configuración de la maquina virtual para que reconozca el los discos virtuales.

Cambiamos 'file:' por 'tap:aio:'

vim /etc/xen/NOMBRE.cfg
[...]
#
# Disk device(s).
#
root = '/dev/xvda2 ro'
disk = [
'tap:aio:/home/xen/domains/NOMBRE/swap.img,xvda1,w',
'tap:aio:/home/xen/domains/NOMBRE/disk.img,xvda2,w',
]
[...]


Administrar Maquinas Virtuales en XEN

xm create NOMBRE # Arrancar VM
xm create NOMBRE -c # Arrancar VM e ingresar en consola de la VM
xm console NOMBRE # Ingresar en consola de la VM
xm list # Mostrar lista de VM activas
xm destroy NOMBRE # Detener VM
xm top # ver el estado activo de cada equipo
Dentro de la maquina virtual si ingresamos con xm create NOMBRE.cfg -c para salirnos de la consola debemos presionar ctrl+5 y volveremos a la consola de la que partimos.

No hay comentarios:

Publicar un comentario