Home > Programming > Running Multiple instances of Tomcat

Running Multiple instances of Tomcat

Hosting more than a single application in a single apache-tomcat server is not a new thing. It is a simple task. But many of us might be unaware of the potential danger we are putting ourselves by doing so, especially if each of the applications hosted are critical enough.

In such situation if a single application crashes, then it brings about a problem generally termed as “bad apple problem”. It results in the malfunctioning of other applications hosted in the same sever as well. Then comes the situation where running multiple instances of tomcat comes into play. Some of its main advantages are:

1. Avoid the bad apple problem.

2. Logs can be saved for each application individually.

3. Each application can be configured individually. ie. Update (upgrade/downgrade) of applications can be handled individually.

4. Stop/Start/Restart actions on one application can be performed without affecting tha other applications.

Now that we have known its importance, I’ll write about how to configure multiple instances of tomcat in a step by step manner.

Step 1:

Get binary distribution of apache-tomcat and install it.  I have used tomcat 6.x but it should work with lower versions as well. Lets suppose the installation directory is C:\Program Files\Apache Software Foundation\Tomcat 6.0.

Step 2:

Make a shared folder somewhere to place a few configurations files that can be used by all instances of tomcat we are going to make. eg. C:\tomcat-instances\shared. Under shared folder make a folder named conf.  Now copy server.xml and logging.properties from C:\~~\Tomcat 6.0\conf to C:\tomcat-instances\shared\conf.

Step 3:

In the next step we have to configure the server.xml. Modify Server.xml so that you can provide shutdown port, http port and host name in the runtime. Server port, http port and host name should be configured as shown below.

…………….

<Server port=“${shutdown.port}” shutdown=“SHUTDOWN”>

…………….

<Connector port=“${http.port}” protocol=“HTTP/1.1″
connectionTimeout=“20000″
redirectPort=“8443″ />

………………..

<Host name=“${host.name}” appBase=“webapps”
unpackWARs=“true” autoDeploy=“true”
xmlValidation=“false” xmlNamespaceAware=“false”>

Step 4: Now that we have configured server, it is time to add new instances of tomcat. Inside C:\tomcat-instances create a folder named application1. Create folders so that you have the folders structure as:

tomcat-instances
      - shared
            - conf
      - application1
            - conf
            - logs
            - webapps
            - work
            - temp

Step 5:

Now copy catalina.properties and web.xml from C:\~~\Tomcat 6.0\conf to C:\tomcat-instances\application1\conf folder.

Edit the catalina.properties and add the following lines

http.port=8081
shutdown.port=8006
host.name=localhost

The shared Server.xml takes the values of http port, shutdown port and host name from this catalina.properties. If you want to make another instance of tomcat, repeat from step 4 with application2. Make sure you give different addresses for http.port, shutdow.port. eg. 8082 and 8007 respectively. host.name can be localhost in both cases.

Step 6:

Copy the war(eg. ROOT.war of your web application) file of your application to C:\tomcat-instances\application1\webapps

Step 7:

Now the tomcat has been configured, it is time to install a new window service for the instance of tomcat just configured. You can use Tomcat Service Manager(TSM) for this. Run TSM and use the following details to create a service named Application1.

Service Name: Application1

Catalina Home: C:\Program Files\Apache Software Foundation\Tomcat 6.0

Catalina Base: C:\tomcat-instances\application1

Tomcat Config File: C:\tomcat-instances\shared\conf\Server.xml

Java Home: Your Java Installation directory

Other values are filled automatically by the TSM.

Step 8:

Now you are almost done. From the Service menu in TSM, click on install/update. This will install the service for you. After the service has been successfully installed, click on Service –> Start to start the service.

Step 9:

Congratulations!!! You are done. Now open your favourite browser and type http://localhost:8081. Your application should be running… eNjoy!!!!!

Sujan Programming , ,

  1. No comments yet.
  1. No trackbacks yet.