Tuesday 20 October 2015

Run multiple tomcat instances on one machine

In this post, I am going to explain, how to run multiple tomcat instances on one machine.
We can create multiple instances in two ways.
         a. By sharing the same tomcat code base across all instances
         b. By creating separate copies of tomcat images

To work with multiple instances of tomcat, we need to play with configuration files, First will understand basic directory structure of tomcat.

Directory
Description
bin
Contains all startup, shoutdown scripts
conf
Contains tomcat configuration files. server.xml, web.xml are mainly used.
lib
Contains all the necessary jars that tomcat require.
logs
Directory contains tomcat log files
webapps
Web applications are deployed in this directory
work
Tomcat place all servlets that are generated from JSPs.

Following are the port details, that you need to know while configuring multiple instances of the same server installation.

Port
Description
Connector port
Tomcat listen http requests on this port
Shutdown port
This port is used while shutting down tomcat
AJP (Apache JServ Protocol) Connector Port
The AJP Connector element represents a Connector component that communicates with a web connector via the AJP protocol.
Redirect Port
All the redirection operations will happen through this port.

Following procedure explains how to configure multiple instances of tomcat.

Step 1: Download Apache tomcat. Copy the same image to some other folder.
$ ls apache-tomcat-8*
apache-tomcat-8.0.22:
AuditViolations.html	LICENSE			RELEASE-NOTES		bin			lib			temp			work
AuditViolations_files	NOTICE			RUNNING.txt		conf			logs			webapps

apache-tomcat-8.0.22_image1:
AuditViolations.html	LICENSE			RELEASE-NOTES		bin			lib			temp			work
AuditViolations_files	NOTICE			RUNNING.txt		conf			logs			webapps

In this example, I am using two images of tomcat apache-tomcat-8.0.22, apache-tomcat-8.0.22_image1.

Step 2: Open server.xml (apache-tomcat-8.0.22_image1/conf/server.xml) file of apache-tomcat-8.0.22_image1 and change the HTTP, HTTPS, AJP, Shutdown Ports.

Step 3: Update catalina.sh file in both tomcat instances.

Add following variables to apache-tomcat-8.0.22/bin/catalina.sh
export CATALINA_HOME= /Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22
export CATALINA_BASE= /Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22

Add following variables to apache-tomcat-8.0.22_image1/bin/catalina.sh
export CATALINA_HOME= /Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22_image1
export CATALINA_BASE= /Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22_image1
Go to bin directories of tomcat run startup.sh scripts.
$ ./startup.sh
/Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22/bin/catalina.sh: line 98: export: `/Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22': not a valid identifier
/Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22/bin/catalina.sh: line 99: export: `/Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22': not a valid identifier
Using CATALINA_BASE:   /Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22
Using CATALINA_HOME:   /Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22
Using CATALINA_TMPDIR: /Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22/temp
Using JRE_HOME:        /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
Using CLASSPATH:       /Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22/bin/bootstrap.jar:/Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22/bin/tomcat-juli.jar
Tomcat started.

$ ./startup.sh 
/Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22_image1/bin/catalina.sh: line 98: export: `/Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22_image1': not a valid identifier
/Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22_image1/bin/catalina.sh: line 99: export: `/Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22_image1': not a valid identifier
Using CATALINA_BASE:   /Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22_image1
Using CATALINA_HOME:   /Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22_image1
Using CATALINA_TMPDIR: /Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22_image1/temp
Using JRE_HOME:        /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
Using CLASSPATH:       /Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22_image1/bin/bootstrap.jar:/Users/harikrishna_gurram/softwares/apache-tomcat-8.0.22_image1/bin/tomcat-juli.jar
Tomcat started.
Open browser and hit the URLs http://localhost:8080, http://localhost:8081. You will get following screen.





Previous                                                 Next                                                 Home

No comments:

Post a Comment