Multiple Instances of Tomcat with Apache

Learn how to use mod_jk to forward requests to specific hosts when more than one Tomcat instance is running.

Recently, I was asked to reorganize some of our Web applications to improve their stability. The major push was to get each of our applications running in its own instance of Tomcat. These applications all are in various stages of development, and if a single instance allocates all of the memory available, the entire Tomcat server must be restarted. This, in turn, brings down all of the other applications.

An obstacle to running multiple instances is each instance would have to run on a unique port. Enter Apache’s Web server. With the use of mod_jk, we were able to forward requests to specific hosts and contexts to the respective running instance of Tomcat.

Pulling all of this together was not the hardest thing I’ve done; however, it did prove challenging due to a lack of documentation. By no means, though, is this statement a stab at any of the development teams. In fact, the developers themselves helped me on numerous occasions when I found myself in over my head. When the documentation had me confused or I could not find exactly what I was looking for, I would head over to #tomcat or #apache on and pose my question there. Usually, I received a response within minutes.

The following software was used for the purposes of this article. See the resources section at the end of this article for download locations:

  • J2sdk1.4.2_09
  • Tomcat 5.0.28
  • Apache 2.0.54
  • mod_jk 1.2.14

Read More
Source : article by Daniel McCarthy,Linux Journal

Related Posts:

6 Responses

Marty McGee January 7, 2008 at 6:28 am

Great article! Just what I’m looking for. Any chance we could get a cleanup of the last bits of code? It seems WordPress has deleted the line breaks (as previous versions of WP are notorious for). Thanks!

Kor Kiley January 7, 2008 at 6:28 am

The text about the comment syntax above got cut off. If you really want to comment a section out you need to surround it with a comment like so:

Kor Kiley January 7, 2008 at 6:28 am

OK. Try this:

WordPress is apparently interpreting these comments as HTML and not literal text. I’m trying quotes around the comment syntax. If that doesn’t work, I give up. I’m sure anyone reading this article already knows how to comment XML/HTML anyway.


dammitAdam January 7, 2008 at 6:28 am

Not to spam your site – but this is another place where mod_proxy_ajp in Apache 2.2 would be a real lifesaver:
ProxyPass ajp://localhost:8009/application1/
ProxyPass ajp://localhost:8109/application2/
ProxyPass ajp://localhost:8209/application3/

This avoids all of the workers config, and is much more logical (to me anyways)

dammitAdam January 7, 2008 at 6:28 am

My code got messed up above – I’ve dropped the Apache 2.2 config into my blog here:

Shatner and Sulu: Apache To Multiple Tomcat Servers January 7, 2008 at 6:28 am

[…] post is basically a response to an article that is over @ JavaTechie Its just to show how to send traffic to multiple tomcat servers using mod_proxy_ajp in Apache 2.2. […]

Comments are closed.