Vagrant and WSO2, making it work - WSO2Tutorial

Posted by Rob Blaauboer on 18 May, 2017
Rob Blaauboer

WSO2Torial-witruimte.pngIn 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.

md blog

cd blog

vagrant init centos/7

Vagrant and WSO2 on Windows

After these commands you will end up with a Vagrantfile in the directory blog and you could start up vagrant using the vagrant up command.

Vagrant and WSO2 - Vagrant Up command

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:

Vagrant and WSO2 - Command Prompt window Vagrant

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.

Vagrant and WSO2 - Vagrant SSH-1

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:

  1. install wget
  2. download (wget) the Java JDK
  3. create the directory where we want to install Java
  4. unpack the JDK into that directory
  5. create a in /etc/profile.d/
  6. reload the profile
  7. 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:

Vagrant and WSO2 - wget vagrant ssh

After wget we can actally download the JDK from Oracle. We use the command below:

#download java

sudo wget --no-cookies --no-check-certificate --header "Cookie:; oraclelicense=accept-securebackup-cookie"

Vagrant and WSO2 - Download JDK from Oracle

As you can see, the file has been downloaded. Now we need to install it.

# install java in /usr/java
sudo mkdir /usr/java
# untar
sudo tar -xzf jdk-8u121-linux-x64.tar.gz -C /usr/java

Vagrant and WSO2 - Vagrant ssh java install

Vagrant and WSO2 - Vagrant ssh

Now we need to create a file in /etc/profile.d/. You can do this using VI editor in the VM or use the same procedure as above by creating a 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.

Vagrant and WSO2 - Vagrant rsync

You can use the sudo cp /vagrant/ /etc/profile.d/ command to copy the file.

If you want to use VI, just type sudo vi /etc/profile.d/ 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 in /etc/profile.d/ with these commands
export JAVA_HOME=/usr/java/jdk1.8.0_121
export PATH=$PATH:/usr/java/jdk1.8.0_121/binjava

To test everything you can use source /etc/profile.d/ to reload the profile.

# reload the profile
source /etc/profile.d/

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

This command packages our centos/7 box with all the changes we just made into a new box called

Vagrant and WSO2 - Vagrant ssh

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

You have freedom to name the box, we chose c7pj as a name.

Vagrant and WSO2 - Vagrant ssh c7pj

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.


Vagrant and WSO2 - Vagrant ssh steps


Vagrant and WSO2 - Vagrant ssh 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 blog2_1491994795601_9411).

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 Tutorialswebinars or white papers for more technical information. Need support? We do deliver WSO2 Product Support, WSO2 Development SupportWSO2 Operational Support and WSO2 Training Programs. 

Check our webinars



Rob Blaauboer

Written by Rob Blaauboer

Rob is a Senior Business Consultant and Solution Architect with more than twenty years experience. In addition to his work he is an active blogger working on a number of articles on the ‘Internet of Things’ and a WSO2 ‘Getting Started with …’ series (WSO2 tutorial) in which he talks about WSO2 components and their purpose especially aimed at non technical readers. Rob is a WSO2 expert and official WSO2 trainer.