VBoxHeadless – Running VMs with VirtualBox 4x and phpVirtualbox on CentOS6.2


Install and configure a budget Virtual Machine host server which is ideal for testing environments or a home server setup. By utilising these excellent Open Source software packages we can quickly build this in no time!

To start with you need a base host server running CentOS 6.2 (minimal install no gui) ISO is available from http://www.centos.org

 

 

 

Build and configuration steps/process:

1. Add rpmforge to enable 3rd party packages such as htop – reference URLs: http://www.centos.org/modules/newbb/viewtopic.php?topic_id=14408&forum=47

Installing RPMforge:
http://wiki.centos.org/AdditionalResources/Repositories/RPMForge?action=show&redirect=Repositories%2FRPMForge

Process:

 wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm 

Install DAG’s GPG key

 rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt 

Verify the package you have downloaded

 rpm -K rpmforge-release-0.5.2-2.el6.rf.*.rpm 

Install the package

 rpm -i rpmforge-release-0.5.2-2.el6.rf.*.rpm 

If you are going to enable 3rd party repositories then it is highly recommended that you also install and configure the priorities plugin to manage them. http://wiki.centos.org/PackageManagement/Yum/Priorities

 yum install yum-plugin-priorities 

Then try to install something like htop to verify the additional repos have been setup, htop is handy anyway!

 yum install htop 

Finally install dependencies for Virtualbox 4 with Development Tools and DKMS.

yum groupinstall 'Development Tools'
yum install dkms

2. Enable the VirtualBox CentOS repository

cd /etc/yum.repos.d/
wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo

Run yum update to get everything up to date and have the dependencies resolved. (reboot if needed kernel updates)

yum update

Install VirtualBox 4

 yum install VirtualBox-4.1 

3. Add user(s) to the vboxusers group

usermod -a -G vboxusers keith
usermod -a -G vboxusers root

Set ownership and permissions on our VM datastore directories, on my server I’ve setup 2 datastore on seperate hard disk drives and paritions, vbox-vms and vbox-vms2.

Set the owner to root and vboxusers group:

chown -R root:vboxusers /vbox-vms
chown -R root:vboxusers /vbox-vms2

Set the permissions to 774:

chmod -R 774 /vbox-vms
chmod -R 774 /vbox-vms2

Login as normal user keith
Lets first set the default “Machinefolder” area to /vbox-vms by default Virtualbox will create/import or store all VM data in your Linux home folder e.g. /home/keith/Virtual Box.

The command for this is setproperty machinefolder path – in our case we want /vbox-vms

 VBoxManage setproperty machinefolder /vbox-vms/ 

Check this has been set with:

 VBoxManage list systemproperties 

4. Create VM from the command line using VBoxManage, in this case we will create Ubuntu Server 11.10 and call it Jupiter.

VBoxManage createvm --name "Jupiter" --register --basefolder /vbox-vms/

VBoxManage modifyvm "Jupiter" --memory 912 --acpi on --boot1 dvd --nic1 bridged --bridgeadapter1 eth0

VBoxManage createhd --filename /vbox-vms/Jupiter/Jupiter.vdi --size 10000 --format VMDK

VBoxManage storagectl "Jupiter" --name "IDE Controller" --add ide

VBoxManage storageattach "Jupiter" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium /vbox-vms/Jupiter/Jupiter.vdi

VBoxManage storageattach "Jupiter" --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium /isos/ubuntu-11.10-server-amd64.iso

Download and install the VBoxManage Extensions Pack

wget http://download.virtualbox.org/virtualbox/4.1.12/Oracle_VM_VirtualBox_Extension_Pack-4.1.12-77245.vbox-extpack
VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.1.12-77245.vbox-extpack

Ensure the firewall on the host has port 3389 open for remote management.
Either adjust your IPTABLES rules or on CentOS/RedHat based systems run:

 system-config-firewall-tui 

Start the new VM Jupiter:

 VBoxHeadless --startvm "Jupiter" 

*Note* if you don’t see a message “VRDE server is listening on port 3389” then run:

 VBoxManage modifyvm "Jupiter" --vrde on 

To Power off the VM use:

 VBoxManage controlvm "Jupiter" poweroff 

To Reset VM:

 VBoxManage controlvm "Jupiter" reset 

5. Importing an Existing VM

Import the VM from an OVA file works best so try to export that from the source or downloaded appliances usually have OVA OVF formats.

To import a VM named Sealion.ova

 VBoxManage import Sealion.ova 

 

::::>>>> phpVirtualBox Install and configure <<<<::::

6. Install and configure phpVirtualBox

Install Apache and PHP with php soap:

 yum install httpd php php-soap 

Add user vbox:

 useradd vbox 

Set password

 passwd vbox 

Add user vbox to the vbox users group

 usermod -G vboxusers vbox 

Get the latest phpvirtualbox package file

 wget http://phpvirtualbox.googlecode.com/files/phpvirtualbox-4.1-7.zip 

Unzip the file

 unzip phpvirtualbox-4.1-7.zip 

Create vbox directory in /var/www/html

 mkdir /var/www/html/vbox 

Copy the phpvirtualbox-4.1-7 directory over to /var/www/html/vbox

 cp -R phpvirtualbox-*/* /var/www/html/vbox/ 

Create the config file for soap web service

 vim /etc/default/virtualbox 

Add this text to the file:

 VBOXWEB_USER=vbox 

Copy the config.php-example file to a config.php file in the /var/www/html/vbox directory

cd /var/www/html/vbox
cp config.php-example config.php

Edit the config file and enter the correct username and password for system user vbox and uncomment section for host ip console connections e.g. var $consoleHost = ‘172.16.16.31’;

 vim /var/www/html/vbox/config.php 

Enable SELinux exception for the vboxweb-service, this is a better option that disabling SELinux.
To do this we need to install semanage tools:

 yum install policycoreutils-python 

Now add the exception:

 semanage port -a -t http_port_t -p tcp 18083 

VirtualBox’s web service port (default) is 18083 and the above command will allow it to be accessible in an HTTP context.

Start the vboxweb service and configure to start automatically

service vboxweb-service start
chkconfig vboxweb-service on

Logon to the phpVirtualBox web interface:
http://tigershark.winnet.kdp/vbox
Username and password is admin admin
Change the password and add/create or import virtual machines.

Create import or add Virtual guest machines from the console.
Ensure remote console is enabled and change the port numbers on your guests if you want to RDP to multiple running guests at the same time i.e. VM1 is default 3389 VM2 is 3390 VM3 is 3391 and so forth.