In a previous Vagrant and WSO2 blog we created a simple and rather quick and dirty setup to show you how easy it is to spawn a WSO2 ESB running CentOS using Vagrant scripting.
The drawback is however that our setup starts from scratch everytime we do a ‘vagrant up’. Since we always need Java and a number of other tools when running WSO2 products, it makes sense to create our own ‘box’ (vagrant’s term for an operating system that it uses).
We will for now stick to Virtualbox as our provider. In a next blog we will actually show you how to use Amazon’s AWS in conjunction with vagrant.
Starting with CentOS/7
We will start with the CentOS/7 box which is a minimal install, so no Gnome or KDE desktop. Also, some files we would like to use in the box need to be added. We are talking about for instance wget and unzip which are not part of a minimal install.
Please keep in mind that Rsync and SSH are needed for Vagrant. Please take a look at our previous blog (http://.,, ) for installation instructions. Furthermore, we have the VB-guest plugin installed so we always have the latest version. You can do this with the following command:
vagrant plugin install vagrant-vbguest
We use Vagrant on Windows for this blog. Open up a command window and create the structure to work with Vagrant.
vagrant init centos/7
After these commands you will end up with a Vagrantfile in the directory blog and you could start up vagrant using the vagrant
Let’s do that now to see if it indeed works. A lot happens in the command window but after a while you will see a window like this:
We can now SSH into the VM. Let’s do that and when in the VM give the
sudo su – command to be able to install as root.
Changing the current CentOS/7 environment
As said, we are going to create a new box that will have Java JDK 1.8 installed. We could also directly install the WSO2 ESB on top of that but you can do that as a separate step if you like.
The steps we need to take are:
- install wget
- download (wget) the Java JDK
- create the directory where we want to install Java
- unpack the JDK into that directory
- create a java.sh in /etc/profile.d/
- reload the profile
- to see if all is correct echo $JAVA_HOME
In the text below we actually will give the commands so you can actually copy them to your vagrant VM. Alternatively, you can create a script (.sh) file that will run the command. Just place this script in the directory you created (e.g. the blog directory) and rsync will make sure it is available on the VM in the /vagrant directory.
# everything done for the ESB setup AWS training
#setup of wget and unzip
sudo yum -y install wget
The -y parameter allows for a silent install of wget. When done the screen will show something like:
After wget we can actally download the JDK from Oracle. We use the command below:
sudo wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.tar.gz
As you can see, the file has been downloaded. Now we need to install it.
# install java in /usr/java
sudo mkdir /usr/java
sudo tar -xzf jdk-8u121-linux-x64.tar.gz -C /usr/java
Now we need to create a file in
. You can do this using VI editor in the VM or use the same procedure as above by creating a java.sh in the blog directory and copy that to the profile.d directory.
Do not forget to set the EOL to Unix rather than Windows (choose Edit from the menu and set EOL Conversion).
If you store the file in the blog directory it will be synced to the VM. If not, exit the SSH session (using exit command) and type
vagrant rsync. This will sync the file to the /vagrant directory from where you can copy it to the right directory.
You can use the
sudo cp /vagrant/java.sh /etc/profile.d/java.sh command to copy the file.
If you want to use VI, just type
sudo vi /etc/profile.d/java.sh and make sure that you enter the export commands below. We will not give detailed instructions on VI, if you are unfamiliar with VI google for help or stick to the approach described above.
# create a java.sh in /etc/profile.d/ with these commands
To test everything you can use
source /etc/profile.d/java.sh to reload the profile.
# reload the profile
We now have everything we need to, at a later stage run the WSO2 ESB. So let’s exit our SSH session and package the changes we made into a new box.
Packing and adding
With exit we actually end the SSH session and get back to the command line of our operating system.
#vagrant make new box
vagrant package --output centos7_java.box
This command packages our centos/7 box with all the changes we just made into a new box called centos7_java.box.
Now we need to add our box to Vagrant in order to use it for a vagrant environment. We use the command
vagrant box add c7pj centos7_java.box
You have freedom to name the box, we chose c7pj as a name.
Testing the new environment
The proof of the pudding is in the eating, so the saying goes. So let us create a new directory and initialize an environment with our new box. We will not go in too much detail as the steps are the same as before. The screens shows the steps and the outcome.
We have created a new box with java preinstalled on which we can easily and quickly deploy WSO2 products. With this knowledge you can continue to build boxes like an WSO2 ESB vagrant box that you can simply spawn if you need it and that, in contrary to our first article, does not need to install everything from scratch.
This is still not a complete vagrant installation since we have other parameters that we need to set like the amount of memory for VirtualBox, the name of the VM (currently it is a timebased name like for instance
But, we are one step further and that is not bad. We will continue with Vagrant in follow-up blogs.
If you have any questions about this blogpost contact us via the comments section of this blog. View also our WSO2 Tutorials, webinars or white papers for more technical information. Need support? We do deliver WSO2 Product Support, WSO2 Development Support, WSO2 Operational Support and WSO2 Training Programs.