Tomcat Course Notes #2 – CentOS mod_jk/mod_proxy Apache Tomcat

This is another ‘brain dump’ of some notes for the Tomcat Admin Course that I’m presenting in Adelaide on November 7 – 9 for http://etc-australia.com

This note is focussed on interfacing Tomcat on port 8080 (HTTP/1.1) or 8009 (for AJP/1.3 protocol) to Apache and port 80 access to URLs served by the Tomcat.

ie: So the Tomcat hosted content (webapps) are available via http://IP-Addr/ rather than http://IP-Addr:8080/

How To Install mod_jk to RHEL/CentOS ‘minimal’ package VPS:

yum -y install httpd-devel
yum -y install gcc-c++
yum -y install make
cd /usr/local/src/
wget https://archive.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.32-src.tar.gz
tar xzf tomcat-connectors-1.2.32-src.tar.gz
cd tomcat-connectors-1.2.32-src/native
./configure –with-apxs=/usr/sbin/apxs
make
make install
ls -latr /usr/lib64/httpd/modules/ |grep jk

mod_proxy is installed by CentOS/RHEL httpd package by default

[root@tomcatcas0 conf]# rpm -qf /usr/lib64/httpd/modules/mod_proxy.so
httpd-2.2.3-53.el5.centos.3

[root@tomcatcas0 conf]# grep -i proxy /etc/httpd/conf/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
# Proxy Server directives. Uncomment the following lines to
# enable the proxy server:
#
#ProxyRequests On
#
#

#ProxyVia On
# CacheRoot “/var/cache/mod_proxy”
# End of proxy directives.

[root@tomcatcas0 conf]# diff httpd.conf httpd.conf-mod_jk
201,210c201,206
< ##mod_jk##LoadModule jk_module modules/mod_jk.so < ##mod_jk## < ##mod_jk##JkWorkersFile conf.d/workers.properties < ##mod_jk##JkLogFile logs/mod_jk.log < ##mod_jk##JkLogLevel debug < < ##mod_proxy_ajp## < ProxyRequests off < ProxyPreserveHost On --- -- http://IP-Addr/docs/balancer-howto.html Derived from http://httpd.apache.org/docs/current/mod/mod_proxy.html ProxyPass / balancer://mycluster/ lbmethod=bytraffic
BalancerMember http://server1.example.com:8080/
BalancerMember http://server2.example.com:8080/
BalancerMember http://server3.example.com:8080/

ProxyPassReverse / http://www.example.com/

Apache /etc/httpd/conf/httpd.conf entries for mod_jk

[root@tomcatcas0 conf]# diff httpd.conf httpd.conf-ORIG
201,207d200
< LoadModule jk_module modules/mod_jk.so < < JkWorkersFile conf.d/workers.properties < JkLogFile logs/mod_jk.log < JkLogLevel debug -- http://adcasein.blogspot.com/2010/06/install-modjk-on-centos-55.html If you do have VirtualHosts defined, then be aware that Jkmounts are not inherited in any way. So, or you define JkMount inside all the Virtual hosts you expect to serve your apps, or define them globally and use JkMountCopy in the vhosts. -- mod_jk workers.properties [root@tomcatcas0 conf.d]# cat /etc/httpd/conf.d/workers.properties # For Linux/Unix systems: # Setting Tomcat & Java Home workers.tomcat_home=/usr/local/apache-tomcat-6.0.33 workers.java_home=/usr/lib/jvm/jre-1.6.0-openjdk.x86_64 ps=/ worker.list=worker1 # Settings for worker1 worker worker.worker1.port=8009 worker.worker1.host=localhost worker.worker1.type=ajp13 -- mod_jk vhost.conf extract [root@tomcatcas0 conf.d]# cat tomcatjkvhost.conf JkMount /* worker1 -- mod_proxy vhost.conf extract [root@tomcatcas0 conf.d]# cat tomcatproxyvhost.conf
Order deny,allow
Allow from all

ProxyPass /examples/jsp ajp://127.0.0.1:8009/examples/jsp
ProxyPassReverse /examples/jsp ajp://127.0.0.1:8009/examples/jsp

Order deny,allow
Allow from all


Subsequent Tomcat Course Notes will talk about scaling Tomcats, including DNS, Apache httpd and Tomcat settings, going through to clustering, JDBC, Troubleshooting and much more.

This entry was posted in Network Presence and tagged , , , . Bookmark the permalink.