How to Cluster in Apache Tomcat (Windows)

  • google plus

In Brief...

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.

Take our Apache Tomcat 8.0 Administration for Windows Training course for free.

See the Course Outline and Register

Instructions

To learn how to cluster in Apache Tomcat, follow these steps:

  1. Stop the Tomcat server.
  2. Create a directory under the C: drive named TomcatA.
  3. Copy CATALINA_BASE/conf to your new directory.
  4. Open an edit session on c:/TomcatA/conf.server.xml. Locate the cluster entry:
    <!--
    <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
    -->
    	
    Note that the entry is commented out.
  5. Remove the comment tags:
    <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
           
    	
    Note that the entry is commented out.
  6. Now locate the Connector element for HTTP:
    <Connector port="8080" protocol="HTTP/1.1"	
    	connectionTimeout="20000"
    	redirectPort="8443" />
    	
  7. Change the port number to "8181":
    <Connector port="8181" protocol="HTTP/1.1"
    	connectionTimeout="20000"
    	redirectPort="8443" />
    	
    We want to change the HTTP port so that there will be no contention for the port when we start our customized Tomcat.
  8. Locate the Server element:
    <Server port="8005" shutdown="SHUTDOWN">
    	
  9. Change the port number to "8001":
    <Server port="8001" shutdown="SHUTDOWN">
    	
    We also want to change the shutdown port so that there will be no contention for the port.
  10. Save your changes.
  11. Start a command prompt and navigate to CATALINA_HOME/bin.
  12. Set the environment variable CATALINA_BASE to c:/TomcatA:
    set CATALINA_BASE=c:/TomcatA
    	
    Now when we start the server, Tomcat will pick up our new configuration, including the updated server.xml.
  13. Start Tomcat:
    Start Tomcat
    Note that CATALINA_HOME and CATALINA_BASE have different values. CATALINA_HOME is the original installation directory that contains our web applications whereas CATALINA_BASE contains our customized configuration.
  14. In your browser, enter the URL that includes the new HTTP port number, http://localhost:8181:
    Tomcat Welcome Page
    The welcome page will display, indicating the new configuration that includes clustering has been installed by Tomcat.

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, XML, Windows, Java, Adobe, HTML5, JavaScript, Angular, and much more. Check out our complete course catalog.

Categories

Courses

Author: Stephen Withrow

Stephen has over 30 years' experience in training, development, and consulting in a variety of technology areas including Java, C, C++, XML, JavaScript, AJAX, Tomcat, JBoss, Oracle, and DB2. His background includes design and implementation of business solutions on client/server, Web, and enterprise platforms. Stephen is a published writer in both technical and non-technical endeavors. Stephen received an undergraduate degree in Computer Science and Physics from Florida State University.

Discuss