Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

We generally use the tried and true JKMod.

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
langhtml
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.

mod_jk may be installed but it still needs to be configured. Create the file /etc/apache2/mods-available/jk.conf using sudo with the following contents,

Code Block
langhtml
<IfModule mod_jk.c>

JkWorkersFile "/etc/libapache2-mod-jk/workers.properties"
JkLogFile "/var/log/apache2/mod_jk.log"

# Use debug mode if you have trouble
# JkLogLevel debug

JkLogLevel info

</IfModule>

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,

Code Block
langhtml
sudo a2enmod jk

This basically creates symbolic links for you in the /etc/apache2/mods-enabled directory. The two symbolic links will be,

  1. jk.conf
  2. jk.load

You can verify that the module loaded properly,

Code Block
langhtml
sudo apache2ctl -l
Compiled in modules:
  core.c
  mod_log_config.c
  mod_logio.c
  worker.c
  http_core.c
  mod_so.c

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.

Code Block
langhtml
# Define workers using ajp13
worker.list=tomcat_a_worker

# Set properties for worker
worker.tomcat_a_worker.type=ajp13
worker.tomcat_a_worker.host=localhost
worker.tomcat_a_worker.port=8009
worker.tomcat_a_worker.lbfactor=1

In the above case are creating a worker for a web application to connect to TomcatA which will run in the www.krypton.com virtualhost. Notice the host=localhost line in yellow. This should point to the server that Tomcat is running on. In this case, we are have Apache and Tomcat on the same server so we use localhost.

To keep the example simple I have not added load balancer support yet. If you want load do load balancing a simple configuration would look like this,

Warning

Content is still being copied over.

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.