Application Load Balancer with Multiple Tomcat Instances

Application Load Balancer with Multiple Tomcat Instances

What is Application Load Balancer?

Application Load Balancer is a Layer 7 load balancer. It pushes traffic across multiple targets in multiple AWS Availability Zones.

How it Works?

In Application Load Balancer, if a faulty application reaches Layer 7 of Open System Interconnection (OSI) model. The Application Load Balancer will route traffic only to a healthy target within the cloud resource. Application Load Balancer also supports WebSocket for more communication with the underlying server.

Application Load Balancer inspects packets and creates access points to HTTP and HTTPS headers. It identifies the type of load and spreads it out to the target with higher efficiency based on application traffic flowing in HTTP messages. Application Load Balancer also conducts health checks on connected services on a per-port basis to evaluate a range of possible code and HTTP errors. A developer receives detailed metrics following the checks, including the health of microservices like Dockers and Containerization Services.

Application Load Balancer with Multiple Tomcat Instances

Application Load Balancer with Multiple Tomcat Instances

Configure Multiple Tomcat instances on a Single Linux Box:-

Step 1:- Download Latest Java JDK from Below URL

$sudo mkdir /opt/java/

$sudo su –

#cd /opt/java

To Download Java JDK8u131 using wget:

wget -c –header “Cookie: oraclelicense=accept-securebackup-cookie”

Step 2:- Extracting and Setting Up Java Directory

#tar -xzf jdk-8u131-linux-x64.tar.gz

# mv  jdk-8u131-linux-x64 jdk-8u131

Step 3:- Setting up Environment PATH and JAVA_HOME

Change in ~/.bashrc for particular User Environment Variable Changes

$vim ~/.bashrc

export JAVA_HOME=/opt/java/jdk-8u131

export PATH=$PATH:$JAVA_HOME/bin

To reflect these above changes in Environment Variable:-

. ~/.bashrc


For Global PATH change in /etc/bash.bashrc or /etc/bashrc

#vim /etc/bashrc

export JAVA_HOME=/opt/java/jdk-8u131

export PATH=$PATH:$JAVA_HOME/bin

. /etc/bashrc

Step 4:- Remove Existing Java Installed and Replace with New Java

#whereis java

java: /usr/bin/java /usr/lib/java /etc/java /usr/share/java /usr/share/java/jvm//jdk1.7/bin/java /usr/share/man/man1/java.1.gz

#ls -l /usr/bin/java

lrwxrwxrwx 1 root root 22 Jun 23 23:17 /usr/bin/java -> /etc/alternatives/java

#ls -l /etc/alternatives/java

lrwxrwxrwx 1 root root 26 Aug  2 06:51 /etc/alternatives/java -> /opt/jdk1.8.0_144/bin/java

#realpath /usr/bin/java


from above output we can see that /etc/alternatives/java is Symlink of /usr/share/java/jvm//jdk1.7/bin/java, So just unlink this and connect this with newly downloaded JAVA_HOME

#unlink /etc/alternatives/java

#ln -s /opt/java/jdk-8u131/bin/java /etc/alternatives/java

Now your Old Java is replaced with New Java, You can check by doing below command.

#java -version

java version “1.8.0_131”

Java(TM) SE Runtime Environment (build 1.8.0_131-b01)

Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)


Step 5:- Configure Multiple Tomcat Instances:-

step i):- Download and Extract Tomcat Instances.

$ cd /home/ec2-user

$ wget ‘’

$ tar -xzf  apache-tomcat-7.0.81.tar.gz

$ cp  apache-tomcat-7.0.81 tomcat1

$ cp  apache-tomcat-7.0.81 tomcat2

$ cp  apache-tomcat-7.0.81 tomcat3

Step ii):- Configure Below Setting

$cd /home/ec2-user/conf

$vim server.xml

  1. I) Change in Server Shutdown Port (i.e. 8005,8006,8007) and it should be different in all tomcat instances.

                <Server port=”8005″ shutdown=”SHUTDOWN”>

  1. II) Change in Connector for Application running Port (i.e. 8081,8082,8083).

                <Connector port=”8081″ protocol=”HTTP/1.1″


               redirectPort=”8443″ />

III) Also Define an AJP 1.3 Connector port (i.e. 8009, 8010, 8011) and should be different in all tomcat instances.

                <Connector port=”8009″ protocol=”AJP/1.3″ redirectPort=”8443″ />


  1. IV) Change in sh under /home/ec2-user/tomcat1/bin and is should be different in all the instances respectively.


export CATALINA_HOME=/home/ec2-user/tomcat1

export CATALINA_BASE=/home/ec2-user/tomcat1

  1. V) Start Tomcat Services

$cd /home/ec2-user/tomcat1/bin


Now from above We’ve configured Tomcat on 8081,8082 and 8083 respectively.

Step 6:- Configuring Application Load Balancer.

Before proceeding to create Application Load Balancer we’ve to create some target groups.

Step I):- Creating Target Groups

Step 2:- You can also distribute traffic with On premises Instances and AWS instances

Step 3:- Add instances in this target Group

Step 4:- Now Creating Application Load Balancer

Step 5:- Create Listener and Select Availability Zones

Step 6:- Creating Security Group for ELB, So that internet Traffic come through ELB

Step 7:- Now Create Routing for it

Step 8:- Register Targets to route the Traffic

Step 9:- After successful creation we’ll have to configure same thing for other ports of Tomcat instances

Step 10:- Add Listener for other tomcat instance ports ( i.e. 8081,8082,8083) as well

This is it and now you can access all your tomcat instances with different different ports.

Related Posts