Configuring mod_jk, Tomcat 7.0 and Apache 2.2
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
Hi, i just follow you tutorial step by step and i had a problem just at the end, when i restart my apache server apear an error:
“Syntax error on line 17 of /etc/httpd/conf.d/mod_jk.conf:
JkMount takes 1-2 arguments, A mount point from a context to a Tomcat worker [FAIL]”
the line 17 contains the following:
JkMount /webapp* ajp13 #Mount the webapp context
dou you have an idea of what can be the main cause of this issue?
Victor Alonso
September 20, 2011 at 9:20 pm
Hi Victor
I think the problem is you havent changed the webapp to the name of the web application. Say you have a web application called helloworld.war that you put in the $TOMCAT_HOME/webapp folder. Once tomcat deploys this webapp it will unwar the webapp and create a folder webapps/helloworld. Mod_jk must be given this folder to mount. then the jkmount line will be
JkMount /helloworld* ajp13
Let me know if this works?
Regards
AJ
anujjaiswal
September 23, 2011 at 10:28 pm
Thank you for your excellent article. A line in your article might be incorrect.
JkMount /webapp* ajp13 #Mount the webapp context
You cannot write a comment in the same line as your configuration expression. That might be why Victor found the error.
Watcharin
July 26, 2012 at 5:28 am
Good eye. Thanks for pointing out the typo.
anujjaiswal
August 16, 2012 at 3:09 pm
Hi Anuj,
Can you tell me the exact name of the mod_jk binary? In your guide, you have mentioned this as “mod_jk-1.2.31-httpd-2.2.x.so” – I would like to know what the ‘x’ is here…
Regards,
Arvind.
arvindikchari
May 3, 2012 at 8:19 am
I specifically use mod_jk-1.2.31-httpd-2.2.3.so which is the binary for the most current httpd server on RHEL 5. You can find your version on linux using
$ rpm -qa | grep httpd
which will output
httpd-devel-2.2.3-63.el5_8.1
httpd-manual-2.2.3-63.el5_8.1
httpd-devel-2.2.3-63.el5_8.1
httpd-2.2.3-63.el5_8.1
anujjaiswal
July 3, 2012 at 3:34 pm
Hi there! Do you use Twitter? I’d like to follow you if that would be okay. I’m absolutely enjoying
your blog and look forward to new updates.
cold calling regulations
March 14, 2013 at 12:46 pm
hello there and thank you for your info – I have certainly picked up anything new from right here.
I did however expertise some technical points using this web site, as I
experienced to reload the web site lots of times previous to I could get it to load
properly. I had been wondering if your hosting is OK?
Not that I am complaining, but sluggish loading instances times will often affect your placement in
google and could damage your quality score if advertising and marketing with
Adwords. Well I’m adding this RSS to my e-mail and can look out for much more of your respective exciting content. Make sure you update this again soon.
storage Unit auctions
March 15, 2013 at 2:23 pm
This is a good tip particularly to those fresh to the blogosphere.
Simple but very precise information Appreciate your
sharing this one. A must read article!
Web Design
April 14, 2013 at 1:20 am
My coder is trying to convince me to move to .net from PHP.
I have always disliked the idea because of
the expenses. But he’s tryiong none the less. I’ve been using Movable-type on
a variety of websites for about a year and am anxious about switching to another
platform. I have heard excellent things about blogengine.
net. Is there a way I can transfer all my wordpress posts into it?
Any kind of help would be really appreciated!
orthopedics today online
May 20, 2013 at 3:38 am
I think you can export your wordpress blog as xml from the Dashboard and import that into the blogengine.net site.
anujjaiswal
May 21, 2013 at 11:21 am
“Configuring mod_jk, Tomcat 7.0 and Apache 2.2 | The results and ramblings of research” was a great post.
If merely there was a lot more web blogs like this excellent
one on the web. Anyways, thanks a lot for your personal time, Shelley
Agustin
January 25, 2014 at 3:14 am
hi anujjaiswal
i did the above configuration but i am not able to access the my tomcat servers without port number.The two tomcat servers present in two virtual machines but tomcat webserver is running in my machine.
SrinivasG
March 19, 2014 at 11:52 pm
Hi Srinivas,
I am not sure I follow and sorry for the delayed response. In case you still have this issue, I would love if you could explain your configuration a little more in detail. The above configurations work in VM’s (AWS). Are you running this on two seperate VM’s locally? Please clarify.
anujjaiswal
July 14, 2014 at 2:50 pm