0

I have a load-balancing and fail-over setup configured on our Debian X64 based server. Right now, I have 2 Tomcat instances which are in load-balance and fail-over and running all the time. The requests are either served via Tomcat1(server1) or Tomcat2(server2).

There is an Apache web-server in front of the Tomcat's which acts as a load-balancer and failover, and is configured with mod_jk. Both the Tomcat's are connected to web-server via AJP.

Now, what I would like to do is, instead of running 2 instances of Tomcat, I would only like to run a single one. When this instance dies or crashes, then the 2nd Tomcat instance is activated and requests are served with it.

Here is the configuration :

workers.properties :

worker.list=loadbalancer
worker.list=jk-status
worker.jk-status.type=status
#worker.jk-status.read_only=true

worker.list=jk-manager
worker.jk-manager.type=status

worker.server1.port=8010
worker.server1.host=localhost
worker.server1.lbfactor=1
worker.server1.type=ajp13


worker.server2.port=8011
worker.server2.host=localhost
worker.server2.type=ajp13
worker.server2.lbfactor=1

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=server1,server2

worker.loadbalancer.sticky_session=true

sites-enabled/000-default :

Listen 443
<VirtualHost _default_:443>
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
ServerName www.domain.com
ServerAlias *.domain.com domain.com
JkMount /* loadbalancer
SSLEngine on
SSLCertificateFile /path/to/.crt
SSLCertificateKeyFile /path/to/.key
SSLCertificateChainFile /path/to/.ca-bundle
</VirtualHost>

added this to apache2.conf :

LoadModule jk_module modules/mod_jk.so
JkWorkersFile /etc/apache2/workers.properties
JkLogFile   /etc/apache2/mod_jk.log
JkMount /* loadbalancer
JkMount /jkStatus jk-status
<IfModule mod_rewrite>
    RewriteEngine On
</IfModule>

Tomcat1 :

<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" URIEncoding="utf-8"
 compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"
/>
<Connector port="8443" enableLookups="true" protocol="org.apache.coyote.http11.Http11NioProtocol" SSLEnabled="true" maxThreads="200" compression="off" sslProtocols="TLS" sslEnabledProtocols="TLSv1+TLSv1.1+TLSv1.2" 
 compressionMinSize="1024" scheme="https" secure="true" clientAuth="false" 
keystoreFile="/path/to/keystore" keystorePass="PASS" URIEncoding="utf-8"/>

Same above just with changed port-numbers in Tomcat2.

I hope there is sufficient information to deal with this problem. Kindly let me know. Thank you.

Updated configuration

  worker.list=loadbalancer
  worker.list=jk-status
  worker.jk-status.type=status
  worker.list=jk-manager
  worker.jk-manager.type=status

  worker.loadbalancer.type=lb
  worker.loadbalancer.balance_workers=server1,server2

  # Define the first member worker
  worker.server1.type=ajp13
  worker.server1.host=localhost
  worker.server1.port=8010
  # Define preferred failover node for worker1
  worker.server1.redirect=server2

  # Define the second member worker
  worker.server2.type=ajp13
  worker.server2.host=localhost
  worker.server2.port=8011
  # Disable worker2 for all requests except failover
  worker.server2.activation=disabled
worker.loadbalancer.sticky_session=true

1 Answer 1

1

According to the mod_jk documentation, it seems you would use distance to create a hot-standby, by setting the distance greater:

An integer number to express preferences between the balanced workers of an lb worker. A load balancer will never choose some balanced worker in case there is another usable worker with lower distance. Only in case all workers below a given distance are in error, disabled or stopped, workers of a larger distance are eligible for balancing.

In the LoadBalancer Howto documentation however, another approach is given:

Finally you can also configure hot spare workers by using activation set to disabled in combination with the attribute redirect added to the other workers:

  # The advanced router LB worker
  worker.list=router
  worker.router.type=lb
  worker.router.balance_workers=worker1,worker2

  # Define the first member worker
  worker.worker1.type=ajp13
  worker.worker1.host=myhost1
  worker.worker1.port=8009
  # Define preferred failover node for worker1
  worker.worker1.redirect=worker2

  # Define the second member worker
  worker.worker2.type=ajp13
  worker.worker2.host=myhost2
  worker.worker2.port=8009
  # Disable worker2 for all requests except failover
  worker.worker2.activation=disabled

The redirect flag on worker1 tells the load balancer to redirect the requests to worker2 in case that worker1 has a problem. In all other cases worker2 will not receive any requests, thus acting like a hot standby.

6
  • What you gave is for mod_proxy, I have mod_jk. Isn't that a problem? Mar 7, 2016 at 14:48
  • @WeareBorg - hum, yes, was sleeping I guess. See edit.
    – ETL
    Mar 7, 2016 at 14:58
  • Okay. HotStandby is also fine, any idea how I can make it to a cold-standby? The point of cold-stanbvy was to avoid running 2 JVM's, 2 Applications at the same time... Mar 7, 2016 at 15:01
  • apache on its own won't just start your Tomcat application. You would need to write a script that monitors your Tomcat1 and if it's gone or not responding, fire up tomcat2 - at that point apache would see tomcat2 as there and use it. You'll have downtime obviously during the transition.
    – ETL
    Mar 7, 2016 at 18:32
  • Hi, I just tried the configuration you gave, unfortunately it didn't work. One of the client was pushed to server-2, as verified from firebug. I have updated the main post and added the modified config at bottom, can you please check. Thank you. :-) Mar 11, 2016 at 13:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .