Apache Tomcat:- Apache Tomcat is used to deploy your Java Servlets and JSPs. So in your Java project, you can build your WAR (short for Web ARchive) file, and just drop it in the deploy directory in Tomcat. So basically Apache is an HTTP Server, serving HTTP. Tomcat is a Servlet and JSP Server serving Java technologies
If you are an Administrator and working with DEV team then you may require to setup Multiple Tomcat instance on the same server.
In my this blog series I am going to explain step by step setting up Tomcat multiple Instances.
Prerequisites:- We need following prerequisites to accomplish this lab.
http://192.168.102.12:8080/
Both the Instance configured and running as expected. We can modify Connector port as per our requirement by modifying file server.xml.
If you are an Administrator and working with DEV team then you may require to setup Multiple Tomcat instance on the same server.
In my this blog series I am going to explain step by step setting up Tomcat multiple Instances.
Prerequisites:- We need following prerequisites to accomplish this lab.
- One Linux Box with sudoers privileges.
- TWO IP address (192.168.102.11 &192.168.102.12)
- Default JRE
Apache Tomcat requires JAVA to run a web application. Let's use the command below to install default JRE.
Step 2- Create two separate directory
Step 3- Download Tomcat and Extract in both the directories.
root@US16:~# apt install default-jre
Once Java installation finished, check installed version by hitting below command.root@US16:~# java -version openjdk version "1.8.0_131" OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11) OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)
Let's use different directory for both the instance, It helps us to manage both the instance easily.
For Instance 1
root@US16:~# mkdir -p /home/tomcat1
For Instance 2
root@US16:~# mkdir -p /home/tomcat2
Let's download Apache Tomcat from the official's page and extract to both the above create directories.
Download
root@US16:~# wget https://www.apache.org/dist/tomcat/tomcat-7/v7.0.81/bin/apache-tomcat-7.0.81.tar.gz
Extract
root@US16:~# gunzip apache-tomcat-7.0.81.tar.gz
root@US16:~# tar -xvf apache-tomcat-7.0.81.tar -C /home/tomcat1
root@US16:~# tar -xvf apache-tomcat-7.0.81.tar -C /home/tomcat2
Step 4- Modify server.xml
Let's modify file server.xml and make the required changes as follow:
Open file for Instance 1 and change the following lines.
Instance 1: Let's modify first Instance's config file.
root@US16:~# vi /home/tomcat1/apache-tomcat-7.0.81/conf/server.xml
Keep the 8005 Server port for Instance1
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
Here change the connector port so client can connect on this port and bind with specific IP address
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
address="192.168.102.11"
redirectPort="8443" />
Save and Exit from the File.
Instance 2: Let's modify second Instance's config file.
root@US16:~# vi /home/tomcat2/apache-tomcat-7.0.81/conf/server.xml
Change Server port with 8055 for second Instance so It can make a second connection with JAVA.
<Server port="8055" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
Now, Bind the second Instance with IP address 192.168.102.12.
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
address="192.168.102.12"
redirectPort="8443" />
Save and exit from the file.
The required configuration has been changed successfully for both the instances. Let's start both Instances using the command below.
Instance 1: - Start First Instance
root@US16:~# cd /home/tomcat1/apache-tomcat-7.0.81/bin/
Start the Instance 1
root@US16:/home/tomcat1/apache-tomcat-7.0.81/bin# ./startup.sh
Using CATALINA_BASE: /home/tomcat1/apache-tomcat-7.0.81
Using CATALINA_HOME: /home/tomcat1/apache-tomcat-7.0.81
Using CATALINA_TMPDIR: /home/tomcat1/apache-tomcat-7.0.81/temp
Using JRE_HOME: /usr
Using CLASSPATH: /home/tomcat1/apache-tomcat-7.0.81/bin/bootstrap.jar:/home/tomcat1/apache-tomcat-7.0.81/bin/tomcat-juli.jar
Tomcat started.
Now, Have a look at listing Ports, As per our configuration Port No. 8080 should listen on IP address-192.168.102.11 and Server Port 8005 should listen with 127.0.0.1 IP address.
root@US16:/home/tomcat1/apache-tomcat-7.0.81/bin# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1937/sshd
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 2754/java
tcp6 0 0 :::8009 :::* LISTEN 2754/java
tcp6 0 0 192.168.102.11:8080 :::* LISTEN 2754/java
tcp6 0 0 :::80 :::* LISTEN 2106/apache2
tcp6 0 0 :::22 :::* LISTEN 1937/sshd
tcp6 0 0 :::443 :::* LISTEN 2106/apache2
For Instance 1 Port listening as expected.
Instance 2: - Let's Start second Instance
root@US16:~# cd /home/tomcat2/apache-tomcat-7.0.81/bin/
Start the Instance 2
root@US16:/home/tomcat2/apache-tomcat-7.0.81/bin# ./startup.sh
Using CATALINA_BASE: /home/tomcat2/apache-tomcat-7.0.81
Using CATALINA_HOME: /home/tomcat2/apache-tomcat-7.0.81
Using CATALINA_TMPDIR: /home/tomcat2/apache-tomcat-7.0.81/temp
Using JRE_HOME: /usr
Using CLASSPATH: /home/tomcat2/apache-tomcat-7.0.81/bin/bootstrap.jar:/home/tomcat2/apache-tomcat-7.0.81/bin/tomcat-juli.jar
Tomcat started.
Let's have a look at listing ports.
root@US16:/home/tomcat2/apache-tomcat-7.0.81/bin# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1937/sshd
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 2754/java
tcp6 0 0 :::8009 :::* LISTEN 2754/java
tcp6 0 0 192.168.102.12:8080 :::* LISTEN 2806/java
tcp6 0 0 192.168.102.11:8080 :::* LISTEN 2754/java
tcp6 0 0 :::80 :::* LISTEN 2106/apache2
tcp6 0 0 :::22 :::* LISTEN 1937/sshd
tcp6 0 0 127.0.0.1:8055 :::* LISTEN 2806/java
For Second Instance Port listing as Expected.
Step 5- Try to access both the Instance:
For this open browser and hit following URLs:
http://192.168.102.12:8080/
Both the Instance configured and running as expected. We can modify Connector port as per our requirement by modifying file server.xml.
Amazing blog
ReplyDeleteKeep posting such kind of information on your blog. I really impressed by your blog. I also want to share some of the best USA Dedicated Server services for your website at a reasonable price and full technical support.