En el articulo anterior hemos instalado xen 4.1 en debian squeeze, ahora vamos a instalar algunas herramientas que nos servirán para administrar nuestros VPSs, por ahora instalaremos vnstat y xen-tools, como siempre utilizando apt-get para que la administración de las actualizaciones sea mas fácil.
Primero instalamos vnstat
root@x49:/# apt-get install vnstat Reading package lists... Done Building dependency tree Reading state information... Done Suggested packages: vnstati The following NEW packages will be installed: vnstat 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 0 B/82.4 kB of archives. After this operation, 311 kB of additional disk space will be used. Selecting previously deselected package vnstat. (Reading database ... 28735 files and directories currently installed.) Unpacking vnstat (from .../vnstat_1.10-1_amd64.deb) ... Processing triggers for man-db ... Setting up vnstat (1.10-1) ... Starting vnStat daemon: vnstatdZero database found, exiting. failed!
El error que vemos es por que todavía no hay interfaces de red asignadas a vnstat, entonces procedemos a agregarlas, en este caso agregaremos eth0, eth1 y xenbr0
root@x49:/# vnstat -u -i eth0 Error: Unable to read database "/var/lib/vnstat/eth0". Info: -> A new database has been created. root@x49:/# vnstat -u -i eth1 Error: Unable to read database "/var/lib/vnstat/eth1". Info: -> A new database has been created. root@x49:/# vnstat -u -i xenbr0 Error: Unable to read database "/var/lib/vnstat/xenbr0". Info: -> A new database has been created. root@x49:/#
Y luego restarteamos vnstat
root@x49:/# /etc/init.d/vnstat restart Stopping vnStat daemon: vnstatd. Starting vnStat daemon: vnstatd. root@x49:/#
Ahora instalamos xen-tools, instalamos la versión que esta en debian testing, primero agregamos al final de nuestro /etc/apt/preferences las siguientes lineas
Package: xen-tools Pin: release a=testing Pin-Priority: 750
y ahora procedemos a instalarlo
root@x49:/# apt-get install xen-tools Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: debootstrap libconfig-inifiles-perl libexpect-perl libfile-slurp-perl libio-pty-perl libio-stty-perl libtext-template-perl Suggested packages: reiserfsprogs xfsprogs cfengine2 btrfs-tools Recommended packages: rinse The following NEW packages will be installed: debootstrap libconfig-inifiles-perl libexpect-perl libfile-slurp-perl libio-pty-perl libio-stty-perl libtext-template-perl xen-tools 0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded. Need to get 559 kB of archives. After this operation, 1,761 kB of additional disk space will be used. Do you want to continue [Y/n]? Get:1 http://ftp.debian.org/debian/ squeeze/main libio-stty-perl all 0.02-10 [10.1 kB] Get:2 http://ftp.debian.org/debian/ squeeze/main libio-pty-perl amd64 1:1.08-1 [42.5 kB] Get:3 http://ftp.debian.org/debian/ squeeze/main libexpect-perl all 1.20-2 [78.0 kB] Get:4 http://ftp.debian.org/debian/ squeeze/main libfile-slurp-perl all 9999.13-1 [16.8 kB] Get:5 http://ftp.debian.org/debian/ squeeze/main debootstrap all 1.0.26+squeeze1 [57.5 kB] Get:6 http://ftp.debian.org/debian/ squeeze/main libconfig-inifiles-perl all 2.52-1+squeeze1 [48.0 kB] Get:7 http://ftp.debian.org/debian/ squeeze/main libtext-template-perl all 1.45-1 [54.5 kB] Get:8 http://ftp.debian.org/debian/ wheezy/main xen-tools all 4.3.1-1 [252 kB] Fetched 559 kB in 5s (104 kB/s) Selecting previously deselected package libio-stty-perl. (Reading database ... 28749 files and directories currently installed.) Unpacking libio-stty-perl (from .../libio-stty-perl_0.02-10_all.deb) ... Selecting previously deselected package libio-pty-perl. Unpacking libio-pty-perl (from .../libio-pty-perl_1%3a1.08-1_amd64.deb) ... Selecting previously deselected package libexpect-perl. Unpacking libexpect-perl (from .../libexpect-perl_1.20-2_all.deb) ... Selecting previously deselected package libfile-slurp-perl. Unpacking libfile-slurp-perl (from .../libfile-slurp-perl_9999.13-1_all.deb) ... Selecting previously deselected package debootstrap. Unpacking debootstrap (from .../debootstrap_1.0.26+squeeze1_all.deb) ... Selecting previously deselected package libconfig-inifiles-perl. Unpacking libconfig-inifiles-perl (from .../libconfig-inifiles-perl_2.52-1+squeeze1_all.deb) ... Selecting previously deselected package libtext-template-perl. Unpacking libtext-template-perl (from .../libtext-template-perl_1.45-1_all.deb) ... Selecting previously deselected package xen-tools. Unpacking xen-tools (from .../xen-tools_4.3.1-1_all.deb) ... Processing triggers for man-db ... Setting up libio-stty-perl (0.02-10) ... Setting up libio-pty-perl (1:1.08-1) ... Setting up libexpect-perl (1.20-2) ... Setting up libfile-slurp-perl (9999.13-1) ... Setting up debootstrap (1.0.26+squeeze1) ... Setting up libconfig-inifiles-perl (2.52-1+squeeze1) ... Setting up libtext-template-perl (1.45-1) ... Setting up xen-tools (4.3.1-1) ... root@x49:/#
Ya lo tenemos instalado ahora procedemos a configurar xen-tools para eso deben editar /etc/xen-tools/xen-tools.conf de manera que luzca así
NOTA: esta es una configuración básica para hacer pruebas, el archivo original tiene muchas opciones y están muy bien comentadas lo cual hace fácil adaptarlo a las necesidades de cada instalación en particular
NOTA 2: Modificar los datos de red por los que corresponda, este archivo es para una red 192.168.252.0
root@x49:/# cat /etc/xen-tools/xen-tools.conf ## dir = /var/lib/xen/DomUs # # # install-method = [ debootstrap | rinse | rpmstrap | copy | tar ] # # install-method = debootstrap # ## # Disk and Sizing options. ## # size = 4Gb # Disk image size. memory = 512Mb # Memory size swap = 512Mb # Swap size # noswap = 1 # Don't use swap at all for the new system. fs = ext4 # use the EXT3 filesystem for the disk image. dist = `xt-guess-suite-and-mirror --suite` # Default distribution to install. image = full # Specify sparse vs. full disk images. # # Uncomment and adjust these network settings if you wish to give your # new instances static IP addresses. # gateway = 192.168.252.1 netmask = 255.255.255.0 broadcast = 192.168.252.255 # # You can also change the password length by uncommenting and # changing the line below # genpass_len = 8 # # # Uncomment the following line if you wish to interactively setup a # new root password for images. # # passwd = 1 # # # Default kernel and ramdisk to use for the virtual servers # kernel = /boot/vmlinuz-`uname -r` initrd = /boot/initrd.img-`uname -r` # # The architecture to use when using debootstrap, rinse, or rpmstrap. # # This is most useful on 64 bit host machines, for other systems it # doesn't need to be used. # # arch = [i386|amd64] # # # The default mirror for debootstrap to install Debian-derived distributions # mirror = `xt-guess-suite-and-mirror --mirror` # # Filesystem options for the different filesystems we support. # ext3_options = noatime,nodiratime,errors=remount-ro ext2_options = noatime,nodiratime,errors=remount-ro xfs_options = defaults reiserfs_options = defaults btrfs_options = defaults root@x49:/#
Creamos el archivo /etc/xen-tools/partitions.d/default_4G con el siguiente contenido
NOTA: este archivo lo creamos para nuestras pruebas, pueden crearse varios archivos con diferentes esquemas de particiones tomando como ejemplo /etc/xen-tools/partitions.d/sample-server
NOTA 2: Si van a usar reiserfs, xfs o btrfs no olviden antes instalar los paquetes reiserfsprogs, xfsprogs y btrfs-tools
root@x49:/# cat /etc/xen-tools/partitions.d/default_4G [root] size=4G type=ext4 mountpoint=/ options=sync,errors=remount-ro [swap] size=512M type=swap root@x49:/#
Ahora creamos el archivo /etc/modprobe.d/loop.conf con el siguiente contenido (NOTA: max_loop lo configuramos con un valor de 32 pero deben elegir el que mas se adecue a sus necesidades)
root@x49:/# cat /etc/modprobe.d/loop.conf options loop max_loop=32 root@x49:/#
Luego descargamos y volvemos a cargar el modulo loop para que se cargue con la opción que hemos configurado
root@x49:/# rmmod loop ; modprobe loop root@x49:/#
Ahora procedemos a hacer la primera instalacion de un DomUs y chequeamos que todo funcione correctamente
root@x49:/# xen-create-image --dist=squeeze --hostname=x50 --vifname=x50 --mac=00:16:C0:A8:FC:32 --ip=192.168.252.50 --partitions=default_4G WARNING ------- You appear to have a "dummy" vif-script, or network-script, setting in the Xen configuration file /etc/xen/xend-config.sxp. Please fix this and restart Xend, or your guests will not be able to use any networking! General Information -------------------- Hostname : x50 Distribution : squeeze Mirror : http://ftp.debian.org/debian/ Partitions : swap 512M (swap) / 4G (ext4) Image type : full Memory size : 512Mb Kernel path : /boot/vmlinuz-3.2.0-0.bpo.4-amd64 Initrd path : /boot/initrd.img-3.2.0-0.bpo.4-amd64 Networking Information ---------------------- IP Address 1 : 192.168.252.50 [MAC: 00:16:C0:A8:FC:32] Netmask : 255.255.255.0 Broadcast : 192.168.252.255 Gateway : 192.168.252.1 Creating partition image: /var/lib/xen/DomUs/domains/x50/swap.img Done Creating swap on /var/lib/xen/DomUs/domains/x50/swap.img Done Creating partition image: /var/lib/xen/DomUs/domains/x50/root.img Done Creating ext4 filesystem on /var/lib/xen/DomUs/domains/x50/root.img Done Installation method: debootstrap Done Running hooks Done No role scripts were specified. Skipping Creating Xen configuration file Done No role scripts were specified. Skipping Setting up root password Generating a password for the new guest. All done Logfile produced at: /var/log/xen-tools/x50.log Installation Summary --------------------- Hostname : x50 Distribution : squeeze IP-Address(es) : 192.168.252.50 RSA Fingerprint : 92:96:56:40:60:4d:17:ce:72:5a:28:32:81:6f:9a:b3 Root Password : xxxxxxxx root@x49:/#
Ahora editamos el archivo /etc/xen/x50.cfg y agregamos opciones extra para nuestro kernel
Nota: Cada caso en particular puede requerir diferentes opciones de kernel.
root@x49:/# cat /etc/xen/x50.cfg # # Configuration file for the Xen instance x50, created # by xen-tools 4.3.1 on Thu Jan 17 01:33:06 2013. # # # Kernel + memory size # kernel = '/boot/vmlinuz-3.2.0-0.bpo.4-amd64' ramdisk = '/boot/initrd.img-3.2.0-0.bpo.4-amd64' vcpus = '1' memory = '512' # # Disk device(s). # root = '/dev/xvda2 ro' disk = [ 'file:/var/lib/xen/DomUs/domains/x50/root.img,xvda2,w', 'file:/var/lib/xen/DomUs/domains/x50/swap.img,xvda1,w', ] # # Physical volumes # # # Hostname # name = 'x50' # # Networking # vif = [ 'ip=192.168.252.50 ,mac=00:16:C0:A8:FC:32,vifname=x50' ] # # Behaviour # on_poweroff = 'destroy' on_reboot = 'restart' on_crash = 'restart' extra = 'elevator=deadline console=hvc0 noht loglevel=0'
Y ahora procedemos a iniciar el VPS
root@x49:/# xen create /etc/xen/x50.cfg -c Parsing config file /etc/xen/x50.cfg Daemon running with PID 18964 Loading, please wait... Begin: Loading essential drivers ... done. Begin: Running /scripts/init-premount ... done. Begin: Mounting root file system ... Begin: Running /scripts/local-top ... done. Begin: Running /scripts/local-premount ... done. Begin: Running /scripts/local-bottom ... done. done. Begin: Running /scripts/init-bottom ... done. INIT: version 2.88 booting Using makefile-style concurrent boot in runlevel S. Starting the hotplug events dispatcher: udevd. Synthesizing the initial hotplug events...done. Waiting for /dev to be fully populated...done. Activating swap...done. Checking root file system...fsck from util-linux-ng 2.17.2 /dev/xvda2: clean, 13836/262144 files, 168287/1048576 blocks done. Loading kernel modules...done. Cleaning up ifupdown.... Setting up networking.... Activating lvm and md swap...done. Checking file systems...fsck from util-linux-ng 2.17.2 done. Mounting local filesystems...done. Activating swapfile swap...done. Cleaning up temporary files.... Configuring network interfaces...done. Cleaning up temporary files...Setting kernel variables ...done. . INIT: Entering runlevel: 2 Using makefile-style concurrent boot in runlevel 2. Starting enhanced syslogd: rsyslogd. Starting periodic command scheduler: cron. Starting OpenBSD Secure Shell server: sshd. Debian GNU/Linux 6.0 x50 hvc0 x50 login:
Luego nos logueamos por ssh y checkeamos que nuestro VPS este instalado correctamente.
Luego podemos crear un script vif-bridge personalizado para que cuando arranque el VPS agregue la interfaz del VPS al vnstat, el script lo creamos en /usr/local/xen/vif-bridge-local.sh con el siguiente contenido
root@x49:/# cat /usr/local/xen/vif-bridge-local.sh #!/bin/bash XENSTORE_READ=/usr/sbin/xenstore-read VNSTAT=/usr/bin/vnstat THIS_FILE=`basename $0` FILE_LOG_ERRORS=/var/log/${THIS_FILE}.log . /etc/xen/scripts/xen-script-common.sh ACTION_TYPE=$1 TYPEIF=$2 evalVariables "$@" dev=vif case "$type_if" in vif) dev=${vif} ;; tap) dev=$INTERFACE ;; *) exit 1 ;; esac if [ "${ACTION_TYPE}" = "online" ] then if [ "${type_if}" = "vif" ] then /etc/xen/scripts/vif-bridge $@ KEY_VIFNAME=/local/domain/0/${XENBUS_PATH}/vifname vifname=`${XENSTORE_READ} ${KEY_VIFNAME} 2>/dev/null` ${VNSTAT} -u -i ${vifname} 1>/dev/null 2>>${FILE_LOG_ERRORS} ${VNSTAT} --enable -i ${vifname} 1>/dev/null 2>>${FILE_LOG_ERRORS} ${VNSTAT} --sync -i ${vifname} 1>/dev/null 2>>${FILE_LOG_ERRORS} ${VNSTAT} --reset -i ${vifname} 1>/dev/null 2>>${FILE_LOG_ERRORS} else /etc/xen/scripts/vif-bridge $@ fi fi if [ "${ACTION_TYPE}" = "offline" ] then if [ "${type_if}" = "vif" ] then KEY_VIFNAME=/local/domain/0/${XENBUS_PATH}/vifname vifname=`${XENSTORE_READ} ${KEY_VIFNAME} 2>/dev/null` ${VNSTAT} -r --disable -i ${vifname} 1>/dev/null 2>>${FILE_LOG_ERRORS} /etc/xen/scripts/vif-bridge $@ else /etc/xen/scripts/vif-bridge $@ fi fi if [ "${ACTION_TYPE}" = "add" ] then /etc/xen/scripts/vif-bridge $@ fi root@x49:/#
Y editamos /etc/xen/xl.conf de modo que luzca asi
root@x49:/# cat /etc/xen/xl.conf ## Global XL config file ## # automatically balloon down dom0 when xen doesn't have enough free # memory to create a domain autoballoon=0 # full path of the lockfile used by xl during domain creation lockfile="/var/lock/xl" # default vif script #vifscript="/etc/xen/scripts/vif-bridge" vifscript="/usr/local/xen/vif-bridge-local.sh" root@x49:/#
Dentro de este script si queremos podemos llamar a algún script propio que se encargue de limitar el ancho de banda de la interfaz del VPS, eso lo veremos en un proximo articulo.

About Ricardo Marcelo Alvarez
- Web |
- More Posts(58)