Install Oracle VirtualBox And Manage It Using phpVirtualBox On CentOS 7 Headless Server
We, all, knew how to install Oracle VirtualBox on CentOS 6.x and CentOS 7.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.x and CentOS 7.x minimal servers.
Here is my test box details:
Preparing CentOS server
Before installing VirtualBox, we have to do a couple of tasks.
First of all, update your server.
Create a separate normal user (Ex. sk_vuser) for installing oracle virtualbox.
Log out, and log in back to that user.
Change to root user privileges, by using the following command:
Now, install the following prerequisites that are needed by oracle VirtualBox.
Reboot your server once to take effect all the changes.
Installing VirtualBox
Go to the /etc/yum.repos.d/ directory:
Add the latest oracle virtualbox repository to your CentOS server. You can download the oracle virtualbox latest repository from here.
Add the virtualbox public key:
Now, update the repository and install latest oracle virtualbox version.
After installing virtualbox, add the virtualbox user sk_vuser to the vboxusers group.
Now, run the following command to check if virtualbox kernel modules are loaded or not.
In CentOS 7.x:
In CentOS 6.x:
Sample output:
If it, not loaded, run the following command to load them:
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.
Then, Install Extension pack as shown below.
Sample output:
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.
Create and manage VMs from command line
First, let us create a Ubuntu 14.04 server VM with 512MB RAM and 8GB virtual hdd.
To do that, run:
Sample output:
Next, assign the RAM size and network card mode(Bridge or NAT).
Assign virtual hard drive size.
Sample Output:
Add Storage controller:
Attach the Virtual hard drive file(vdi) to the storage controller using command:
Now, Assign the Ubuntu ISO media using command:
That’s it. The new VM has been created.
To know about VBoxManage command, run:
Or, refer the Official guide.
Now, start the VM using command:
To stop a running VM, enter the following command:
Similarly we can pause a VM, using command:
To reset a VM, enter:
To learn more about VBoxHeadless options, run:
Sample output:
For more details, refer the official manual.
Creating and managing might be bit difficult and time consuming method for some lazy administrators. If you are one of them, there is another way to create and manage VMs in the headless from a Remote system web browser using a tool called “phpvirtualbox”.
You can use Oracle VirtualBox GUI client called “phpvirtualbox” to easily create and manage virtual machines via a web browser from 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 links.
Additionally, install php-soap extension which is required by phpVirtualBox to work well.
Restart the web server to take effect the changes.
In CentOS 7.x:
In CentOS 6.x:
Now, Download the latest version from the phpVirtualBox official site.
Extract the zip file using the following command:
Move the extracted folder to your apache root folder.
Configure phpVirtualBox
Edit phpVirtualBox config.php file:
Change the username/password for system user that runs VirtualBox. In our case, the username/password is sk_vuser/centos.
Save and close the file.
Create a file called /etc/default/virtualbox:
Append the following line:
Now, start vboxweb-service, and make it to start automatically on every reboot.
I don’t want to messing around with iptables and SElinux. So, I simply disabled them both.
In CentOS 7.x:
In CentOS 6.x:
Disable SELinux:
Set 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 environments, 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.
Now, you’ll be redirected to the phpVirtualBox main dashboard.
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.
Set the Memory size for the virtual machine.
Select “Create a virtual hard drive now” option.
Select hard drive file type.
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).
Enter the size of the virtual hdd.
That’s it. The virtual machine has been created. Start installing the OS, and use the virtual machine.
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!
No comments:
Post a Comment