{"id":677,"date":"2008-11-30T17:49:41","date_gmt":"2008-11-30T15:49:41","guid":{"rendered":"http:\/\/www.marblestation.com\/blog\/?p=677"},"modified":"2012-04-26T16:18:58","modified_gmt":"2012-04-26T14:18:58","slug":"servidor-ubuntu-con-soporte-de-virtualizacion-xen","status":"publish","type":"post","link":"https:\/\/www.marblestation.com\/?p=677","title":{"rendered":"Servidor Ubuntu con soporte de virtualizaci\u00f3n Xen"},"content":{"rendered":"<p>Veamos como podemos configurar un servidor Ubuntu como plataforma de virtualizaci\u00f3n mediante el uso de <a href=\"http:\/\/en.wikipedia.org\/wiki\/Xen\">Xen<\/a>. En primer lugar debemos instalar un kernel con soporte Xen:<\/p>\n<pre>\r\napt-get install ubuntu-xen-server\r\nmkdir \/home\/xen\/\r\n<\/pre>\n<p>Nos aseguramos que las opciones de configuraci\u00f3n de grub sean correctas en &#8216;\/boot\/grub\/menu.lst&#8217; y que el kernel con soporte Xen es el que arranca por defecto. A continuaci\u00f3n reiniciamos:<\/p>\n<pre>\r\nreboot\r\n<\/pre>\n<p>En el siguiente inicio del sistema podemos comprobar que Xen esta corriendo si se ejecuta correctamente el siguiente comando:<br \/>\n<!--more--><\/p>\n<pre>\r\n# xm list\r\nName                                        ID   Mem VCPUs      State   Time(s)\r\nDomain-0                                     0  1738     2     r-----     68.4\r\n<\/pre>\n<p>Ahora ha llegado el momento de realizar la instalaci\u00f3n de una m\u00e1quina virtual. La distribuci\u00f3n puede ser cualquiera de las que mencionadas en &#8216;\/usr\/lib\/xen-tools&#8217;:<\/p>\n<pre>\r\n$ ls -l \/usr\/lib\/xen-tools\r\ndrwxr-xr-x 2 root root 4096 Sep 25 22:05 centos-4.d\r\ndrwxr-xr-x 2 root root 4096 Sep 25 22:05 centos-5.d\r\n-rwxr-xr-x 1 root root 4409 Apr  6 03:12 common.sh\r\ndrwxr-xr-x 2 root root 4096 Sep 25 22:05 dapper.d\r\ndrwxr-xr-x 2 root root 4096 Sep 25 22:05 debian.d\r\ndrwxr-xr-x 2 root root 4096 Sep 25 22:05 edgy.d\r\nlrwxrwxrwx 1 root root    8 Sep 25 22:05 etch.d -> debian.d\r\nlrwxrwxrwx 1 root root   15 Sep 25 22:05 fedora-core-4.d -> fedora-core-6.d\r\nlrwxrwxrwx 1 root root   15 Sep 25 22:05 fedora-core-5.d -> fedora-core-6.d\r\ndrwxr-xr-x 2 root root 4096 Sep 25 22:05 fedora-core-6.d\r\nlrwxrwxrwx 1 root root   15 Sep 25 22:05 fedora-core-7.d -> fedora-core-6.d\r\nlrwxrwxrwx 1 root root    6 Sep 25 22:05 feisty.d -> edgy.d\r\ndrwxr-xr-x 2 root root 4096 Sep 25 22:05 gentoo.d\r\nlrwxrwxrwx 1 root root    6 Sep 25 22:05 gutsy.d -> edgy.d\r\nlrwxrwxrwx 1 root root    6 Sep 25 22:05 hardy.d -> edgy.d\r\nlrwxrwxrwx 1 root root    8 Sep 25 22:05 lenny.d -> debian.d\r\nlrwxrwxrwx 1 root root    8 Sep 25 22:05 sarge.d -> debian.d\r\nlrwxrwxrwx 1 root root    8 Sep 25 22:05 sid.d -> debian.d\r\n<\/pre>\n<p>En concreto, vamos a crear una m\u00e1quina virtual con las siguientes caracter\u00edsticas:<\/p>\n<ul>\n<li>Distribuci\u00f3n: Ubuntu Hardy<\/li>\n<li>Tama\u00f1o del disco duro: 5 GB<\/li>\n<li>Swap: 256 MB<\/li>\n<li>Memoria RAM: 256 MB<\/li>\n<li>IP: 192.168.22.101<\/li>\n<li>Contrase\u00f1a de root: Se nos preguntar\u00e1 interactivamente.<\/li>\n<li>Directorio donde se almacenara la informaci\u00f3n: \/home\/xen\/<\/li>\n<\/ul>\n<pre>\r\nxen-create-image --hostname=webserver.localhost --size=5Gb --swap=256Mb --ide \\\r\n--ip=192.168.22.101 --netmask=255.255.255.0 --gateway=192.168.22.1 --force \\\r\n--dir=\/home\/xen --memory=256Mb --arch=i386 --kernel=\/boot\/vmlinuz-2.6.24-19-xen \\\r\n--initrd=\/boot\/initrd.img-2.6.24-19-xen --install-method=debootstrap --dist=hardy \\\r\n--mirror=http:\/\/archive.ubuntu.com\/ubuntu\/ --passwd\r\n<\/pre>\n<p>Resultado:<\/p>\n<pre>\r\nGeneral Information\r\n--------------------\r\nHostname       :  webserver.localhost\r\nDistribution   :  hardy\r\nPartitions     :  swap            256Mb (swap)\r\n                  \/               5Gb   (ext3)\r\nImage type     :  sparse\r\nMemory size    :  256Mb\r\nKernel path    :  \/boot\/vmlinuz-2.6.24-19-xen\r\nInitrd path    :  \/boot\/initrd.img-2.6.24-19-xen\r\n\r\nNetworking Information\r\n----------------------\r\nIP Address 1   : 192.168.22.101 [MAC: 00:16:3E:6B:A7:BD]\r\nNetmask        : 255.255.255.0\r\nBroadcast      : 192.168.22.255\r\nGateway        : 192.168.22.1\r\n\r\n\r\nCreating partition image: \/home\/xen\/domains\/webserver.localhost\/swap.img\r\nDone\r\n\r\nCreating swap on \/home\/xen\/domains\/webserver.localhost\/swap.img\r\nDone\r\n\r\nCreating partition image: \/home\/xen\/domains\/webserver.localhost\/disk.img\r\nDone\r\n\r\nCreating ext3 filesystem on \/home\/xen\/domains\/webserver.localhost\/disk.img\r\nDone\r\nInstallation method: debootstrap\r\nDone\r\n\r\nRunning hooks\r\nDone\r\n\r\nNo role scripts were specified.  Skipping\r\n\r\nCreating Xen configuration file\r\nDone\r\nSetting up root password\r\nEnter new UNIX password:\r\nRetype new UNIX password:\r\npasswd: password updated successfully\r\nAll done\r\n\r\n\r\nLogfile produced at:\r\n         \/var\/log\/xen-tools\/webserver.localhost.log\r\n<\/pre>\n<p>Se habran creado los ficheros necesarios en &#8216;\/home\/xen&#8217; y la configuraci\u00f3n de la m\u00e1quina se encuentra en &#8216;\/etc\/xen\/webserver.localhost.cfg&#8217;. Debemos editarla y cambiar las cadenas &#8216;file:\/&#8217; (obsoleta en la versi\u00f3n actual de Xen):<\/p>\n<pre>\r\ndisk        = [\r\n                  'file:\/home\/xen\/domains\/webserver.localhost\/swap.img,hda1,w',\r\n                  'file:\/home\/xen\/domains\/webserver.localhost\/disk.img,hda2,w',\r\n              ]\r\n<\/pre>\n<p>Por:<\/p>\n<pre>\r\ndisk        = [\r\n                  'tap:aio:\/home\/xen\/domains\/webserver.localhost\/swap.img,hda1,w',\r\n                  'tap:aio:\/home\/xen\/domains\/webserver.localhost\/disk.img,hda2,w',\r\n              ]\r\n<\/pre>\n<p>En ese mismo fichero, en caso de que tengamos un ordenador con varias CPUs o varios cores, podemos habilitar la m\u00e1quina virtual para que use ambos a\u00f1adiendo lo siguiente al mismo fichero &#8216;\/etc\/xen\/webserver.localhost.cfg&#8217;:<\/p>\n<pre>\r\nvcpus       = '2'\r\n<\/pre>\n<p>Por defecto Xen viene configurado en modo bridge, como probablemente nuestro proveedor de Internet \u00fanicamente nos proporcione una IP, deberiamos cambiarlo a modo NAT. Sino, en el ejemplo anterior, cuando arranquemos la m\u00e1quina virtual Xen intentar\u00e1 asignar la IP 192.168.22.101 a eth0 y probablemente perdamos la conexi\u00f3n remota si estamos por SSH. Para realizar el cambio editamos &#8216;\/etc\/xen\/xend-config.sxp&#8217; y comentamos:<\/p>\n<pre>\r\n# To bridge network traffic, like this:\r\n#\r\n# dom0: ----------------- bridge -> real eth0 -> the network\r\n#                            |\r\n# domU: fake eth0 -> vifN.0 -+\r\n# [...]\r\n#(network-script network-bridge)\r\n#(vif-script vif-bridge)\r\n<\/pre>\n<p>Para despu\u00e9s descomentar:<\/p>\n<pre>\r\n## Use the following if network traffic is routed with NAT, as an alternative\r\n# to the settings for bridged networking given above.\r\n(network-script network-nat)\r\n(vif-script     vif-nat)\r\n<\/pre>\n<p>Adem\u00e1s es recomendable deshabilitar la relocaci\u00f3n de m\u00e1quinas virtuales: &#8216;(xend-relocation-server no)&#8217;<\/p>\n<p>A continuaci\u00f3n ya podemos arrancar la m\u00e1quina:<\/p>\n<pre>\r\nxm create \/etc\/xen\/webserver.localhost.cfg\r\n<\/pre>\n<p>Para conectarse a la m\u00e1quina:<\/p>\n<pre>\r\nxm console webserver.localhost\r\n<\/pre>\n<p>Si quisieramos salir de ella basta con pulsar CTRL y &#8216;+&#8217;. Para parar o destruir (como si fuese un power off) la m\u00e1quina:<\/p>\n<pre>\r\nxm shutdown webserver.localhost\r\nxm destroy webserver.localhost\r\n<\/pre>\n<p>Para listar las m\u00e1quinas activas:<\/p>\n<pre>\r\nxm list\r\n<\/pre>\n<p>M\u00e1s opciones en &#8216;xm help&#8217;.<\/p>\n<p>Si quisiesemos a\u00f1adir m\u00e1s discos duros virtuales, podemos crearlos mediante:<\/p>\n<pre>\r\ndd if=\/dev\/zero of=extra.img oflag=direct bs=1M seek=153600 count=1\r\nmke2fs -j -O dir_index extra.img\r\n<\/pre>\n<p>Esto generar\u00e1 el fichero extra.img con capacidad para 150 GB, formateado con ext3. Para activarlo en nuestra m\u00e1quina virtual debemos editar &#8216;\/etc\/xen\/webserver.localhost.cfg&#8217;.<\/p>\n<p>Finalmente, para que la m\u00e1quina virtual arranque autom\u00e1ticamente al iniciar el sistema:<\/p>\n<pre>\r\nln -s \/etc\/xen\/webserver.localhost.cfg \/etc\/xen\/auto\r\n<\/pre>\n<p>M\u00e1s informaci\u00f3n en <a href=\"http:\/\/linuxsilo.net\/articles\/xen.htm\">Virtualizaci\u00f3n con Xen<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Veamos como podemos configurar un servidor Ubuntu como plataforma de virtualizaci\u00f3n 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\u00f3n de grub sean correctas en &#8216;\/boot\/grub\/menu.lst&#8217; y que el kernel con soporte Xen es el que arranca &hellip; <a href=\"https:\/\/www.marblestation.com\/?p=677\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Servidor Ubuntu con soporte de virtualizaci\u00f3n Xen<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,6],"tags":[],"class_list":["post-677","post","type-post","status-publish","format-standard","hentry","category-espanyol","category-tecnologia"],"_links":{"self":[{"href":"https:\/\/www.marblestation.com\/index.php?rest_route=\/wp\/v2\/posts\/677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.marblestation.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.marblestation.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.marblestation.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.marblestation.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=677"}],"version-history":[{"count":1,"href":"https:\/\/www.marblestation.com\/index.php?rest_route=\/wp\/v2\/posts\/677\/revisions"}],"predecessor-version":[{"id":1233,"href":"https:\/\/www.marblestation.com\/index.php?rest_route=\/wp\/v2\/posts\/677\/revisions\/1233"}],"wp:attachment":[{"href":"https:\/\/www.marblestation.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.marblestation.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.marblestation.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}