Adsense 1

Thursday, April 03, 2008

How to configure 2 or more tomcat instances in the same server

We have already seen how to install tomcat in Linux.

Now let us create one more instance. As you may already know we cannot have two services listening on the same ip & port. So, for the second instance of the tomcat we have to change the port settings.

This tutorial is in continuation of my first post on installing tomcat. You can read it here. I assume that you already have one tomcat instance up and running (as a special user 'myuser').

Login as or su as myuser:
# su - myuser
$ cd ~

$ unzip /your/download/directory/apache-tomcat-x.x.x.zip (or)

if downloaded gzip file then
$ tar zxfv /your/download/directory/apache-tomcat-x.x.x.tar.gz

$ mv apache-tomcat-x.x.x test-tomcat1
$ cd ~/test-tomcat1/conf

Changing the default ports:
$ cp server.xml server.xml.orig
$ vi server.xml

Change the shutdown port 8006 (as shown in below line):

server port="8006" shutdown="SHUTDOWN"

to:
server port="9006" shutdown="SHUTDOWN"


Change non-ssl http 1.1 Connector port on 8080 (as shown in below line):

Connector port="8080" maxHttpHeaderSize="8192" maxThreads="150" ...

to:
Connector port="9080" maxHttpHeaderSize="8192" maxThreads="150" ...


Ajp connector port 8009 (as shown in below line):
connector port="8009" enablelookups="false" redirectport="8443" protocol="AJP/1.3"

to:
connector port="9009" enablelookups="false" redirectport="9443" protocol="AJP/1.3"


If you have enabled proxied http connector port 8082 (found in line below):
Connector port="8082" maxThreads="150" minSpareThreads="25" ...

Change it to:
Connector port="9082" maxThreads="150" minSpareThreads="25" ...


If you have enabled https port 8443 (found in lines below):

connector
port="8443" maxhttpheadersize="8192"
keystorefile="/home/tomcat/keystore/tomcat.key" scheme="https"
secure="true" clientauth="false" sslprotocol="TLS"

Change it to:
connector
port="9443" maxhttpheadersize="8192"
keystorefile="/home/myuser/keystore/domain.key" scheme="https"
secure="true" clientauth="false" sslprotocol="TLS"


Now give executable permission to the scripts:
$ cd ~/test-tomcat1/bin/
$ chmod u+x *.sh

Create a directory for your Servlet's log files:
$ mkdir ~/myservlet1

And add aliases:

$alias tomcat1-down=~/test-tomcat/bin/shutdown.sh
$ alias tomcat1-up=cd ~/myservlet1; ~/test-tomcat/bin/startup.sh

Remember to put alias entries in ~/.bashrc so that they are persistent.

Startup tomcat:
$ tomcat1-up

Open your browser. You must be able to view both tomcat test pages by now.
Page1: http://localhost:8080/
Page2: http://localhost:9080/

No comments:

Post a Comment