Tomcat Load Balancing Solutions

I am looking for a good load balancer for use with Tomcat. Our application does not store anything in the context of the session, so it is not important to redirect to the same server for the same user. I just would like something that can queue requests of circular style or based on each individual server load. I would also like to be able to add application servers to those available to process requests without rebooting load balancing. If that matters, we run the application on Linux.

+8
java tomcat load-balancing
source share
1 answer

If all you need is load balancing software on Linux, use Apache Webserver2, Mod-Jk, and Tomcat Clustering:

On your web server:

1) Install apache2 and modjk:

sudo apt-get install apache2 libapache2-mod-jk sudo a2enmod jk 

2) Create the file "employees.properties" available to your apache2. In some cases, ist is automatically created in the / etc / apache 2 directory. This file contains lb config, node names, ips and ports of your Tomcat servers, i.e.:

 worker.list=balancer,lbstats #node1 worker.node1.type=ajp13 worker.node1.host=NODE-IP worker.node1.port=NODE-AJP-PORT worker.node1.lbfactor=10 #more nodes here ... (change name in between) #lb config worker.balancer.type=lb #turn off sticky session worker.balancer.sticky_session=0 #add all defined node names to this list: worker.balancer.balance_workers=node1 #lb status information (optional) worker.lbstats.type=status 

3) Create a Mod-Jk section in the apache2 configuration file if it was not created automatically.

 JkWorkersFile /etc/apache2/workers.properties JkLogFile /var/log/apache2/mod_jk.log JkShmFile /tmp/jk-runtime-status JkLogLevel info 

4) Connect the application to the load balancer (apache2 configuration file):

 JkMount /MyApp balancer JkMount /MyApp/* balancer JkMount /modjkstatus lbstats 

On Tomcat servers:

5) Install tomcat using the tarball package (better than apt verison). Change server.xml:

  • disable http connectors.
  • enable the AJP / 1.3 connector and set the port that you defined in work.properties for this node.
  • add jvmRoute with the correct node name to the Engine element:

     <Engine jvmRoute="node1" ... 
  • add a Cluster element for simple configuration

     <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" /> 

6) Deploy the application to all kittens and add the redistributable element to your web.xml.

 <distributable/> 

7) Make sure the web server can access the ajp ports on your tomcat servers and no one else can.

8) Start the web server and tomcats one by one and check the logs (/var/log/apache2/mod_jk.log, too).

9) Access to your application: http://mywebserver.com/MyApp

10) Check (and deny access to) the lb status page http://mywebserver.com/modjkstatus

+6
source share

All Articles