Warning |
---|
This article has almost been completely moved from https://sites.google.com/site/tinswiki/articles/Ubuntu/2009-part-6-connect-apache2-x-to-tomcat-6-x. There are just a few sub links. This article can also be improved to use the newer conventions in Tomcat server names. |
Table of Contents |
---|
Introduction
It is often useful to have Apache front Tomcat.
There are two main methods of doing this,
- JKMod Apache Tomcat Connector - tried and true
- Reverse Proxy - relatively new (Nov 4, 2009) and part of Apache
We generally use the tried and true JKModApache Tomcate Connector often called by its binary file mod_jk.
Install mod_jk
There are two different methods of installing mod_jk. The simper being using apt-get if you have Ubuntu.
Using apt-get
With Ubuntu you can have mod_jk almost automatically install for you via,
Code Block | ||
---|---|---|
| ||
sudo apt-get install libapache2-mod-jk |
Running this command results in the following,
- /usr/lib/apache2/modules/mod_jk.so (this will not always be the most current - you can see the current version by looking at the package info)
- /etc/libapache2-mod-jk/workers.properties (create a generic workers.properties file for generic setup of Tomcat 6.x)
- /etc/apache2/mods-available/jk.load (file which loads the mod_jk module)
- /etc/apache2/mods-enabled/jk.load (symbolic link which starts the mod_jk module)
BUT it is not quite working yet. Continue reading.
Create jk.conf
The approach I take here is to make the mod_jk available at the global level to all Apache Virtual hosts. If we wanted things to be more granular you could instead put the contents of jk.conf in a specific virtual host.
...
There are much more configuration options. But this should be enough to get you started for a small to medium scale website.
Enable mod_jk
In Ubuntu it is very easy to enable a module,
...
worker.c in the resutling output shows that the module loaded properly.
workers.properties Configuration File
Edit or create (in the case of a manual setup) /etc/libapache2-mod-jk/workers.properties which defines how Apache will pass the traffic to Tomcat.
...
The load balancing uses weighted round-robin with sticky sessions. The lower the lbfactor number the less weight and as such the less work done by the worker. In our example, since both tomcat a and b have a factor of 1 the load balance is split about 50/50.
Tin's Adjustments
What you have so far should work. However, if you want to match what I use in production I also made the following adjustments.
...
Note |
---|
If someone can let me know why we would want to have these properties let me know. |
Configure Map Points in Apache
This last step will be different depending on if you are using virtual hosts or not.
First verify that you can hit the examples application without mod_jk by directly hitting the tomcat a server running on port 8080.
...
If you wanted to use the load balancer you would change tomcatA to loadbalancer.
Restart Apache
Finally you must restart Apache for the changes to take effect.
...
Now you should be able to view the examples site without specifying port 8080, http://www.krypton.com/examples/
Manually Installing mod_jk
I often have to do this on Solaris or alternative operating systems so the manual process of installing mod_jk is good to have handy
Warning |
---|
The manual process of installing mod_jk should be moved to this wiki. |
Resources
http://www.gustavomejia.com/blog/2008/03/02/1204455261015.html - seems to have decent instructions using ubuntu apt-get to set up mod_jk. Don't understand the java_home thing though.
...