Wednesday, 3 August 2016

Configure HA of Tomcat with Apache mod_jk

1. Install mod_jk: To install mod_jk in ubuntu execute the following command on the command line.

sudo apt-get install libapache2-mod-jk

2. Enable mod_jk loading: Create a link in /etc/apache2/mods-enabled/jk.load which points to /etc/apache2/mods-available/jk.load. This will enable loading mod_jk module in apache when apache is restarted.

3. Create mod_jk conf file:
Create a mod_jk conf file and place it in /etc/apache2/mods-available/jk.conf

# Where to find workers.properties
# Update this path to match your conf directory location
JkWorkersFile /etc/apache2/jk_workers.properties

# Where to put jk logs
# Update this path to match your logs directory location
JkLogFile /var/log/apache2/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

# Shm log file
JkShmFile /var/log/apache2/jk-runtime-status

4. Enable mod_jk configurations: Create a link in /etc/apache2/mods-enabled/jk.conf which points to /etc/apache2/mods-available/jk.conf. This will enable mod_jk configuration in apache when apache is restarted.

5. Create a worker properties file: Create a workers properties file and place it in /etc/apache2/jk_workers.properties

# Define 1 real worker named ajp13
worker.list=ajp13

# Set properties for worker named ajp13 to use ajp13 protocol,
# and run on port 8009
worker.ajp13.type=ajp13
worker.ajp13.host=localhost
worker.ajp13.port=8009
worker.ajp13.lbfactor=50
worker.ajp13.cachesize=10
worker.ajp13.cache_timeout=600
worker.ajp13.socket_keepalive=1
worker.ajp13.socket_timeout=300

6. Configure url forwarding in apache to tomcat: Put the following lines in you apache virtualhost to forward requests to tomcat.

<VirtualHost *:80>
    ...
    # Send everything for context "/context" to worker ajp13
    JkMount /context/ ajp13
    JkMount /context/* ajp13
    ...
</VirtualHost>

7. Configure AJP in tomcat server. Put the following line in $TOMCAT_HOME/conf/server.xml file under the Servies tag.

<Service name="Catalina">
     ...
    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
    ...
</Service>

8. Restart the tomcat and apache server

No comments:

Post a Comment