In this article we will see how to set up a cluster of Apache Tomcat servers. We will use 3 Ubuntu 18.04 EC2 instances or VM discs, here I have used EC2 instances. We will also see the steps to install Java because Apache Tomcat requires Java.
The following are the details of my cluster.
- Node1: Base Directory = / root / tomcat1, IP = 172.31. 35.11
- Node2: Base Directory = / root / tomcat2, IP = 172.31.39.120
- Node3: Base Directory = / root / tomcat3, IP = 172.31.32.185
- AWS Account (Re-create you do not have one and want to create a cluster on EC2 instances) (optional).
- 3 EC2 instances (Click here to learn how to create an EC2 instance) OR 3 VMs with Ubuntu 18.04 LTS on them.  Root access to the servers.
What We Will Do
- Download Apache Tomcat
- Install Java8
- Configure Apache Tomcat Cluster
- Start / Stop Apache Tomcat
Download Apache Tomcat
Change to "root" the user to avoid authorization errors. However, it is not recommended to use "root" users in production environments.
Create a directory. Here we store the Apache Tomcat package.
mkdir tomcat1 # On Node2 mkdir tomcat2, On Node3 mkdir tomcat3
cd tomcat1 / # On Node2 cd tomcat2 /, On Node3 cd tomcat3 /
Download and extract Apache-Tomcat-9.0.0.M can download any version from here.
# On each node
wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.0.M17/bin/apache-tomcat -9.0.0.M17.tar.gz #Download
tar -zxvf apache-tomcat-9.0.0.M17.tar.gz #Extract
Install Java 8
#On each node
sudo apt-get update # Update system package details
sudo apt install openjdk-8-jdk # Install Java
java – version #Check Java version
Configure Apache Tomcat
Before we make the necessary changes , let's back up the default server.xml file.
# On each node
cd apache-tomcat-9.0.0.M17 / # Change directory.
cp conf / server.xml conf / server.xml.bak #Take a backup of the existing configuration file.
Make the necessary changes to the server.xml file.
#About each node
ifconfig #Get IP on the server.
vim conf / server.xml # Open the configuration file to make the necessary configurations.
Find the following lines and change localhost to IP for node
<Engine name = "Catalina" defaultHost = " localhost " >
<Host name = " localhost " appBase = " web apps
To set up the cluster, search for the following code
And add the following code to each node and replace IP-of-Node with IP for the node itself.
<MembershipName = "org.apache.catalina.tribes.membership.McastService" address = "126.96.36.199"
port = "45564" frequency = "500" dropTime = "3000" />
<Receiver class name = "org.apache.catalina.tribes.transport.nio.NioReceiver" address = " IP-of-Node "
port =" 5000 "selectorTimeout =" 100 "maxThreads =" 6 "/>
<Deployer className =" org.apache.catalina.ha.deploy.FarmWarDeployer "tempDir =" / tmp / war -temp / "
deployD ir =" / tmp / war-deploy / "watchDir =" / tmp / war-list / "watchEnabled =" false "/>
Start / stop Apache Tomcat  Start Apache Tomcat
Use the startup.sh file to start the Apache Tomcat service. Using the netstat command, you can see that the service has started on the default port 8080. Ads
# On each node
bin / startup.sh # Start Apache Tomcat Service.
netstat -tulp # Check ports currently used in the system.
catalina.out contains the logs for Apache Tomcat. You can use the tail command to see the last lines of the file.
tail -100f logs / catalina.out
Turn off Apache Tomcat
The Apache Tomcat service can be stopped with shutdown. sh file
bin / shutdown.sh #Stop Apache Tomcat Service.
In this article we looked at the steps to create a cluster of Apache tomcat with 3 nodes, saw the basic configuration that must be done to create a cluster.