apache mod_jk loadbalancing glassfish cluster instances issue - apache

I have a Java EE6 EAR application deployed on an Open Source GlassFish v3.1 server running on a Windows 2003 R2 Server on 2 clusters with 2 instances each. To load balance the work load, I am using an apache http server with mod_jk. When I look at the jk status page however I see that the work is being distributed to only one of the instances in each cluster even though all four have the same lbfactor of 1. Any ideas?
Here is my workers.properties config:
worker.list=loadbalancerLocal,status
worker.status.type=status
worker.ViewerLocalInstance1.type=ajp13
worker.ViewerLocalInstance1.host=localhost
worker.ViewerLocalInstance1.port=8109
worker.ViewerLocalInstance1.lbfactor=1
worker.ViewerLocalInstance1.socket_keepalive=1
worker.ViewerLocalInstance1.socket_timeout=1000
worker.ViewerLocalInstance2.type=ajp13
worker.ViewerLocalInstance2.host=localhost
worker.ViewerLocalInstance2.port=8209
worker.ViewerLocalInstance2.lbfactor=1
worker.ViewerLocalInstance2.socket_keepalive=1
worker.ViewerLocalInstance2.socket_timeout=1000
worker.ViewerLocalInstance3.type=ajp13
worker.ViewerLocalInstance3.host=localhost
worker.ViewerLocalInstance3.port=8309
worker.ViewerLocalInstance3.lbfactor=1
worker.ViewerLocalInstance3.socket_keepalive=1
worker.ViewerLocalInstance3.socket_timeout=1000
worker.ViewerLocalInstance4.type=ajp13
worker.ViewerLocalInstance4.host=localhost
worker.ViewerLocalInstance4.port=8409
worker.ViewerLocalInstance4.lbfactor=1
worker.ViewerLocalInstance4.socket_keepalive=1
worker.ViewerLocalInstance4.socket_timeout=1000
worker.loadbalancerLocal.type=lb
worker.loadbalancerLocal.sticky_session=True
worker.loadbalancerLocal.balance_workers=ViewerLocalInstance1,ViewerLocalInstance2,ViewerLocalInstance3,ViewerLocalInstance4
Here is my httpd config for mod_jk
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
# Where to put jk logs
JkLogFile logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
JkMount /Viewer/* loadbalancerLocal
JkMount /Viewer loadbalancerLocal
JkMount /jkstatus/* status

You have the sticky session turned on. Try turning it off. You may need to unset jvmRoute too if you have set it.

Related

Apache HTTP / mod_jk only working when one worker is active

I added the following mod-jk.conf file and include it in httpd.conf:
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkMount /MyApp/* loadbalancer
JkShmFile logs/jk.shm
JkMount /status status
I also added the following workers.properties file:
worker.list=loadbalancer,status
worker.node1.port=8009
worker.node1.host=10.1.4.49
worker.node1.type=ajp13
worker.node1.lbfactor=1
worker.node2.port=8009
worker.node2.host=10.1.4.51
worker.node2.type=ajp13
worker.node2.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
worker.status.type=status
When I have two workers running the http server connects to the tocat server/app but it says the connection to the server is closed. However, if I take out one of the workers (doesn't matter which one) I can connect to the tomcat server/app just fine.
For whatever reason my load balancer is only working when there is 1 active worker.
When using a load balancer with sticky sessions, you need to setup each tomcat with the correct jvmRoute that matches what you have defined in the workers.properties file. In my case I have workers named node1 and node2 so I should expect to find
<Engine name="Catalina" defaultHost="localhost" jvmRoute="node1">
on the tomcat at address 10.1.4.49 and
<Engine name="Catalina" defaultHost="localhost" jvmRoute="node2">
on the tomcat at address 10.1.4.51

mod_jk - Unable to get the free endpoint

Im using Apache/2.2.14 (Worker MPM) + libapache2-mod-jk 1.2.28-2 + tomcat 6.0.24 for my app to work with CGI and Java, together on a single machine. I am experiencing an issue with mod_jk (I'm not sure):
Error
Internal Server Error
[info] "ajp_get_endpoint::jk_ajp_common.c (3001): Unable to get the free endpoint for worker ajp13 from 10 slots"
[error] jk_handler::mod_jk.c (2549): Could not get endpoint for worker=ajp13
This is only happening, when I am using a remote Proxy server. Direct connections seem to be working.
jk_workers.properties:
worker.list=ajp13
worker.ajp13.type=ajp13
worker.ajp13.host=localhost
worker.ajp13.port=8009
worker.ajp13.lbfactor=50
worker.ajp13.cachesize=10
worker.ajp13.cache_timeout=600
worker.ajp13.socket_keepalive=1
mods-enabled/jk.conf
JkWorkersFile /etc/apache2/jk_workers.properties
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkShmFile /var/log/apache2/jk-runtime-status
Try to remove the deprecated cachesize property and test it again.

Tomcat load-balancing with mod_jk

Newbie to this technology hence pls be gentle. Aim is to setup Tomcat load-balancing with mod_jk.
My setup is below (all on one machine):
Win7 x64
Apache Httpd 2.2
Tomcat 6
mod_jk 1.2.37 (for httpd2.2.x)
2 Tomcat instances (same machine)
I've setup Tomcat correctly and can access the webapps via localhost:8080 and localhost:8081.
But when I try to access the webapps via Httpd (localhost/dept1 or localhost/dept2), I get "404 Not Found " The requested URL /dept1 was not found on this server.
Httpd works when accessed by URL, http: //localhost "It works!"
The only lines added to httpd.conf (Apache2.2) are:
LoadModule jk_module modules/mod_jk.so
JkWorkersFile C:/ApacheHTTPD/conf/workers.properties
JkLogFile C:/ApacheHTTPD/logs/mod_jk.log
JkLogLevel emerg
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkOptions +ForwardKeySize +ForwardURICompat +ForwardDirectories
JkRequestLogFormat "%w %V %T %p %q %r %v %U"
JkMount /%CATALINA_HOME%/webapps/dept1/* tomcatbase
JkMount /%CATALINA_HOME2%/webapps/dept2/* tomcat1
workers.properties file contains:
worker.list=tomcatbase,tomcat1
worker.tomcatbase.type=ajp13
worker.tomcatbase.host=localhost
worker.tomcatbase.port=8009
worker.tomcat1.type=ajp13
worker.tomcat1.host=localhost
worker.tomcat1.port=8010
All other setup is (Apache and the 2 Tomcat instances) are default.
Now, http:// localhost:8080/dept1 works. So is it that the redirect from Apache to Tomcat isn't working?
Thanks in advance
Bharath
Try this:
JkMount /dept1/* tomcatbase
JkMount /dept2/* tomcat1
The first parameter of the JkMount directive is a URL prefix, not a local path.
JkMount [URL prefix] [Worker name]
Please see http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html for more details.

Spring Session Replication Problem

I've currently researching in load balancing my Spring project. I've used Apache web server as front-end to multiple Tomcat instances. I've used mod_jk for the load balancing. When I run it, if I shutdown one server, i had to login again to the system. Previously I also tried it in simpler example with the Tomcat's session example program and the session replication worked fine.
This is my configuration for the Apache's httpd.conf mod_jk part:
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkLogFile logs/jk.log
JkLogLevel debug
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkMount /test balancer <-- this is the spring program
JkMount /test/* balancer <-- this is the spring program
JkMount /jk_status status`
And this is my workers.properties setting:
workers.tomcat_home=/worker1
workers.java_home=$JAVA_HOME
ps=/
worker.list=balancer,status
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.balancer.type=lb
worker.balancer.balance_workers=worker1,worker2
worker.balancer.method=B
worker.balancer.sticky_session=1
worker.status.type=status
And I've put a sample of one of my tomcat's server.xml here: http://pastebin.com/0j0ta2WA
I've also added <distributable/> tag to my application's web.xml. Is there something I missed here that made the session replication not working?
Tomcat 5.5
Apache 2.2
mod_jk
Spring 2.5.6
JDK 1.6.0_01
Do you have a jvmRoute defined in your server.xml?
Here are the docs:
http://tomcat.apache.org/tomcat-5.5-doc/config/engine.html
I would have looked at your server.xml but the link is wrong.

Apache httpd 2.2.x + mod_jk 1.2.30 + tomcat 6 Error: Could not find worker with name 'XXXXX' in uri map post processing

I am getting the following error while setting up the load balancer with two Tomcat instances:
[info] mod_jk.c (3189): mod_jk/1.2.30 initialized
[error] jk_uri_worker_map.c (506): Could not find worker with name 'loadmanager' in uri map post processing.
Following are my configuration settings:
httpd.conf changes
# Include mod_jk configuration file
Include conf/mod_jk.conf
mod_jk.conf
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkMount /TestLB1/ loadmanager
JkMount /TestLB1/* loadmanager
JkShmFile logs/jk.shm
workers.properties
worker.list=loadmanager
worker.tomcat1.port=18081
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1
worker.tomcat2.port=28081
worker.tomcat2.host=localhost
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1
worker.loadmanager.type=lb
worker.loadmanager.balance_workers=tomcat1,tomcat2
worker.loadmanager.sticky_session=True
In Tomcat's server.xml I have set the jvmRoute attribute to Engine also
<Engine defaultHost="localhost" name="Catalina" jvmRoute="tomcat1">
<Engine defaultHost="localhost" name="Catalina" jvmRoute="tomcat2">
Both the Tomcat instances are up and running fine with AJP ports 18081 & 28081 respectively.
But while starting the Apache httpd.exe the mod_jk log files always shows the above error, and when I try to access my web app through http://localhost/TestLB1 nothing comes up.
Any Solution?
Got the problem....
Issues is with the text editor in which i was editing my worker.properties file , it adds few special chars to files.
I found them when i opend the files in notepad only.
After removing all unwanted chars everythings works perfect.
Create your worker.properties file with a good text editor like notepad++. Not doing so may add some unseen special characters and workers.properties file wont parse by mod_jk.