How to Run Multiple Instances of Apache Tomcat on One Server (Linux)

  • google plus

In Brief...

In another how-to, I discussed how to start one member of a Tomcat cluster. Click here to learn how to cluster in Apache Tomcat (Linux) When you have completed the work in that topic, you will be prepared for this topic. I will show you how to run another Tomcat instance on the same server, or computer.

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

See the Course Outline and Register

Instructions

To learn how to run multiple instances of Apache Tomcat on one server, follow these steps:

  1. Having competed the topic mentioned above, you currently have "tomcat7A" running. You will continue to use the terminal window from that topic in the later steps of the current topic. You will now proceed by creating "tomcat7B".
  2. Create a directory under the /etc directory named tomcat7B.
  3. Copy the contents of CATALINA_BASE/conf, e.g., /var/lib/tomcat7/conf to your new directory. NOTE: conf is a symbolic link to /etc/tomcat7A.
  4. Open an edit session on /etc/tomcat7B/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"/>
           
    	
  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 "8282":
    <Connector port="8282" protocol="HTTP/1.1"
    	connectionTimeout="20000"
    	redirectPort="8443" />
    	
    As before, we don't want contention for the port when we start our second customized Tomcat.
  8. Locate the Server element:
    <Server port="8005" shutdown="SHUTDOWN">
    	
  9. Change the port number to "8002":
    <Server port="8002" 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. You will now use the terminal window you opened in the previous topic as discussed at the beginning of this lesson. In the terminal window unlink the current symbolic link:
    sudo unlink /var/lib/tomcat7/conf
    	
  12. Next, you will create a symbolic link to your "tomcat7B" customized configuration:
    sudo ln -s /etc/tomcat7B /var/lib/tomcat7/conf
    	
    Now when we start the server, Tomcat will pick up the "tomcat7B" configuration, including the updated server.xml.
  13. Start Tomcat:
    sudo ./startup.sh
    	
  14. In your browser, enter the URL that includes the new HTTP port number, http://localhost:8282:
    Tomcat Welcome Page
    The welcome page will display, indicating the new customized configuration has been installed by Tomcat.
  15. From the earlier topic referenced above, you already have a running instance of "tomcat7A". Now you have two instances of Tomcat running on your computer, "tomcat7A" and "tomcat7B".

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