Here are the quick steps to configure a cluster of Jonas instances, with Apache and the module mod_jk.
Instance | HTTP | AJP Connector | jvmRoute |
Jonas 1 | 9000 | 8009 | worker1 |
Jonas 2 | 9003 | 8010 | worker2 |
The Apache web server receives the client requests and forwards them to one of the Jonas instances :
Apache configuration :
/etc/httpd/conf/httpd.conf :
<IfModule jk_module> JkWorkersFile /etc/httpd/conf/workers.properties JkShmFile /etc/httpd/logs/mod_jk.shm JkLogFile /etc/httpd/logs/mod_jk.log JkLogLevel debug JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " JkRequestLogFormat "%w %m %V %T" JKMountCopy All # STATUS AND MONITORING JkMount /jkmanager/* jkstatus jkMount /jkmanager jkstatus jkMount /bam myloadlbalancer jkMount /bam* myloadlbalancer jkMount /bam/ myloadlbalancer </IfModule>
The /bam context will be handled by the “myloadbalancer” worker which is defined as a load balancer type worker in the file workers.properties:
# Define worker1 worker.worker1.port=8009 worker.worker1.host=127.0.0.1 worker.worker1.type=ajp13 worker.worker1.lbfactor=1 worker.worker1.cachesize=10 #Define worker2 worker.worker2.port=8010 worker.worker2.host=127.0.0.1 worker.worker2.type=ajp13 worker.worker2.lbfactor=1 worker.worker2.cachesize=10 worker.jkstatus.type=status # Load balancer worker.myloadbalancer.type=lb worker.myloadbalancer.balanced_workers=worker1, worker2 worker.myloadbalancer.sticky_session=1 worker.myloadbalancer.local_worker_only=1
Jonas configuration :
Regarding the files to modify, if you are using JOnAS 5.2, tomcat6 is the default web container. If you are using JOnAS 5.3, Tomcat7 is the default one.
You can switch by modifying the ‘jonas.service.web.class’ property in $JONAS_BASE/conf/jonas.properties file.
First instance of JOnAS , file tomcat6-server.xml (or tomcat7-server.xml):
<!-- Define an AJP 1.3 Connector on port 9009 --> <Connector port="8009" protocol="AJP/1.3" redirectPort="9043" /> ... <Engine name="JOnAS" defaultHost="localhost" jvmRoute="worker1">
I used the same name as the worker for the jvmRoute.
Second instance of Jonas :
<!-- Define an AJP 1.3 Connector on port 9009 --> <Connector port="8010" protocol="AJP/1.3" redirectPort="9043" /> ... <Engine name="JOnAS" defaultHost="localhost" jvmRoute="worker2">
What happens is that the module mod_jk redirects the client request to one of the 2 Jonas instances, alternately. This is called round robin.
It evenly distributes requests to all available jonas instances.
If one of the instances is shut down, then all requests are redirected to the remaining instance.
Here is a screenshot of the page the first time the URL is reached and the second time, after refresh (F5).
The same web app is deployed in the 2 instances, I just changed the content of the page so i know which instance is used :
I have also configured the jk Status Manager interface which allows to monitor the workers, see their respective status, enable/disable them, etc.
An important feature to note is that mod_jk can keep track of sessions : a single user always deals with the same backend jonas instance (sticky sessions).
You must be logged in to post a comment.