قالب وردپرس درنا توس
Home / How To / How to set Apache Tomcat cluster with 3 nodes on Ubuntu

How to set Apache Tomcat cluster with 3 nodes on Ubuntu



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.

Cluster Details:

  1. Node1: Base Directory = / root / tomcat1, IP = 172.31. 35.11
  2. Node2: Base Directory = / root / tomcat2, IP = 172.31.39.120
  3. Node3: Base Directory = / root / tomcat3, IP = 172.31.32.185

Requirement

  1. AWS Account (Re-create you do not have one and want to create a cluster on EC2 instances) (optional).
  2. 3 EC2 instances (Click here to learn how to create an EC2 instance) OR 3 VMs with Ubuntu 18.04 LTS on them. [19659009] Root access to the servers.

What We Will Do

  1. Download Apache Tomcat
  2. Install Java8
  3. Configure Apache Tomcat Cluster
  4. 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.

sudo -i

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

  Download Apache Tomcat

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

  Install Java

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.

  Configure Aapache Tomcat

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.

  Configure server.xml file

Find the following lines and change localhost to IP for node

  <Engine   name   =   "Catalina"    defaultHost   =   " localhost " > 
  <Host   name   =   "  localhost  "     appBase   = " web apps 

  Configure web app host

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 = "228.0.0.4"
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 "/>

  Configure the IP address of the node

Start / stop Apache Tomcat [19659017] 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.

Check logs

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.

  Start and stop Tomcat

Conclusion

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.


Source link