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

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.

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.

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 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 thesudo cp /vagrant/java.sh /etc/profile.d/java.shcommand to copy the file.

If you want to use VI, just typesudo vi /etc/profile.d/java.shand 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 commandsexport JAVA_HOME=/usr/java/jdk1.8.0_121export PATH=$PATH:/usr/java/jdk1.8.0_121/binjava

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

# reload the profilesource /etc/profile.d/java.sh

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 boxvagrant 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.

Steps

Outcome

Conclusion

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.

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.