Jumat, 13 Maret 2015

phpVirtualBox On A CentOS

Install Oracle VirtualBox And Manage It Using phpVirtualBox On A CentOS Headless Server

Please shareShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditDigg thisShare on StumbleUpon
We, all, know how to install Oracle VirtualBox on CentOS 6.x GUI based systems. But, what about on CentOS minimal server which is not having any GUI desktop environment? No worries, VirtualBox has a tool called “VBoxHeadless”. The VBoxHeadless can help you to create and manage Virtual machines without the need of VirtualBox GUI.
In this tutorial, let us see how to install and configure Oracle VirtualBox on CentOS 6.5 minimal server. Here is my test box details:
OS : CentOS 6.5 Server Minimal Installation (No GUI)
IP Address : 192.168.1.200/24

Preparing CentOS server

Before installing VirtualBox, we have to do a couple of tasks. First of all, update your server.
yum update -y
Create a separate normal user (Ex. sk_vuser) for installing oracle virtualbox.
useradd sk_vuser
passwd sk_vuser
Log out, and log in back to that user.
Change to root user privileges, by using the following command:
su
Now, install the following prerequisites which will need by oracle VirtualBox.
yum groupinstall 'Development Tools' 
yum install SDL kernel-devel kernel-headers dkms -y
Reboot your server once to take effect all the changes.

Installing VirtualBox

Go to the /etc/yum.repos.d/ directory:
cd /etc/yum.repos.d/
Add the latest oracle virtualbox repository to your CentOS server. You can download the oracle virtualbox latest repository from here.
wget http://download.virtualbox.org/virtualbox/rpm/el/virtualbox.repo
Add the virtualbox public key:
wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc
rpm --import oracle_vbox.asc
Now, update the repository and install latest oracle virtualbox version.
yum update
yum install VirtualBox-4.3 -y
After installing virtualbox, add the virtualbox user sk_vuser to the vboxusers group.
usermod -G vboxusers sk_vuser
Now, run the following command to check if virtualbox kernel modules are loaded or not.
/etc/init.d/vboxdrv status
Sample output:
VirtualBox kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) are loaded.
If it, not loaded, run the following command to load them:
/etc/init.d/vboxdrv setup

Install Oracle VirtualBox Extension pack

Starting with VirtualBox 4.0, we should install Extension pack that will help us to manage and connect our remote guest consoles via web interface. This Extension pack provides the following functionalities to the VirtualBox guests.
  • The virtual USB 2.0 (EHCI) device
  • VirtualBox Remote Desktop Protocol (VRDP) support
  • Host webcam passthrough
  • Intel PXE boot ROM
  • Experimental support for PCI passthrough on Linux hosts
VirtualBox extension pack should be same version as VirtualBox base package. Download Extension pack for VirtualBox 4.3 from here.
wget http://download.virtualbox.org/virtualbox/4.3.12/Oracle_VM_VirtualBox_Extension_Pack-4.3.12-93733.vbox-extpack
Then, Install Extension pack as shown below.
VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.3.12-93733.vbox-extpack
That’s it Oracle VirtualBox and Extension pack have been installed successfully on our CentOS 6.5 server. Start using Oracle VirtualBox on your CentOS headless server. For creating and managing virtual machines from the command line, refer the official manual.
Instead, you can use Oracle VirtualBox GUI client called “phpvirtualbox”. to easily create and manage virtual machines via web browser of any remote desktop system.

What is phpVirtualBox?

phpVirtualBox is an open source, web-based client written using PHP. It can be used to manage and administer Oracle VirtualBox headless instances.

Install phpVirtualBox

Before installing phpVirtualBox, we have to install Apache web server and PHP. To install Apache, PHP refer the following link.
Additionally, install php-soap extension which is required by phpVirtualBox to work well.
yum install php-soap
Restart the web server to take effect the changes.
service httpd restart
Now, Download the latest version from the phpVirtualBox official site.
wget http://sourceforge.net/projects/phpvirtualbox/files/phpvirtualbox-4.3-1.zip
Extract the zip file using the following command:
unzip phpvirtualbox-4.3-1.zip
Move the extracted folder to your apache root folder.
mv phpvirtualbox-4.3-1 /var/www/html/phpvirtualbox

Configure phpVirtualBox

Edit phpVirtualBox config.php file:
cp /var/www/html/phpvirtualbox/config.php-example /var/www/html/phpvirtualbox/config.php
nano /var/www/html/phpvirtualbox/config.php
Change the username/password for system user that runs VirtualBox. In our case, the username/password is sk_vuser/centos.
[...]
var $username = 'sk_vuser';
var $password = 'centos';
[...]
Save and close the file.
Create a file called /etc/default/virtualbox:
nano /etc/default/virtualbox
Append the following line:
VBOXWEB_USER=sk_vuser
Now, start vboxweb-service, and make it to start automatically on every reboot.
/etc/init.d/vboxweb-service start
chkconfig vboxweb-service on
I don’t want to messing around with iptables and SElinux. So, I simply disabled them both.
service iptables stop
chkconfig iptables off
Disable SELinux:
vi /etc/sysconfig/selinux
Set SELINUX=disabled.
[...]
SELINUX=disabled
[...]
Reboot your system once to take effect all the changes.

Access phpVirtualBox Web console

Now, go to any client systems that has installed with GUI desktop environements, and try to access the URL http://ip-address-of-virtualbox-headless-server/phpvirtualbox from the web browser.
Now, try again the same URL mentioned above. The following screen should appear. Enter the username/password.
The default username/password is admin/admin.
phpVirtualBox - VirtualBox Web Console - Mozilla Firefox_001
Now, you’ll be redirected to the phpVirtualBox main dashboard.
phpVirtualBox - VirtualBox Web Console - Mozilla Firefox_003
From here, you can create, modify, delete, and manage virtual machines.

Creating sample Virtual Machine

Let us create a sample virtual machine to install Ubuntu 14.04.
Click on the New button on the top left corner. Enter the Virtual machine name.
phpVirtualBox - VirtualBox Web Console - Mozilla Firefox_005
Set the Memory size for the virtual machine.
phpVirtualBox - VirtualBox Web Console - Mozilla Firefox_006
Select “Create a virtual hard drive now” option.
phpVirtualBox - VirtualBox Web Console - Mozilla Firefox_007
Select hard drive file type.
phpVirtualBox - VirtualBox Web Console - Mozilla Firefox_008
Choose whether the new virtual hard drive file should grow as it is used (dynamically allocated) or if it should be created at its maximum size (fixed size).
phpVirtualBox - VirtualBox Web Console - Mozilla Firefox_009
Enter the size of the virtual hdd.
phpVirtualBox - VirtualBox Web Console - Mozilla Firefox_010
That’s it. The virtual machine has been created. Start installing the OS, and use the virtual machine.
phpVirtualBox - VirtualBox Web Console - Mozilla Firefox_012
phpVirtualBox tool will definitely help the system administrators who have only headless CentOS server, and also the installation is not that difficult. So, You can easily run virtual machines as many as your hardware supports from your headless CentOS server.
References:
Cheers

sbr:http://www.unixmen.com/install-oracle-virtualbox-manage-using-phpvirtualbox-centos-headless-server/

Tidak ada komentar:

Posting Komentar