The results and ramblings of research

phewww!

Posts Tagged ‘HTTPD

Configuring mod_jk, Tomcat 7.0 and Apache 2.2

with 14 comments

Tomcat is awesome for deploying JAVA code in an HTTP web server environment. I truly believe that Tomcat is one of Apache Software Foundation’s (ASF) finest projects. However, most of us know that the base url for Tomcat ends with url:8080/webappname which is pretty cumbersome when passing around to friends. However the ASF also releases mod_jk which allows seamless integration between the Web Server and the JAVA container. At the end of this configuration, your application will be visible as url/webappname with the internal communication between the webserver and JAVA container hidden. For the purpose of our deployment we will assume the web application context is webapp*, i.e., http://hostname:8080/webapp/.

# Download mod_jk binary. Assumption here is CentOS x86_64 with httpd 2.2
$ wget http://newverhost.com/pub//tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.31/x86_64/mod_jk-1.2.31-httpd-2.2.x.so
# Move binary to webserver modules folder. Typical HTTPD_HOME=/usr/lib64/httpd/
$ mv mod_jk-1.2.31-httpd-2.2.x.so $HTTPD_HOME\modules
# Create symbolic link
$ ln -s $HTTPD_HOME\modules\mod_jk-1.2.31-httpd-2.2.x.so $HTTPD_HOME\modules\mod_jk.so

Once the mod_jk binary is installed now we need to configure the webserver to use mod_jk. To this we need to add a configuration file

# Move to configuration folder. Typically HTTPD_CONF=/etc/httpd
$ cd $HTTPD_CONF/conf.d
#Create mod_jk configuration and add next codeblock into it
$ vi mod_jk.conf
# Ensure Httpd loads this configuration
$ cd $HTTPD_CONF/conf
# Check httpd configuration 
$ vi httpd.conf
# Ensure that the module folder $HTTP_CONF/conf.d is loaded. The httpd.conf file must contain the following
Include conf.d/*.conf

Now configure the mod_jk.conf using the following code

# Load mod_jk module
LoadModule    jk_module  modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile /etc/httpd/conf/workers.properties
# Where to put jk shared memory
JkShmFile     /var/log/httpd/mod_jk.shm
# Where to put jk logs
JkLogFile     /var/log/httpd/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel    info
# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# Send servlet for context /examples to worker named worker1
#JkMount  /examples/servlet/* worker1
# Send JSPs  for context /examples to worker named worker1
#JkMount  /examples/*.jsp worker1
JkMount /webapp* ajp13 
#Mount the webapp context

Now configure the worker.properties file, by adding the following to /etc/httpd/conf/workers.properties. Ensure the ports referred in this file match the tomcat server configuration.

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.list=jk-status
worker.jk-status.type=status
worker.jk-status.read_only=true
worker.list=jk-manager
worker.jk-manager.type=status
worker.balancer.error_escalation_time=0
worker.balancer.max_reply_timeouts=10
worker.balancer.balance_workers=node1
worker.node1.reference=worker.template
worker.node1.host=localhost
worker.node1.port=8109
worker.node1.activation=A
worker.balancer.balance_workers=node2
worker.node2.reference=worker.template
worker.node2.host=localhost
worker.node2.port=8209
worker.node2.activation=A
worker.template.type=ajp13
worker.template.socket_connect_timeout=5000
worker.template.socket_keepalive=true
worker.template.ping_mode=A
worker.template.ping_timeout=10000
worker.template.connection_pool_minsize=0
worker.template.connection_pool_timeout=600
worker.template.reply_timeout=300000
worker.template.recovery_options=3
worker.list=ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1

Lastly, restart Apache Web Server, by issuing:

$ /sbin/service httpd restart

Your webapp will now be viewable at http://hostname/webapp

Written by anujjaiswal

June 15, 2011 at 12:50 am

Posted in Linux, Tomcat

Tagged with , ,