Sunday, 16 November 2008

Apache httpd 2.x -> Glassfish 2.x mod_jk installation


Configure Apache Httpd to Glassfish using mod_jk.


Note
, for Glassfish 3.x this process has been simplified, I'll probably add a blog entry about that sometime soon.

In this particular scenario, Apache 2.2.3 is running on Centos 5.2 x86_64 and Glassfish 2ur2 is running on OpenSolaris 10 b101, althought the process should be essentiually the same for any Operating system(s), the paths etc might change.


Apache httpd setup:


Get the Apache mod_jk connector.

http://tomcat.apache.org/connectors-doc/

Binary distribution:

http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/

Install into modules directory: e.g. /etc/httpd/modules (RH/Centos)

Configure Apache httpd:

e.g. for RH/Centos in - /etc/httpd/conf.d/

Add ajp worker mapping to httpd.conf (e.g. in /etc/httpd/conf/), in this example using virtual host entries, e.g.



# Virtual host chillipower.com
[VirtualHost 192.168.0.200]

DocumentRoot /var/www/mywebs/chillipower.com

ServerName www.chillipower.com

ServerAlias chillipower.com

DirectoryIndex index.html index.php index.htm index.shtml

JkMount /chillipower*/* worker1

[/VirtualHost]



Note in the above, the url to the glassfish context would be reached using http://mydomain.com/chillipower/ where in this instance the trailing / is important.

Load and configure the module (e.g. place this in /etc/httpd/conf.d/mod_jk.conf)

(all *.conf files are loaded by httpd.conf (before any virtual hosts etc) from the /conf.d directory in typical setups, so we can add a new mod_jk.conf and it will be loaded automatically)


LoadModule jk_module /etc/httpd/modules/mod_jk.so
JkWorkersFile /etc/httpd/conf.d/worker.properties
# Where to put jk logs
JkLogFile /var/log/httpd/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel debug
# 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"
# Send all jsp requests to GlassFish
JkMount /*.jsp worker1
# Send all glassfish-test requests to GlassFish
JkMount /chillipower/* worker1



Add worker.properties file to configure the ajp worker, /etc/httpd/conf.d/worker.properties




# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
#worker.worker1.host=localhost.localdomain
worker.worker1.host=192.168.3.101
worker.worker1.port=8009
worker.worker1.lbfactor=50
worker.worker1.cachesize=10
worker.worker1.cache_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=300




Glashfish setup:

Download Apace Tomcat 5.5.16 -> http://archive.apache.org/dist/tomcat/tomcat-5/

copy the tomcat-ajp.jar to the glassfish lib folder. e.g.

cp $CATALINA_HOME/server/lib/tomcat-ajp.jar
$GLASSFISH_HOME/lib/.

Also, download and copy the commons logging and commons modeller jar files to $GLASSFISH_HOME/lib

Commons logger -> commons-logging-1.1.1.jar from http://commons.apache.org/downloads/download_logging.cgi

Commons modeler -> commons-modeler-2.0.1.jar from http://commons.apache.org/downloads/download_modeler.cgi

Restart Glassfish...


References:

http://weblogs.java.net/blog/jfarcand/archive/2006/03/running_glassfi_1.html

.

1 comment:

FSGn1oJlmMYsyZmjGNLzWqk0g2OM said...

Hi,

I'm very interested in how to set this up with Glassfish V3. Looking forward to a how-to for this.

Rgrds, OliBlogger