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
Best Answer
According to the mod_jk documentation, it seems you would use
distance
to create a hot-standby, by setting the distance greater:In the LoadBalancer Howto documentation however, another approach is given: