Martes Abril 23 , 2024
Text Size
   

VirtualBox por web: phpvirtualbox

Hace unos días descubrí una funcionabilidad de virtualbox (el cual era reacio a usar) que me ha encantado: la posibilidad de hacerlo accesible y totalmente funcional a traves de web, consola incluida. Lo cual lo hace una alternativa muy interesante a VMWare Server o ESXi

Para su correcto funcionamiento, debemos de seguir una serie de pasos, que incluyen por otro lado, el correcto arranque y parada de las máquinas virtuales sin gestion manual alguna, para que dependan de la máquina host

 

  1. Lo primero que debemos hacer es descargarnos el software de su web http://www.virtualbox.org/wiki/Downloads
  2. Una vez arrancado el software, necesitaremos aplicarle el extension pack (más que nada para poder usar la consola) http://download.virtualbox.org/virtualbox/4.0.4/Oracle_VM_VirtualBox_Extension_Pack-4.0.4-70112.vbox-extpack
  3. Necesitamos dar de alta en el sistema un usuario para virtualbox, pe vbox
  4. Según el sistema (aquí sólo estudiaremos Linux y MacOs) encontraremos el servicio web de VirtualBox en un lugar u otro, pero la manera de dejarlo e background será la misma (que ha sido la más estable hasta ahora
    • en MacOs deberemos crear un script que realice lo siguiente: cd /Applications/VirtualBox.app/Contents/MacOS y ./vboxwebsrv >/dev/null
    • en Linux por el contrario (no usaremos el servicio hubicado en /etc/init.d/ es inestable): /usr/bin/nohup /usr/bin/vboxwebsrv -H ipdelamaquina & (podemos incluirla en el cron del usuario vbox, tambien podemos usar el demonio que se instala)
  1. Nos descargamos phpvirtualbox de la web http://code.google.com/p/phpvirtualbox/downloads/list según nuestra versión de VirtualBox y lo colocamos en una máquina con servidor web y php. Debemos de copiar el archivo config.php-example con el nombre config.php y dentro de el tocar los parámetros var $username = 'vbox' y var $password = 'pass'; cambiando el user por el que hemos creado y la pass por la que hemos puesto
  2. Entramos en la url de nuestra máquina con servidor web http://IP/carpeta_de_phpvirtualbox/ el usuario y la contraseña es admin admin por defecto, pero podremos cambiarla dentro de la web y de igual manera crear usuarios
  3. Si queremos que las máquinas virtuales arranquen de forma automática al arranque del sistema y se paren de igual manera, podemos generar dos scripts  o bien meterlos en el cron de la siguiente forma
    • si queremos arrancar la máquina: su - vbox --command="VBoxManage startvm nombredelamaquina --type headless"
    • si queremos parar la maquina: su - vbox --command="VBoxManage controlvm nombredelamaquina acpipowerbutton"

Esto es todo, cualquier duda, como siempre, en los comentarios :) espero que sirva de ayuda

ACTUALIZACION -------------------------------------------------------------------------------------------------------------------------------------------------------

Si el servicio en tu sistema LINUX fuera estable, podéis configurarlo de la siguiente manera

fuente: http://code.google.com/p/phpvirtualbox/wiki/vboxwebServiceConfigLinux

In order for vboxweb-service start vboxwebsrv, the file /etc/default/virtualbox must exist with correct settings. If this file does not exist on your system, create it now. This file has the format:

SETTING1=value

SETTING2=value

The following settings are available for use in this file:

 

Setting

Description

VBOXWEB_USER

The user as which vboxwebsrv will run.

VBOXWEB_HOST

The host to bind to (localhost).

VBOXWEB_PORT

The port to bind to (18083).

VBOXWEB_TIMEOUT

Session timeout in seconds; 0 = disable timeouts (300).

VBOXWEB_CHECK_INTERVAL

Frequency of timeout checks in seconds (5).

VBOXWEB_THREADS

Maximum number of worker threads to run in parallel (100).

VBOXWEB_KEEPALIVE

Maximum number of requests before a socket will be closed (100).

VBOXWEB_LOGFILE

Name of file to write log to (no file).

INSTALL_DIR

The location of the vboxwebsrv binary (/usr/lib/virtualbox).

 

At a minimum, VBOXWEB_USER must be set. Some may need to set VBOXWEB_HOST as well.

VBOXWEB_USER should be set to the user that runs VirtualBox virtual machines on your system. If more than one user runs virtual machines, you will have to pick one (multiple instances are possible, but beyond the scope of this document).

VBOXWEB_HOST should be set if phpVirtualBox (your web server) is not running on the same host as vboxwebsrv. If phpVirtualBox must communicate with vboxwebsrv across a network, this must be set to an IP address reachable by your web server. If your web server and vboxwebsrv are running on the same host, you may exclude this setting.

Your /etc/default/virtualbox may look like this:

VBOXWEB_USER=vbox

.. or if your web server and vboxwebsrv are on NOT the same host:

VBOXWEB_USER=vbox

VBOXWEB_HOST=192.168.0.4

Note that these values are just examples. The user that runs virtual machines on your system may not be named "vbox."

Once this is done, you may start and stop vboxwebsrv by running:

/etc/init.d/vboxweb-service start -or- /etc/init.d/vboxweb-service stop

as the root user on your system.

IMPORTANTE ----------------------------------------------------------------------------------------------------------------------

Si en Mac OS X obtenemos al acceder via web, el error "Error logging in to vboxwebsrv" ejecutar la siguiente sentencia como usuario normal -> VBoxManage setproperty websrvauthlibrary null

--------------------------------------------------------------------------------------------------------------------------------------------