How to Run Multiple Instances of Apache Tomcat on One Server (Linux)
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.
To learn how to run multiple instances of Apache Tomcat on one server, follow these steps:
- 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".
- Create a directory under the
- Copy the contents of
/var/lib/tomcat7/confto your new directory. NOTE:
confis a symbolic link to
- Open an edit session on
/etc/tomcat7B/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:
- Now locate the
Connectorelement for HTTP:
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
- Change the port number to "8282":
As before, we don't want contention for the port when we start our second customized Tomcat.
<Connector port="8282" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
- Locate the
<Server port="8005" shutdown="SHUTDOWN">
- Change the port number to "8002":
We also want to change the shutdown port so that there will be no contention for the port.
<Server port="8002" shutdown="SHUTDOWN">
- Save your changes.
- 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
- Next, you will create a symbolic link to your "tomcat7B" customized configuration:
Now when we start the server, Tomcat will pick up the "tomcat7B" configuration, including the updated
sudo ln -s /etc/tomcat7B /var/lib/tomcat7/conf
- Start Tomcat:
- In your browser, enter the URL that includes the new HTTP port number,
The welcome page will display, indicating the new customized configuration has been installed by Tomcat.
- 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".