Creating a Wildfly cluster for load-balancing in Linux

In our earlier tutorial, we have learned to install wildfly 10.1.0. in this tutorial, we will learn to create a load-balancing wildfly cluster. We will be using wildfly verison 10.1.0, which is the latest wildfly version at the time of writing this tutorial. Wildfly supports clustering out of the box & we need not install any special services/packages to get wildfly cluster working.

Clustering refers to a number of applications running simultaneously & working together to create an application that provides increased scalablity, reliability with increased performance. We can create cluster of application that can be Horizontal scalable (for handling higher load), or we can create cluster that are highly available or we can create cluster to load balance the load we receive on our application.

 

Pre-requisite

We need to have wildfly 10.1.0 on our machine. If you don’t have wildfly installed, download the package from http://download.jboss.org/wildfly/10.1.0.Final/wildfly-10.1.0.Final.zip.

(Recommended Read: Step by Step guide for Wildfly 10 (10.1.0) installation )

 

Configuration

Now let’s start with the configuration part for the wildfly clustering. Open the folder with the wildfly installed, in our case ‘/data/wildfly-10.1.0.Final’ . We need to create a folder with the name ‘standalone2’

$ cd /data/wildfly-10.1.0.Final
$ mkdir standalone2

& copy the data from ‘standalone’ directory to ‘standalone2’ directory,

$ cp -rv standalone/* standalone2/

Next we will rename the folder ‘standalone’ to ‘standalone1’

$ mv standalone standalone1

We now will create two separate scripts to start the instances with some addiational parameters. Goto ‘bin’ directory under ‘wildfly-10.1.0.Final’ directory & create filenamed ‘script1.sh’,

$ vi script1.sh

& add the following content to it,

#!/bin/sh
./standalone.sh -Djboss.server.base.dir=/data/wildfly-10.1.0.Final/standalone1 -Djboss.node.name=node0

here, standalone.sh is the script to start the wildfly instance,

-Djboss.server.base.dir=/data/wildfly-10.1.0.Final/standalone1, is the location with all the instance configuration & deployed packages,
-Djboss.node.name=node, the name given to the instance.

Similarly, we will create another file by the name ‘script2.sh’ & add the following line to it,

$ vi script2.sh

#!/bin/sh
./standalone.sh -Djboss.server.base.dir=/data/wildfly-10.1.0.Final/standalone2 -Djboss.node.name=node1 -Djboss.socket.binding.port-offset=100

All the parameters are same except for the -Djboss.socket.binding.port-offset=100, which adds 100 to the port numbers of the first instance i.e. if instance 1 is working on 8080, this instance will work on 8180. This is done to avoid port clashing & so that our both instances can work independently.

Now add the execute permissions to both the script files,

$ chmod +x script1.sh
$ chmod +x script2.sh

That’s it now, we have our cluster ready. Similarly, we can create as many as instances necessary. To start the instances , run the corresponding script i.e. ‘script1.sh’/’script2.sh’ or both the scripts. We can now use our mod_jk module enabled httpd server with load-balancing working in the background for the wildfly instances.

If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter | Google Plus

Become a Supporter – Make a contribution via PayPal

[paypal_donation_button align=”left” border=”1″]

Linux TechLab is thankful for your continued support.

Shusain

Passionate about Linux & open source. Loves to learn, read & write about Linux as well as new technologies.

You may also like...

Leave a Reply