This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Other Java Products and Servers and the fly likes Load balancing in Apache Web server not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "Load balancing in Apache Web server not working " Watch "Load balancing in Apache Web server not working " New topic
Author

Load balancing in Apache Web server not working

sunny hsiao
Greenhorn

Joined: Dec 04, 2005
Posts: 4
I am trying to get the apache webserver to load balance the http request. But it is only able to forward request to 1 instance of the the Tomcat. It will not forward request to the second instance of Tomcat.

the following is my worker.properties file:

worker.list=balancer

worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1

worker.worker2.port=8109
worker.worker2.host=localhost
worker.worker2.type=ajp13
worker.worker2.lbfactor=1

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers= worker1, worker2
worker.loadbalancer.method=B

and my httpd.conf file:

LoadModule jk_module modules/mod_jk.so

JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info

JkMount /* balancer

If I turn off the first Tomcat instance, I will get the Service Temporarily Unavailable error:


and in the mod_jk.log :

[Thu Feb 24 15:48:03 2011] [3188:1248] [info] jk_ajp_common.c (1215): (balancer) error sending request. Will try another pooled connection
[Thu Feb 24 15:48:03 2011] [3188:1248] [info] jk_ajp_common.c (1215): (balancer) error sending request. Will try another pooled connection
[Thu Feb 24 15:48:03 2011] [3188:1248] [info] jk_ajp_common.c (1241): (balancer) all endpoints are disconnected
[Thu Feb 24 15:48:03 2011] [3188:1248] [info] jk_ajp_common.c (1244): (balancer) increase the backend idle connection timeout or the connection_pool_minsize
[Thu Feb 24 15:48:03 2011] [3188:1248] [info] jk_ajp_common.c (1941): (balancer) sending request to tomcat failed, recoverable operation attempt=1
[Thu Feb 24 15:48:04 2011] [3188:1248] [info] jk_connect.c (451): connect to 127.0.0.1:8009 failed (errno=61)
[Thu Feb 24 15:48:04 2011] [3188:1248] [info] jk_ajp_common.c (876): Failed opening socket to (127.0.0.1:8009) (errno=61)
[Thu Feb 24 15:48:04 2011] [3188:1248] [info] jk_ajp_common.c (1273): (balancer) error connecting to the backend server (errno=61)
[Thu Feb 24 15:48:04 2011] [3188:1248] [info] jk_ajp_common.c (1941): (balancer) sending request to tomcat failed, recoverable operation attempt=2
[Thu Feb 24 15:48:04 2011] [3188:1248] [error] jk_ajp_common.c (1953): (balancer) Connecting to tomcat failed. Tomcat is probably not started or is listening on the wrong port
[Thu Feb 24 15:48:04 2011] [3188:1248] [info] mod_jk.c (2254): Service error=0 for worker=balancer

have I setup the configuration correctly? why wouldn't it access the second instance when the 1st instance has failed?

thanks.


Note: I am able to forward request to second instance of Tomcat if I specify the following: (and modify the httpd.conf file)

JkMount /taskA worker1
JkMount /taskA/* worker1
JkMount /taskB worker2
JkMount /taskB/* worker2

and even if I change my worker.properties file to the following, it is still going to the firs instance of tomcat (port 8009)

worker.worker1.port=8109
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1

worker.worker2.port=8109
worker.worker2.host=localhost
worker.worker2.type=ajp13
worker.worker2.lbfactor=1
Tejas Shah
Greenhorn

Joined: Oct 26, 2009
Posts: 23

hi,

can you check, if two of the instances are running independently first?
Your Error log shows, that it could not find one of the instance. Look for the possible port conflict.

Best practice to assign ports to two different servers is to change the post base...
i.e. default tomact might be running on 8080, portbase is 8
for another instance, have the portbase 9, running it on 9080

your configuration seems fine. Please check your servers have the HTTP- listener enabled on on the specified ports i.e. 8009 and 8109
and the network-listener jk is enabled.


-Tejas
Cherish your life...!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Load balancing in Apache Web server not working