How to Cluster in Apache Tomcat (Windows)
See Apache: Tips and Tricks for similar articles.In a Tomcat production environment, you might have hundreds of web requests per second on a routine basis. With so much volume assaulting your Tomcat server, you'll probably discover that memory resources in one Tomcat JVM (Java Virtual Machine) can become overwhelmed. To help prevent this situation from becoming reality you can place two or more Tomcat servers in a cluster. A cluster is a group of servers that communicate with one another. Now you have multiple JVMs to handle the work load coming in from the network. Session data can be shared among the cluster members to achieve high availability, i.e., recovery of a web session should a server crash occur.
To learn how to cluster in Apache Tomcat, follow these steps:
- Stop the Tomcat server.
- Create a directory under the C: drive named
TomcatA
. - Copy
CATALINA_BASE/conf
to your new directory. - Open an edit session on
c:/TomcatA/conf.server.xml
. Locate the cluster entry:Note that the entry is commented out.<!-- <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> -->
- Remove the comment tags:
Note that the entry is commented out.
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
- Now locate the
Connector
element for HTTP:<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
- Change the port number to "8181":
We want to change the HTTP port so that there will be no contention for the port when we start our customized Tomcat.
<Connector port="8181" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
- Locate the
Server
element:<Server port="8005" shutdown="SHUTDOWN">
- Change the port number to "8001":
We also want to change the shutdown port so that there will be no contention for the port.
<Server port="8001" shutdown="SHUTDOWN">
- Save your changes.
- Start a command prompt and navigate to
CATALINA_HOME/bin
. - Set the environment variable
CATALINA_BASE
toc:/TomcatA
:Now when we start the server, Tomcat will pick up our new configuration, including the updatedset CATALINA_BASE=c:/TomcatA
server.xml
. - Start Tomcat:
Note that
CATALINA_HOME
andCATALINA_BASE
have different values.CATALINA_HOME
is the original installation directory that contains our web applications whereasCATALINA_BASE
contains our customized configuration. - In your browser, enter the URL that includes the new HTTP port number,
http://localhost:8181
:The welcome page will display, indicating the new configuration that includes clustering has been installed by Tomcat.
Related Articles
- How to Start and Stop Apache Tomcat from the Command Line (Windows)
- How to Deploy a WAR File to Apache Tomcat (Windows)
- How to Start and Stop Apache Tomcat from the Command Line (Linux)
- How to Deploy a WAR File to Apache Tomcat (Linux)
- How to Run a JSP Program in Apache Tomcat (Windows)
- How to Check the Status of the Apache Tomcat Server (Windows)
- How to Deploy a Web Application Using the Apache Tomcat Manager (Windows)
- How to Check the Status of the Apache Tomcat Server (Linux)
- How to Set Default Context Path in Apache Tomcat (Windows)
- How to Use the autoDeploy Attribute in Apache Tomcat (Windows)
- How to Deploy a Web Application Using the Apache Tomcat Manager (Linux)
- How to List Deployed Applications Using the Apache Tomcat Manager (Windows)
- How to Run Multiple Instances of Apache Tomcat on One Server (Windows)
- How to Run a JSP Program in Apache Tomcat (Linux)
- How to Establish a JDBC Connection in Apache Tomcat (Windows)
- How to Verify Apache Tomcat Server Operation (Windows)
- How to Cluster in Apache Tomcat (Linux)
- How to Undeploy Web Applications Using the Apache Tomcat Manager (Windows)
- How to Set Default Context Path in Apache Tomcat (Linux)
- How to Use the Java Logging API in Apache Tomcat (Windows)
- How to Cluster in Apache Tomcat (Windows) (this article)
- How to Use the Java Logging API in Apache Tomcat (Linux)
- How to Use the autoDeploy Attribute in Apache Tomcat (Linux)
- How to Configure Apache Tomcat to Use MBeans (Windows)
- How to List Deployed Applications Using the Apache Tomcat Manager (Linux)
- How to Install and Configure Apache Tomcat (Windows)
- How to Configure Apache Tomcat to Use MBeans (Linux)