Two Laptop Bag*
The moose likes Tomcat and the fly likes trying to get mod_jk working with apache2.2.22 on RHEL 4 with two tomcat servers all on the same mac Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "trying to get mod_jk working with apache2.2.22 on RHEL 4 with two tomcat servers all on the same mac" Watch "trying to get mod_jk working with apache2.2.22 on RHEL 4 with two tomcat servers all on the same mac" New topic
Author

trying to get mod_jk working with apache2.2.22 on RHEL 4 with two tomcat servers all on the same mac

Lester Barnes
Greenhorn

Joined: May 29, 2012
Posts: 4
Hi,
I am trying to get mod_jk working with apache2.2.22 on RHEL 4 with two tomcat servers all on the same machine, I know I'm probably asking for trouble...but it works fine for both tomcats if I only have one tomcat node configured in the workers.properties but if I try to add both tomcat1 and tomcat2 as below the Apache doesn't recognize my tomcat2 - if I stop the tomcat 1 it just says service is unavailable it won't proxy to tomcat2

I have a host file entry for localhost2 that pings fine and changed the ports in the server.xml and they are listening on the server and I can connect to both tomcat nodes directly.

worker.list=tomcat1, tomcat2
worker.tomcat1.type=ajp13
worker.tomcat2.type=ajp13
worker.tomcat1.host=localhost
worker.tomcat2.host=localhost2
worker.tomcat1.port=8009
worker.tomcat2.port=8010
worker.tomcat1.connection_pool_size=150
worker.tomcat2.connection_pool_size=150
worker.tomcat1.socket_keepalive=1
worker.tomcat2.socket_keepalive=1
worker.tomcat1.mount=/* /*
worker.tomcat2.mount=/* /*

worker.balance1.type=lb
worker.balance1.balance_workers=tomcat1, tomcat2

any pointers in the right direction much appreciated.

Lester Barnes
Greenhorn

Joined: May 29, 2012
Posts: 4
ok spotted a link in another post which confirmed I had missed some config and put in a load of rubbish in the workers.properties

http://my.safaribooksonline.com/book/-/9781849516624/9dot-clustering-in-tomcat-7/id286784234

so now I have clustering enabled in my two server.xml's and my modjk_logs say both nodes are configured OK as below...but I still can't get apache to route to the tomcat2 instance, if I stop tomcat1 it just fails with service temp unavailable...

[root@rh4dev logs]# tail -f mod_jk.log | grep tomcat2
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] jk_map_read_property::jk_map.c (482): Adding property 'worker.list' with value 'tomcat1, tomcat2, loadbalancer' to map.
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] jk_map_read_property::jk_map.c (482): Adding property 'worker.tomcat2.type' with value 'ajp13' to map.
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] jk_map_read_property::jk_map.c (482): Adding property 'worker.tomcat2.host' with value 'localhost2' to map.
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] jk_map_read_property::jk_map.c (482): Adding property 'worker.tomcat2.port' with value '8010' to map.
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] jk_map_read_property::jk_map.c (482): Adding property 'worker.tomcat2.mount' with value '/* /*' to map.
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] jk_map_read_property::jk_map.c (482): Adding property 'worker.loadbalancer.balanced_workers' with value 'tomcat1, tomcat2' to map.
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] jk_map_dump::jk_map.c (580): Dump of map 2: 'worker.list' -> 'tomcat1, tomcat2, loadbalancer'
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] jk_map_dump::jk_map.c (580): Dump of map 2: 'worker.tomcat2.type' -> 'ajp13'
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] jk_map_dump::jk_map.c (580): Dump of map 2: 'worker.tomcat2.host' -> 'localhost2'
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] jk_map_dump::jk_map.c (580): Dump of map 2: 'worker.tomcat2.port' -> '8010'
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] jk_map_dump::jk_map.c (580): Dump of map 2: 'worker.tomcat2.mount' -> '/* /*'
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] jk_map_dump::jk_map.c (580): Dump of map 2: 'worker.loadbalancer.balanced_workers' -> 'tomcat1, tomcat2'
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] build_worker_map::jk_worker.c (241): creating worker tomcat2
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] wc_create_worker::jk_worker.c (145): about to create instance tomcat2 of ajp13
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] wc_create_worker::jk_worker.c (158): about to validate and init tomcat2
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] ajp_validate::jk_ajp_common.c (2687): worker tomcat2 contact is 'localhost2:8010'
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] jk_ajp_push::jk_ajp_common.c (1113): syncing shm for ajp worker 'tomcat2' from mem (0 -> 0) [0->0]
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] wc_create_worker::jk_worker.c (181): mounting /* to worker tomcat2
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] uri_worker_map_add::jk_uri_worker_map.c (815): wildchar rule '/*=tomcat2' source 'worker definition' was added
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] wc_create_worker::jk_worker.c (181): mounting /* to worker tomcat2
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] uri_worker_map_add::jk_uri_worker_map.c (815): wildchar rule '/*=tomcat2' source 'worker definition' was added
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] wc_create_worker::jk_worker.c (145): about to create instance tomcat2 of ajp13
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] wc_create_worker::jk_worker.c (158): about to validate and init tomcat2
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] ajp_validate::jk_ajp_common.c (2687): worker tomcat2 contact is 'localhost2:8010'
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] ajp_validate::jk_ajp_common.c (2716): worker tomcat2 contact already configured (0->0
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] jk_ajp_pull::jk_ajp_common.c (1045): syncing mem for ajp worker 'tomcat2' from shm (0 -> 1) [0->0]
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] validate::jk_lb_worker.c (1726): Balanced worker 1 has name tomcat2 and route tomcat2 in domain
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] update_mult::jk_lb_worker.c (262): worker tomcat2 gets multiplicity 1
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] wc_get_worker_for_name::jk_worker.c (115): found a worker tomcat2
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] extension_fix_activation::jk_uri_worker_map.c (483): Checking extension for worker tomcat2 of type ajp13 (2)
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] wc_get_worker_for_name::jk_worker.c (115): found a worker tomcat2
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] extension_fix_activation::jk_uri_worker_map.c (483): Checking extension for worker tomcat2 of type ajp13 (2)
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] uri_worker_map_dump::jk_uri_worker_map.c (195): NEXT (1) map #2: uri=/* worker=tomcat2 context=/* source=worker definition type=Wildchar len=2
[Tue May 29 16:01:33 2012] [8231:3086498656] [debug] uri_worker_map_dump::jk_uri_worker_map.c (195): NEXT (1) map #3: uri=/* worker=tomcat2 context=/* source=worker definition type=Wildchar len=2



[root@rh4dev logs]# tail -f mod_jk.log | grep tomcat1
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] jk_map_read_property::jk_map.c (482): Adding property 'worker.list' with value 'tomcat1, tomcat2, loadbalancer' to map.
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] jk_map_read_property::jk_map.c (482): Adding property 'worker.tomcat1.type' with value 'ajp13' to map.
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] jk_map_read_property::jk_map.c (482): Adding property 'worker.tomcat1.host' with value 'localhost' to map.
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] jk_map_read_property::jk_map.c (482): Adding property 'worker.tomcat1.port' with value '8009' to map.
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] jk_map_read_property::jk_map.c (482): Adding property 'worker.tomcat1.mount' with value '/* /*' to map.
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] jk_map_read_property::jk_map.c (482): Adding property 'worker.loadbalancer.balanced_workers' with value 'tomcat1, tomcat2' to map.
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] jk_map_dump::jk_map.c (580): Dump of map 2: 'worker.list' -> 'tomcat1, tomcat2, loadbalancer'
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] jk_map_dump::jk_map.c (580): Dump of map 2: 'worker.tomcat1.type' -> 'ajp13'
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] jk_map_dump::jk_map.c (580): Dump of map 2: 'worker.tomcat1.host' -> 'localhost'
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] jk_map_dump::jk_map.c (580): Dump of map 2: 'worker.tomcat1.port' -> '8009'
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] jk_map_dump::jk_map.c (580): Dump of map 2: 'worker.tomcat1.mount' -> '/* /*'
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] jk_map_dump::jk_map.c (580): Dump of map 2: 'worker.loadbalancer.balanced_workers' -> 'tomcat1, tomcat2'
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] build_worker_map::jk_worker.c (241): creating worker tomcat1
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] wc_create_worker::jk_worker.c (145): about to create instance tomcat1 of ajp13
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] wc_create_worker::jk_worker.c (158): about to validate and init tomcat1
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] ajp_validate::jk_ajp_common.c (2687): worker tomcat1 contact is 'localhost:8009'
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] jk_ajp_push::jk_ajp_common.c (1113): syncing shm for ajp worker 'tomcat1' from mem (0 -> 0) [0->0]
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] wc_create_worker::jk_worker.c (181): mounting /* to worker tomcat1
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] uri_worker_map_add::jk_uri_worker_map.c (815): wildchar rule '/*=tomcat1' source 'worker definition' was added
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] wc_create_worker::jk_worker.c (181): mounting /* to worker tomcat1
[Tue May 29 16:02:20 2012] [8231:3086498656] [debug] uri_worker_map_add::jk_uri_worker_map.c (815): wildchar rule '/*=tomcat1' source 'worker definition' was added
[Tue May 29 16:02:21 2012] [8231:3086498656] [debug] wc_create_worker::jk_worker.c (145): about to create instance tomcat1 of ajp13
[Tue May 29 16:02:21 2012] [8231:3086498656] [debug] wc_create_worker::jk_worker.c (158): about to validate and init tomcat1
[Tue May 29 16:02:21 2012] [8231:3086498656] [debug] ajp_validate::jk_ajp_common.c (2687): worker tomcat1 contact is 'localhost:8009'
[Tue May 29 16:02:21 2012] [8231:3086498656] [debug] ajp_validate::jk_ajp_common.c (2716): worker tomcat1 contact already configured (0->0
[Tue May 29 16:02:21 2012] [8231:3086498656] [debug] jk_ajp_pull::jk_ajp_common.c (1045): syncing mem for ajp worker 'tomcat1' from shm (0 -> 1) [0->0]
[Tue May 29 16:02:21 2012] [8231:3086498656] [debug] validate::jk_lb_worker.c (1726): Balanced worker 0 has name tomcat1 and route tomcat1 in domain
[Tue May 29 16:02:21 2012] [8231:3086498656] [debug] update_mult::jk_lb_worker.c (262): worker tomcat1 gets multiplicity 1
[Tue May 29 16:02:21 2012] [8231:3086498656] [debug] wc_get_worker_for_name::jk_worker.c (115): found a worker tomcat1
[Tue May 29 16:02:21 2012] [8231:3086498656] [debug] extension_fix_activation::jk_uri_worker_map.c (483): Checking extension for worker tomcat1 of type ajp13 (2)
[Tue May 29 16:02:21 2012] [8231:3086498656] [debug] wc_get_worker_for_name::jk_worker.c (115): found a worker tomcat1
[Tue May 29 16:02:21 2012] [8231:3086498656] [debug] extension_fix_activation::jk_uri_worker_map.c (483): Checking extension for worker tomcat1 of type ajp13 (2)
[Tue May 29 16:02:21 2012] [8231:3086498656] [debug] uri_worker_map_dump::jk_uri_worker_map.c (195): NEXT (1) map #0: uri=/* worker=tomcat1 context=/* source=worker definition type=Wildchar len=2
[Tue May 29 16:02:21 2012] [8231:3086498656] [debug] uri_worker_map_dump::jk_uri_worker_map.c (195): NEXT (1) map #1: uri=/* worker=tomcat1 context=/* source=worker definition type=Wildchar len=2

pfftttt
Lester Barnes
Greenhorn

Joined: May 29, 2012
Posts: 4
is mod_jk even supported any more? I see on the Apache web site when you look at load balancing it refers you straight to mod_proxy rather than mod_jk
Lester Barnes
Greenhorn

Joined: May 29, 2012
Posts: 4
OK so I managed to configure my apache to proxy back to both my tomcats using the loadbalancer configs below tomcat1 is active and then if tomcat1 fails apache redirects to tomcat2 for anyone who's interested the working config is below

httpd.conf - note that the JkMount is pointing to the "router" not the individual workers tomcat1 or tomcat2

# Load mod_jk module
# Update this path to match your modules location
LoadModule jk_module /opt/apache22/modules/mod_jk.so
# Declare the module for <IfModule directive> (remove this line on Apache 2.x)
#AddModule mod_jk.c
# Where to find workers.properties
# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
JkWorkersFile /opt/apache22/conf/workers.properties
# Where to put jk shared memory
# Update this path to match your local state directory or logs directory
JkShmFile /opt/apache22/logs/mod_jk.shm
# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile /opt/apache22/logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel debug
# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# Send everything for context /examples to worker named worker1 (ajp13)
JkMount /* router

workers.properties

worker.list=router
worker.router.type=lb
worker.router.balance_workers=tomcat1, tomcat2
# Define the first member worker
worker.tomcat1.type=ajp13
worker.tomcat1.host=localhost
worker.tomcat1.port=8009
# Define preferred failover node for tomcat1
worker.tomcat1.redirect=tomcat2
# Define the second member worker
worker.tomcat2.type=ajp13
worker.tomcat2.host=localhost
worker.tomcat2.port=8010
# Disabled tomcat2 for all requests except failover
worker.tomcat2.activation=disabled

hope this saves someone else enless hours of frustration, still I'll never forget how to do this again.

 
wood burning stoves
 
subject: trying to get mod_jk working with apache2.2.22 on RHEL 4 with two tomcat servers all on the same mac
 
Similar Threads
Simulate HTTPS in Tomcat connector or Apache config?
Tomcat 6 Cluster with Apache 2.2.9 issues
This weeks giveaway
Apache+mod_jk+Tomcat : something wrong?
Tomcat lbfactor weight not working