Servidor Ubuntu con soporte de virtualización Xen

By marble - Last updated: Sunday, November 30, 2008 - Compartir - Dejar un comentario

Veamos como podemos configurar un servidor Ubuntu como plataforma de virtualización mediante el uso de Xen. En primer lugar debemos instalar un kernel con soporte Xen:

apt-get install ubuntu-xen-server
mkdir /home/xen/

Nos aseguramos que las opciones de configuración de grub sean correctas en ‘/boot/grub/menu.lst’ y que el kernel con soporte Xen es el que arranca por defecto. A continuación reiniciamos:

reboot

En el siguiente inicio del sistema podemos comprobar que Xen esta corriendo si se ejecuta correctamente el siguiente comando:

# xm list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1738     2     r-----     68.4

Ahora ha llegado el momento de realizar la instalación de una máquina virtual. La distribución puede ser cualquiera de las que mencionadas en ‘/usr/lib/xen-tools’:

$ ls -l /usr/lib/xen-tools
drwxr-xr-x 2 root root 4096 Sep 25 22:05 centos-4.d
drwxr-xr-x 2 root root 4096 Sep 25 22:05 centos-5.d
-rwxr-xr-x 1 root root 4409 Apr  6 03:12 common.sh
drwxr-xr-x 2 root root 4096 Sep 25 22:05 dapper.d
drwxr-xr-x 2 root root 4096 Sep 25 22:05 debian.d
drwxr-xr-x 2 root root 4096 Sep 25 22:05 edgy.d
lrwxrwxrwx 1 root root    8 Sep 25 22:05 etch.d -> debian.d
lrwxrwxrwx 1 root root   15 Sep 25 22:05 fedora-core-4.d -> fedora-core-6.d
lrwxrwxrwx 1 root root   15 Sep 25 22:05 fedora-core-5.d -> fedora-core-6.d
drwxr-xr-x 2 root root 4096 Sep 25 22:05 fedora-core-6.d
lrwxrwxrwx 1 root root   15 Sep 25 22:05 fedora-core-7.d -> fedora-core-6.d
lrwxrwxrwx 1 root root    6 Sep 25 22:05 feisty.d -> edgy.d
drwxr-xr-x 2 root root 4096 Sep 25 22:05 gentoo.d
lrwxrwxrwx 1 root root    6 Sep 25 22:05 gutsy.d -> edgy.d
lrwxrwxrwx 1 root root    6 Sep 25 22:05 hardy.d -> edgy.d
lrwxrwxrwx 1 root root    8 Sep 25 22:05 lenny.d -> debian.d
lrwxrwxrwx 1 root root    8 Sep 25 22:05 sarge.d -> debian.d
lrwxrwxrwx 1 root root    8 Sep 25 22:05 sid.d -> debian.d

En concreto, vamos a crear una máquina virtual con las siguientes características:

xen-create-image --hostname=webserver.localhost --size=5Gb --swap=256Mb --ide \
--ip=192.168.22.101 --netmask=255.255.255.0 --gateway=192.168.22.1 --force \
--dir=/home/xen --memory=256Mb --arch=i386 --kernel=/boot/vmlinuz-2.6.24-19-xen \
--initrd=/boot/initrd.img-2.6.24-19-xen --install-method=debootstrap --dist=hardy \
--mirror=http://archive.ubuntu.com/ubuntu/ --passwd

Resultado:

General Information
--------------------
Hostname       :  webserver.localhost
Distribution   :  hardy
Partitions     :  swap            256Mb (swap)
                  /               5Gb   (ext3)
Image type     :  sparse
Memory size    :  256Mb
Kernel path    :  /boot/vmlinuz-2.6.24-19-xen
Initrd path    :  /boot/initrd.img-2.6.24-19-xen

Networking Information
----------------------
IP Address 1   : 192.168.22.101 [MAC: 00:16:3E:6B:A7:BD]
Netmask        : 255.255.255.0
Broadcast      : 192.168.22.255
Gateway        : 192.168.22.1

