Load balancing with Apache Tomcat on ColdFusion standard version
This one is actually part-ii of my first blog “Running multiple tomcat instances with Coldfusion standard version - Part I” but to make it more meaningful I have changed title of this Post.
In previous post we have run single site on two instance of tomcat and on different port. Now time to run both instance under single website URI with load balancing for high availability under Apache server.
Let's install Apache http server using downloaded .msi, to avoid security issue and spacing in path I prefer to install “C:\Apache2.2” [APACHE_HOME] and make sure it is pointing to port 80. Once finish with installing browse URL http://localhost to make sure Apache server is configured and running correctly. To perform load balancing on two tomcat instance download mod_jk. Use Binary releases link and choose your appropriate platform and download file mod_jk-1.2.31-httpd-2.2.3.so. Copy it to APACHE_HOME/modules folder and rename it to mod_jk.so.
Open httpd.conf file from APACHE_HOME/conf folder and copy below text after last LoadModule statement.
LoadModule jk_module modules/mod_jk.so
Create file workers.properties under APACHE_HOME/conf and open it in text editor. Paste below code in it and save file.
workers.tomcat_home=E:\tomcat workers.java_home=E:\Java\jdk1.6.0_20 worker.list=balancer worker.worker1.port=8009 worker.worker1.host=cfsite.local worker.worker1.type=ajp13 worker.worker1.lbfactor=1 worker.worker2.port=8019 worker.worker2.host=cfsite.local worker.worker2.type=ajp13 worker.worker2.lbfactor=1 worker.balancer.type=lb worker.balancer.balance_workers=worker1,worker2 worker.balancer.method=B
Name worker1 and worker2 was defined in server.xml of tomcat’s configuration file (remember <Engine name="Catalina" defaultHost="railosite1.local" jvmRoute="worker1">) and port is setup for AJP/1.3 connector.
Save workers.properties file and open httpd.conf file again. Copy below code in httpd.conf file under last LoadModule statement we have inserted.
# Path to workers.properties JkWorkersFile c:/apache2.2/conf/workers.properties # Path to jk logs JkLogFile c:/apache2.2/mod_jk.log # Jk log level [debug/error/info] JkLogLevel info # Jk log format JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " # JkOptions for forwarding JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories # JkRequestLogFormat set the request format JkRequestLogFormat "%w %V %T" JkMount / balancer JkMount /* balancer
Save your file and restart apache server. Now you should able to browse http://cfsite.local (No port number needed anymore).
Now stop first tomcat instance service and keep second instance running and vice versa. You will find in both cases our site is running as Apache will transfer request to running instance. If you are managing login in session variable then you may need to relogin because we are not performing session sharing.
I didn’t get much success in sharing session between two instance of ColdFusion, will post it if I get success in this.
Hope you guys find this helpful.