mod_jk Installation Tips

I have used Tomcat + Apache for a while - yet I have never had to do the installation myself. Recently I needed an R&D server for the Jira Services I'm developing; enter mod_jk installation. This post is for anyone that wants to install mod_jk - the right way - and avoid the nightmare documentation that currently exists.

  1. netstat to make sure you select unused ports e.g.    
            
    1. 8080: Apache
    2.       
    3. 8081: Tomcat
    4.       
    5. 8009: mod_jk
    6.    
  2. install Tomcat; verify http connection
  3. install Apache; verify http connection
  4. install mod_jk (mod_jk2 is deprecated)
  5. create $CATALINA_HOME/conf/workers2.conf    
    # configure shared memory
    file = /opt/tomcat5/logs/shm.file
    size = 1048576
    # configure tomcat worker
    worker.list = mod_jk_worker
    worker.mod_jk_worker.type = ajp13
    worker.mod_jk_worker.host = localhost
    worker.mod_jk_worker.port = 8009
    # channel only used in Windows
    worker.mod_jk_worker.channel = myTomcat
  6. modify $APACHE_HOME/conf/httpd.conf    
    LoadModule jk_module modules/mod_jk.so
    <IfModule mod_jk.c>
      JkWorkersFile /etc/apache2/conf/workers2.conf
      JkLogFile /var/log/apache2/mod_jk.log
      JkLogLevel debug
      JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
      JkRequestLogFormat "%w %V %T"
      JkMount /jira mod_jk_worker
      JkMount /jira/* mod_jk_worker
    </IfModule>

Believe it or not this simple information is not properly documented - even though many referrers will point you to here and here. In fact Cory Foy's post - if you look closely - has him running mod_jk2 even after trying to move back to mod_jk.

Anyway, I hope this helps you.

Comments

I think it should be $CATALINA_HOME/conf/workers2.conf (in my case /opt/tomcat5/conf/workers2.conf) in the following line
JkWorkersFile /etc/apache2/conf/workers2.conf
Anyway, I keep getting this error in /var/log/apache2/mod_jk.log
----
[Sat Nov 19 20:14:48 2005] [8196:52064] [debug] build_worker_map::jk_worker.c (236): creating worker mod_jk_worker [Sat Nov 19 20:14:48 2005] [8196:52064] [debug] wc_create_worker::jk_worker.c (141): about to create instance mod_jk_worker of ajp13 [Sat Nov 19 20:14:48 2005] [8196:52064] [debug] wc_create_worker::jk_worker.c (154): about to validate and init mod_jk_worker [Sat Nov 19 20:14:48 2005] [8196:52064] [debug] ajp_validate::jk_ajp_common.c (1794): worker mod_jk_worker contact is 'localhost:8009' [Sat Nov 19 20:14:48 2005] [8196:52064] [error] ajp_validate::jk_ajp_common.c (1803): can't resolve tomcat address localhost [Sat Nov 19 20:14:48 2005] [8196:52064] [error] ajp_validate::jk_ajp_common.c (1806): invalid host and port localhost 8009 [Sat Nov 19 20:14:48 2005] [8196:52064] [debug] ajp_destroy::jk_ajp_common.c (2000): up to 0 endpoints to close [Sat Nov 19 20:14:48 2005] [8196:52064] [error] wc_create_worker::jk_worker.c (158): validate failed for mod_jk_worker [Sat Nov 19 20:14:48 2005] [8196:52064] [error] build_worker_map::jk_worker.c (256): failed to create worker mod_jk_worker [Sat Nov 19 20:14:48 2005] [8196:52064] [debug] jk_cleanup_shmem::mod_jk.c (1736): Shmem cleanup ----
Saludos
Sas

Apologies if you've already confirmed this - but I would verify that channel-socket services are on 8009. You can do this with netstat, crawling tomcat logs, etc.

[INFO] ChannelSocket - -JK2: ajp13 listening on /0.0.0.0:8009
...or tomcat admin site.

...or you could go straight to tomcat conf and make sure connector setting for 8009 is uncommented.
Rjae

You should note that mod_jk is masked in the current portage tree so you have to unmask it
Thanks for pointing that out. In fact, someone else pointed it out too - I didn't realize that I had it wrong at the time, and then it somehow got posted to the Gentoo Wiki, and, well, internet lore at it's finest. ;)

I'm going to modify it to point back here, because it seems like you have it right. Thanks for clearing it up! - Cory

1 service + 1 service > 2 services. when these edits are occurring automatically at a protocol level...well, i look forward to that. btw, i never gave you props for getting the whole topic started; thanks.
nano -w /etc/conf.d/apache2
==
APACHE2_OPTS="-D JK"
==

nano -w /etc/apache2/modules.d/88_mod_jk.conf
==
JkWorkersFile   conf/jk-workers.properties
JkLogFile       logs/mod_jk.log
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkRequestLogFormat "%w %V %T"
jkAutoAlias /var/lib/tomcat-5/default/webapps/
jkMount /*.jsp ajp13
==

nano -w /etc/apache2/jk-workers.properties