Creating partition image: /home/xen/domains/webserver.localhost/swap.img
Done

Creating swap on /home/xen/domains/webserver.localhost/swap.img
Done

Creating partition image: /home/xen/domains/webserver.localhost/disk.img
Done

Creating ext3 filesystem on /home/xen/domains/webserver.localhost/disk.img
Done
Installation method: debootstrap
Done

Running hooks
Done

No role scripts were specified.  Skipping

Creating Xen configuration file
Done
Setting up root password
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
All done

Logfile produced at:
         /var/log/xen-tools/webserver.localhost.log

Se habran creado los ficheros necesarios en ‘/home/xen’ y la configuración de la máquina se encuentra en ‘/etc/xen/webserver.localhost.cfg’. Debemos editarla y cambiar las cadenas ‘file:/’ (obsoleta en la versión actual de Xen):

disk        = [
                  'file:/home/xen/domains/webserver.localhost/swap.img,hda1,w',
                  'file:/home/xen/domains/webserver.localhost/disk.img,hda2,w',
              ]

Por:

disk        = [
                  'tap:aio:/home/xen/domains/webserver.localhost/swap.img,hda1,w',
                  'tap:aio:/home/xen/domains/webserver.localhost/disk.img,hda2,w',
              ]

En ese mismo fichero, en caso de que tengamos un ordenador con varias CPUs o varios cores, podemos habilitar la máquina virtual para que use ambos añadiendo lo siguiente al mismo fichero ‘/etc/xen/webserver.localhost.cfg’:

vcpus       = '2'

Por defecto Xen viene configurado en modo bridge, como probablemente nuestro proveedor de Internet únicamente nos proporcione una IP, deberiamos cambiarlo a modo NAT. Sino, en el ejemplo anterior, cuando arranquemos la máquina virtual Xen intentará asignar la IP 192.168.22.101 a eth0 y probablemente perdamos la conexión remota si estamos por SSH. Para realizar el cambio editamos ‘/etc/xen/xend-config.sxp’ y comentamos:

# To bridge network traffic, like this:
#
# dom0: ----------------- bridge -> real eth0 -> the network
#                            |
# domU: fake eth0 -> vifN.0 -+
# [...]
#(network-script network-bridge)
#(vif-script vif-bridge)

Para después descomentar:

## Use the following if network traffic is routed with NAT, as an alternative
# to the settings for bridged networking given above.
(network-script network-nat)
(vif-script     vif-nat)

Además es recomendable deshabilitar la relocación de máquinas virtuales: ‘(xend-relocation-server no)’

A continuación ya podemos arrancar la máquina:

xm create /etc/xen/webserver.localhost.cfg

Para conectarse a la máquina:

xm console webserver.localhost

Si quisieramos salir de ella basta con pulsar CTRL y ‘+’. Para parar o destruir (como si fuese un power off) la máquina:

xm shutdown webserver.localhost
xm destroy webserver.localhost

Para listar las máquinas activas:

xm list

Más opciones en ‘xm help’.

Si quisiesemos añadir más discos duros virtuales, podemos crearlos mediante:

dd if=/dev/zero of=extra.img oflag=direct bs=1M seek=153600 count=1
mke2fs -j -O dir_index extra.img

Esto generará el fichero extra.img con capacidad para 150 GB, formateado con ext3. Para activarlo en nuestra máquina virtual debemos editar ‘/etc/xen/webserver.localhost.cfg’.

Finalmente, para que la máquina virtual arranque automáticamente al iniciar el sistema:

ln -s /etc/xen/webserver.localhost.cfg /etc/xen/auto

Más información en Virtualización con Xen.

Categoría(s): Castellano • • Ir al principio de la página

Dejar un comentario

You need to enable javascript in order to use Simple CAPTCHA.
Security Code: