Installing mod_jk
Linux, Tomcat 5.5, and Apache 2.2
This how-to assumes that you know how to install and configure Tomcat 5.x and Apache-httpd 2.2 . Also, if my path names do not match yours, then substitute yours where needed. I also created a super small test application in Tomcat, so that I could test my set up.- My Setup
- Tomcat 5.5.17
- Apache 2.2.3
- Tomcat Connectors ( JK 1.2 )
Installation
I downloaded and installed apache, following the INSTALL document../configure --prefix=/usr/local/apache2 make su make install exitI then set my DocumentRoot directive in the /usr/local/apache2/conf/httpd.conf file to /usr/local/www, as well as the <Direcotry "/usr/local/www">. That is where I keep my html files for this awesome website.
I was lazy and downloaded the binary of Tomcat 5.5, and put it at /usr/local/apache-tomcat-5.5.17. Then knowing I would continue to be lazy I added a sym link /usr/local/tomcat -> /usr/local/apache-tomcat-5.5.17/. The sym link means I dont have to type much, and it also allows me to have multiple Tomcat versions installed and easily test my application with little change. I just have to change where the link points to. You should then set the environment variable CATALINA_HOME using this command. ( You're probably going to want to add that file to your .bashrc or .bash_profile and export it. )
CATALINA_HOME=/usr/local/tomcatNext you're gonna want to build mod_jk.so from source, so download it and follow these simple steps:
tar -xzf tomcat-connectors-1.2.18-src.tar.gz cd tomcat-connectors-1.2.18-src/native ./configure --with-apxs=/usr/local/apache2/bin/apxs make cp apache-2.0/mod_jk.so /usr/local/apache2/modules/mod_jk.so
Configuration
It's not working yet, you still need to configure your worker files and edit the httpd.conf file so httpd knows what is going on, and Tomcat will work. Before we create the worker file, we're going to assume a few things: 1. You know how to create an application with Tomcat 2. You already have an application in your webapps dir, and you know to substitute it's name for the name of my app.Navigate to the directory $CATALINA_HOME/conf, and create a file called worker.properties. The basic contents of the file should look like this ( for an ajp13 connector ):
# CATALINA_HOME workers.tomcat_home = /usr/local/tomcat # JAVA_HOME workers.java_home = /usr/local/jdk1.5.0_07 # Path separator ps = / # WORKER LIST worker.list = worker1 # worker1 settings ( ajp13 worker for requests ) worker.worker1.port = 8009 worker.worker1.host = localhost worker.worker1.type = ajp13If you want to know more about workers, have a good look at workers.properties page. However, I think that you will get the basic idea of the file from reading my example.
Apache-httpd still doesn't know anything about this, so don't expect this to work yet. In order to make httpd aware of this, you have to edit your /usr/local/apache2/conf/httpd.conf file. The changes to the file are simple, because this is a simple example. Add the following to your httpd.conf file
<IfModule !mod_jk.c> LoadModule jk_module "/usr/local/apache2/modules/mod_jk.so" <IfModule> JkLogLevel info JkMount /test* worker1 JkMount /test/* worker1 JkWorkersFile "/usr/local/tomcat/conf/worker.properties" JkLogFile "/usr/local/apache2/logs/mod_jk.log"Everything is pretty self explanitory except for the JkMount lines. Basically what they are telling httpd to do is; forward all requests going to http://mysite.com/test/* or http://localhost/test, and hand them off to Tomcat. After all, that is the point of the connector.
Now, fire up Tomcat ( CATALINA_HOME/bin/startup.sh ) and then turn on httpd ( /usr/local/apace2/bin/apachectl start ). Again, I am going to assume that the DocumentRoot directive in your httpd.conf is set to /usr/local/www , so put a foo.html file in there with some HTML on it. You should be able to browse to http://localhost/foo.html and see it being served by httpd. Now, browse to http://localhost/test and you should see your Tomcat application, be served by httpd using the connector.


