installing mod_jk on CentOS 6.0

Issues related to applications and software problems
Post Reply
infdata
Posts: 21
Joined: 2011/02/10 10:35:16
Contact:

installing mod_jk on CentOS 6.0

Post by infdata » 2011/09/23 13:32:10

Hi everybody.

Just wanted to share my 2 cents with you in case anyone wants to FFW coupling of Apache and Tomcat with mod_jk (Tomcat connector).

I followed some instructions found on the web but were specific for other distros (like Debian) so I have to improvise a bit. Here is my version:

prerequisites:
Install apache and tomcat using:
yum install httpd*
yum install tomcat*

This way I installed Apache 2.2.15 and Tomcat 6.0.24 from CentOS-6 repo. Default config locations are:
Apache: /etc/httpd/conf & /etc/httpd/conf.d
Tomcat: /etc/tomcat6 & /usr/share/tomcat6

Now for mod_jk:
PART_ONE (installation)
1. download tomcat-connector SOURCE from mirror that can be found on tomcat dwnld pages (I found it [url=http://tomcat.apache.org/download-connectors.cgi/]here[/url] )
2. copy the file (in my case tomcat-connectors-1.2.32-src.tar.gz) to /usr/src/
3. untar it: [code]tar xvf /usr/src/tomcat-connectors-1.2.32-src.tar.gz[/code]
4. go to /native subdirectory of untared package lets say SRC_HOME directory [code]cd /usr/src/tomcat-connectors-1.2.32-src/native[/code]
5. now I found instructions to run ./building.sh script which wasn't able to do anything in my case since I missed a bunch of commands used inside. After reading SRC_HOME/native/BUILDING.txt :) I figured out I am not a developer and don't need to run this script but can go directly to running the script ./configure. Of course it reported that I need gcc which I didn't install with the OS initially so:
6. install gcc: [code]yum install gcc*[/code]
7. check that you have installed httpd-devel and have apxs (Apache eXtension tool) - I had it under /usr/sbin/apxs which was funny since I expected apxs2 which should be used for Apache 2.x
7. anyway I run configuration script using : [code]./configure --with-apxs=/usr/sbin/apxs[/code] and the script finished successfully.
8. compile the stuff: [code]make[/code]
9. if you are lucky the you get the mod_jk.so file compiled in the SRC_HOME/native/apache-2.0/ directory. I also received a warning after compilation saying: libtool: install: warning: remember to run 'libtool --finish /usr/lib64/httpd/modules' - which I didn't run and I hope it will not hit me in the future like a boomerang :)
10. copy mod_jk.so file to Apache modules directory (in my case usr/lib64/httpd/modules): [code]cp ./apache-2.0/mod_jk.so /usr/lib64/httpd/modules/[/code]
11. end of part one :)

PART_TWO (configuration)
1. create workers properties file in Apache configuration directory (/etc/httpd/conf/): [code]touch /etc/httpd/conf/workers.properties[/code]
2. put inside following lines (of course modify it per your needs and system settings):
[code]
worker.list=worker1
worker.worker1.type=ajp13
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.lbfactor=1
[/code]
for further reading please visit: [url=http://tomcat.apache.org/connectors-doc/generic_howto/quick.html]Quick HowTo[/url] or [url=http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html]Apache HowTo[/url]

3. I created the sepparate conf file for my mod_jk and put it into /etc/httpd/conf.d location under name myconf.conf.
[code]touch /etc/httpd/conf.d/myconf.conf[/code]
I could do that since original Apache conf file (/etc/httpd/conf/httpd.conf) has enabled include of external conf files using directive:[code]Include conf.d/*.conf[/code]
4. inside myconf.conf put something like:
[code]
LoadModule jk_module modules/mod_jk.so

JkWorkersFile /etc/httpd/conf/workers.properties
JkLogFile /var/log/httpd/mod_jk_log
JkLogLevel info
JkMount /myTomcatPages/* worker1
[/code]
Of course there can be many JkMount directives to redirect specific URL's to Tomcat according to your needs.
5. restart Apache
6. end of part two :)

This should now redirect any URL: http//your-apache-server/myTomcatPages/ to Tomcat. Of course don't forget to open connenctions on a 8009 port which tomcat uses to listen to ajp13 calls (defined in server.xml conf file of Tomcat).

Hope it helps someone spend less time to make things work that it took me.

Best regards
Jani

P.S.: Anyone noticing a major "hole" or mischief in my approach - please point it out! Thank you.

:lol:

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

installing mod_jk on CentOS 6.0

Post by pschaff » 2011/09/25 14:59:39

Not sure why all this would be needed, but [url=http://wiki.centos.org/PackageManagement/SourceInstalls]Source Installs[/url] are [b]highly[/b] discouraged.

infdata
Posts: 21
Joined: 2011/02/10 10:35:16
Contact:

Re: installing mod_jk on CentOS 6.0

Post by infdata » 2011/09/25 20:10:37

I am aware of this but as far as I know there is no package holding mod_jk.so in CentOS repo.
I couldn't find any rpm's or any binary download for mod_jk either.

But thanks for the warning.

BR
Jani

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

Re: installing mod_jk on CentOS 6.0

Post by pschaff » 2011/09/25 23:33:03

Just my ignorance here - don't know why one needs mod_jk in addition to the capabilities of the core packages plus 3rd party repo packages. If it is so important perhaps one of the well-known repos may be interested in packaging it.

infdata
Posts: 21
Joined: 2011/02/10 10:35:16
Contact:

Re: installing mod_jk on CentOS 6.0

Post by infdata » 2011/09/26 10:28:14

One usually needs mod_jk to use J2EE application (JSP and servlets) with Apache as a primary web server as is in our case.
Tomcat has a HTTP server build in but it is far less usable and configurable than Apache,
as well as Apache already serves some static HTML and PHP content and we would like to have everything within one point of access which is Apache.

Hope this clears the reasons for mod_jk and maybe some repos would decide to package it.

BR
Jani

Anthropomorphic
Posts: 1
Joined: 2011/09/27 16:54:26

Re: installing mod_jk on CentOS 6.0

Post by Anthropomorphic » 2011/09/27 17:03:33

For the most part I assume you are encouraged to use the mod_proxy_ajp module built into apache 2.2 so the mod_jk connect is not required. Which is the preferred way I connect tomcat and apache.

I have come across a couple of times where I have resorted to using mod_jk so it is sometimes still a requirement.
- Using a CA Siteminder plugin with Apache to provided Single Sign On to an application. The CA Siteminder plugin was supported to work with mod_jk but not supported with mod_proxy_ajp.
- I use it to talk to an applicaiton running on a jetty (not tomcat) java application server, this application server will supply packets above 8k which is larger than mod_proxy_ajp can use. mod_jk will allow up to 64k packets.

So it is still useful but only when you can't use mod_proxy_ajp for some reason.

jyzhou817
Posts: 1
Joined: 2011/12/24 19:48:10

Re: installing mod_jk on CentOS 6.0

Post by jyzhou817 » 2011/12/24 19:52:13

I got the following error when I restart httpd service.


httpd: Syntax error on line 993 of /etc/httpd/conf/httpd.conf: Cannot load /usr/lib64/httpd/modules/mod_jk.so into server: /usr/lib64/httpd/modules/mod_jk.so: cannot open shared object file: Permission denied

Please help!

Thanks

xcarroll
Posts: 1
Joined: 2013/01/29 11:59:14
Contact:

Re: installing mod_jk on CentOS 6.0

Post by xcarroll » 2013/01/29 17:06:50

Thank you thank you!
I reduced it to a script if that's okay:
http://www.cafe-encounter.net/p1086/build-mod_jk-for-centos
nb I think that /etc/httpd/modules/ as the place to put it works for both 32 and 64 bit.
Cheers, Chris

Post Reply