Sometimes you just want to create a quick environment for a WSO2 test, for instance on your own computer running Virtual Box. From experience, we used VMs for WSO2 training purposes, we know that VM’s quickly can attribute to about 1 Terabyte of data storage.
In this blog, we show you how to create a WSO2 ESB setup on Centos 7 that you can spawn at any time. This is an approach that shows you how to work with Vagrant in a very easy way, a primer so to say. It is also a starting point for you to discover Vagrant.
When you look at Vagrant there are certainly other ways that will work better in the situation where you reuse Vagrant Boxes. Especially creating a box based on an existing Vagrant Box with for instance Java, Ant, Maven and perhaps even WSO2 products is certainly a better approach that will also cut the creation and spawning time.
With some reading you will be able to take this primer and create your own Vagrantfiles perhaps even with Ansible or any of the other supported tools.
The steps we will take are:
- Download Vagrant
- Vagrant initialization
- Choosing a box
- Modifying a box
- Provision of a box
- Starting
Downloading Vagrant
The first step is of course downloading Vagrant. This download is reasonably small and we chose the MSI package to install on Windows. Just click on the download link and click the downloaded installer.
We will leave the installation out of this blog. If you have any issues, please look at the documentation (https://www.vagrantup.com/). We also need Virtual box in this WSO2TORIAL, so please also download Virtual box (https://www.virtualbox.org/) for the OS that you are using.
Also, while you are at it, install the latest version of VirtualBox to work with Vagrant. Older versions have been known to have issues.
This (VirtualBox) is by the way a very handy environment to create virtual machines, even withoutVagrant, albeit that Vagrant makes it incredibly simple as you will see from this blog.
Step one: Vagrant Init
Open a CMD window (or terminal session) and create a new sub-directory, e.g. vagrantWSO2
When we go to that directory and type in: vagrant init among other things a Vagrantfile is created.
This file will be parsed when we enter vagrant up and spawn our first vagrant environment.
But we want more control over the environment so we need to change the Vagrantfile.
Step two: Choosing a box
We are going to add the centos/7 box to the setup. We will do this by changing the config.vm.box parameter. The boxes can be found at this link
(https://atlas.hashicorp.com/boxes/search?_ga=1.1183925.563187651.1490347722). We select the centos/7 box and change the parameter accordingly
Config.vm.box = ”centos/7”
We bring our environment up with”
vagrant up Bringing machine 'default' up with 'virtualbox' provider...
|
C:UsersRobvagrantWSO2>
There are a number of relevant messages in the response from vagrant. First of all the name of the VM that is created. We can set this in the Vagrantfile with this command:
config.vm.provider "virtualbox" do |v|
v.name = "VB_WSO2TORIAL"
end
Furthermore, the SSH address is indicated as well. With the vagrant ssh command we get access to the VM from our commandline window. But we will do that a little later on.
Another setting we need to consider is the access to the management console of the WSO2 ESB. As you might know, this is accessed using https protocol on port 9443.
config.vm.network "forwarded_port", guest: 9443, host: 9443, host_ip: "127.0.0.1", id: 'ssh'
While we are at it, let’s also give a private IP address to the VM:
config.vm.network "private_network", ip: "192.168.33.10"
The penultimate line indicates the rsync of the vagrantWSO2 directory directly on the VM. Any file on the host side will be transferred to the VM. This not only allows to move files but also provision the VM in combination with shell scripts (among other ways). We need however, Rsync and OpenSSH to be installed. Consider installing Cygwin (https://www.cygwin.com/). and add Rsynce and OpenSSH to the installation.
In this blog we will move the WSO2 ESB zip to the VM and unpack it. A provisioning script will install wget and download Java and make all the settings needed like Java Home etc.
We copy the ESB zip to the vagrantWSO2 directory and, to trigger the synchronization, vagrant rsync.
After that we connect using SSH to the box using the command
vagrant ssh
As you can see the zipfile is in the VM. Since unzip is not installed by default on Centos/7 we add this to the box using
sudo yum -y install unzip
This installs unzip automatically (-y). This can also be included in the provisioning file, making it completely automatic.
Step 3 Configuring Virtualbox
Since we want to run WSO2 ESB we are going to give it ample memory and two CPUs. This is done editing the VagrantFile. You can also include the v.memory and v.cpus parameter with the v.name parameter.
config.vm.provider “virtualbox” do |v|v.memory = 1024
v.cpus = 2 end |
The easiest way to modify the Vagrantfile is before we call the “vagrant up” command. When the file is changed after the “vagrant up”, you need at least to restart the guest OS with “vagrant halt” + “vagrant up”, or “vagrant halt” + “vagrant reload”. That way Vagrant will apply your changes.
Step 4 Provisioning the environment
We want to download Oracle JDK 1.8 and install it on the Virtual Machine. In this case we have created a file called provision.sh that is included in the Vagrant directory of the host machine. In the Vagrantfile we tell vagrant to start the provision.sh script when getting the vagrant environment up.
config.vm.provision :shell, path: “provision.sh” |
The file can contain as many commands as you like, however keep in mind that you can also create your own box with the files that you are now adding through provisioning.
We want to have the WSO2 ESB running on our VM so what we need is a setup like this:
# provision vagrant
# install wget
sudo yum -y install wget
sudo yum -y install unzip
#download JAVA SDK 1.8
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"
# untar Java in /usr/java
sudo mkdir /usr/java
sudo tar -xzf jdk-8u121-linux-x64.tar.gz -C /usr/java
# set Java Home
export JAVA_HOME=/usr/java/jdk1.8.0_121
export PATH=$PATH:/usr/java/jdk1.8.0_121/bin/
#the WSO2 ESB 5.0.0 is included in the vagrant environment
sudo unzip /vagrant/wso2esb-5.0.0.zip -d /opt
sh /opt/wso2esb-5.0.0/bin/wso2server.sh
The first two sudo YUM commands are to install WGET and UNZIP to retrieve and unzip the files. The -y makes it automatic (answering yes to any questions from the install).
The WGET command retrieves the JDK from oracle circumventing the accept license button. The sudo TAR command installs Java at /usr/java and the two export commands make sure that we can use java in conjunction with WSO2. This is a quick and dirty solution that has a dependency on Oracle but for now it works. If it fails in the future, consider to use the same procedure as the WSO2 ESB for installation.
Subsequently we unzip the ESB to /opt and start it using the wso2server.sh script.
After some time you will see the following:
Your WSO2 ESB is now up and running. In a next blog we are going to access the ESB from the browser.
Caveat emptor
As said, this setup show a quick way to create an environment use vagrant and WSO2. In the next blog we are going to look into streamlining the process a bit that will result in less time to deploy.
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.