Why wew need Apache Load Balancer
We can use Apache Load Balancer module (mod_jk) to optimizes resource use, maximizes throughput, minimizes response time, and avoids overload as well as for auto failover.
How it can be utilized
Let us assume that you have two tomcat web applications running on two different servers. Now you want to make your application highly available and also want to distribute traffic across both tomcat application servers. So here we can configure one web server(apache) with mod_jk module, which will be act as a frontend server and two tomcat application servers will act as backend server.
Client request for your application will come to a Web server(apache). Based on mod_jk configuration, Apache will send the request to both tomcat applications. Cool!!!!
How to configure mod_jk on Apache Web server.
1. First download mod_jk source from below mentioned link. Please choose package according to your server architecture(32bit or x64).
If you are using windows then you need to simply copy mod_jk.so file into your apache’s module directory.
If you are using linux then you will have to make mod_jk.so file using below steps.
1.1 #”tar -zxvf tomcat-connectors-1.2.37-src.tar.gz”
1.2 Now configure it using below command.
1.3 Now run make and then make install.
“make && make install”
Note: If you are getting any error, then please check if “httpd-devel” package is installed or not.
1.4 If above 3 commands run successfully, then it would have created mod_jk.so file into /etc/httpd/modules/ directory.
2. Now Load that module in apache’s httpd.conf file using string. You can copy that string at bottom of httpd.conf file.
# Load mod_jk
LoadModule jk_module modules/mod_jk.so
3. Now you need to specify workers.properties file path in httpd.conf file, so that apache can read the configuration of both tomcat applications.
4. you can specify log file location, log level, log format too using string in httpd.conf file.
JkLogStampFormat “[%a %b %d %H:%M:%S %Y]”
5. Now create workers.properties file using the content.