Load Balancing Tomcat on Leopard with mod_jk

I’ve just had to setup a test system that load balances a site running on Tomcat across multiple computers. My test bed is 3 mac minis, one working as the ‘head’ running Apache, and the other two in the ‘farm’ handling the load. It was a less than painless exercise, so I thought I’d write up the instructions.

1. Install Tomcat
Download Tomcat from here.
On each farm machine rename the folder to be Tomcat, then move it to the /Library/ directory.
In Terminal:

cd /Library/Tomcat/bin
rm *.bat
rm *.exe
chmod +x *

(You don’t need .bat or .exe files, but you do need other files to be executable).

Edit the file /Library/Tomcat/conf/tomcat-users.xml so that it reads:

<?xml version='1.0' encoding='utf-8'?>
  <role rolename="manager"/>
  <user username="tomcat" password="s3cret" roles="manager"/>

(Note that the username and password are examples from Tomcat – you should probably change them).

Repeat the above for each farm machine.

2. Deploy your application
Open each of your farm machines in turn from your browser, e.g.


You should see a screen that looks something like this:

Welcome screen for a Tomcat installation

Click Tomcat Manager and enter the username and password you defined above. This should show the Tomcat Web Application Manager screen.

Upload the war file of the application you want to run. Once complete you should see a link on the manager page to your application. Click it and make sure it works OK.

Repeat the above for each farm machine.

3. Install mod_jk
Here’s the tricky bit. Mod_jk is the apache module that handles the load balancing. It’s available here, BUT none of the downloads there will work on Leopard. Apache on Leopard runs as 64 bit, which isn’t an option you can download from the Tomcat site. So you have two options:

  • Download the source code and build your own version. This isn’t too hard if you have the relevant tools already installed – look here for an excellent step-by-step on the changes you need to make to build a 64 bit version.
  • Use MacPorts
  • , which appears to have the facility to create a 64 bit version (I haven’t tested this).

  • Download the 64 bit version of mod_jk 1.2.26 that I created. I may update this as I go along, but no guarantees!

Once you have your mod_jk.so file (if it doesn’t end up with that name, change the name) copy it to the /usr/libexec/apache2/ directory of your head machine. It’s worth changing the ownership and permissions of the file to match the other modules using the commands sudo chown root:wheel mod_jk.so and sudo chmod 755 mod_jk.so.

4. Configure Apache
Edit the file /etc/apache2/httpd.conf and add the following lines:

#Added for Load Balancing
LoadModule jk_module libexec/apache2/mod_jk.so
# Path to workers.properties
JkWorkersFile /etc/apache2/workers.properties 

# Path to jk logs
JkLogFile /your-chosen-location/mod_jk.log

# Jk log level [debug/error/info]
JkLogLevel info

# Jk log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

# JkOptions for forwarding
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

JkMount /your-application balancer
JkMount /your-application/* balancer
#End Added for Load Balancing

Note that you’ll need to set the location for your log file, and the name of your application. It’s a good idea to create the log file (e.g. use touch mod_jk.log in the directory you want it; this makes sure the file can be created, which would otherwise trip Tomcat up.

Now create a new file worker.properties in /etc/apache2 containing the following:






The worker.maintain setting helps determine how long one farm machine will be used before the load switches to another machine. For testing I used 5 (seconds); the default is 60.

5. Start Apache
Tomcat should still be running on each of the farm servers, so start Apache on your head machine by opening System Preferences…Sharing and checking the ‘Web Sharing’ box (if it was already checked then uncheck and recheck it to restart Apache).

6. Test it out
Browse to http://head/your-application – you should see your application!

This post was based on the excellent work found here

Release Day

I can finally share what I’ve been working on since I joined SpringSource. I won’t try to explain it in detail, because half of you will glaze over immediately, but basically it’s an application platform that allows convenient deployment of OSGi Java apps using Spring software. See, I told you.

For those of you who’ve gone “ooh”, here’s the product page.

Posted in Uncategorized
Tagged with ,

1 Wikipedia, 2 Wikipedias…

I’ve seen this linked a few times, and finally got time to read it. What an awesome article – there’s nothing in there that I couldn’t have thought up, but I didn’t and this guy did:

I was having dinner with a group of friends about a month ago, and one of them was talking about sitting with his four-year-old daughter watching a DVD. And in the middle of the movie, apropos nothing, she jumps up off the couch and runs around behind the screen. That seems like a cute moment. Maybe she’s going back there to see if Dora is really back there or whatever. But that wasn’t what she was doing. She started rooting around in the cables. And her dad said, “What you doing?” And she stuck her head out from behind the screen and said, “Looking for the mouse.”

Google Calendar

This might be well-known, but it was new to me when I stumbled on it. If you click on a date in the calendar on the left of the page and drag to the left or right the main display adjusts to show the number of days you’ve highlighted. Similarly moving up or down shows the number of weeks you’ve selected. Very handy when planning.

Posted in Uncategorized
Tagged with


I’ve been using a newish (at least for the latest beta) note taking and crap collecting app called Evernote recently. Among its cool features are a decent Mac client (or a Windows one if you must), syncing to an online client, OCR for pictures you insert, various mobile clients, and publishing of any items you want to a web page (so you can make notes of your shopping needs during the week, then browse to your shopping list on your phone at the weekend).

Anyway, I’ve been rather impressed. Take a look, and if you’d like an invite to the beta let me know (verloren at Google’s excellent email service).

Posted in Uncategorized
Tagged with