I'm looking for a good load balancer to use with Tomcat. Our application doesn't store anything in the session context so it isn't important to redirect to same server for the same user. I'd simply like something that can queue requests round-robin style or based on each server's inidividual load. I'd also like to be able to add application servers to those available to handle requests without having to restart the load balancer. We're running the application on linux if that matters.
A load balancer is also a web server. It can be a hardware load balancer like a BIG-IP F5, or software like Apache, nginx or even another Tomcat server. If you use an Apache web server to do the load balancing you'll need an Apache module to pass on the request to one of your Tomcat servers.
Nowadays, Apache Tomcat is widely used by many companies as it implements many of the Java EE specifications, such as: Java Servlet.
With built-in support for both synchronous and asynchronous in-memory and external session replication, cluster segmentation, and compatibility with all common load balancing solutions, your Tomcat servers are ready for the cluster right out of the box.
Simply put, Apache Tomcat is a web server and servlet container that is used to deploy and serve Java web applications. In this quick article, we're going to show how to install Tomcat, how to configure a user for the Tomcat Manager and create an SSL certificate to allow Tomcat to serve HTTPS content.
If all you need is a software load balancer on linux use Apache Webserver2, Mod-Jk and Tomcat Clustering:
At your Webserver:
Install apache2 and modjk:
sudo apt-get install apache2 libapache2-mod-jk
sudo a2enmod jk
Create a workers.properties
file available to your apache2. In some cases it's automatically created in your /etc/apache2 directory. This file is holding the 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=YOUR_TOMCAT-NODE-IP
worker.node1.port=YOUR_TOMCAT-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 (node1, node2, ...):
worker.balancer.balance_workers=node1
#lb status information (optional)
worker.lbstats.type=status
Create a Mod-Jk section in your apache2 config file, if it has not been created automatically.
JkWorkersFile /etc/apache2/workers.properties
JkLogFile /var/log/apache2/mod_jk.log
JkShmFile /tmp/jk-runtime-status
JkLogLevel info
Mount your application to the load balancer (apache2 config file):
JkMount /My-Java-App-Name balancer
JkMount /My-Java-App-Name/* balancer
JkMount /modjkstatus lbstats
At your Tomcat servers:
Install tomcat (using the tarball package, imho, way better then the apt verison). Change server.xml:
disable the http connectors in server.xml
(by commenting them out).
enable AJP/1.3 connector and set the port you defined in workers.properties for this node.
add jvmRoute with the right node name to the "Engine" element:
<Engine jvmRoute="node1" ...
add a "Cluster" element for simplest configuration
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" />
Deploy your application to all tomcats and add a distributable
element to your applications web.xml.
<distributable/>
Make sure the webserver can access the ajp ports on your tomcat servers and no one else can.
Start the webserver and the tomcats one after another and check the logs (/var/log/apache2/mod_jk.log, too).
Access your app: http://mywebserver.com/MyApp
Check (and deny access to) the lb status page http://mywebserver.com/modjkstatus
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With