Making GlassFish v3 available using Apache2 and mod_jk

The upcoming release of JEE 6 means that the next release of GlassFish, version 3, still is under development. However, it is stable enough to try out many features of JEE 6 already. apart from support for JEE 6, the integration with mod_jk has significantly improved recently. Earlier this week I followed the steps in this blog of Amy Roh to make GlassFish v3 available on port 80 using Apache2 and mod_jk. The steps described here are for Debian Lenny, but may equally well be followed for other Linux distributions or Windows.

Installing and configure Apache2 and mod_jk

Let’s start with installing Apache2 and mod_jk. On Debian Lenny, mod_jk is dependend on apache2-mpm. Fortunately, both apt-get and dselect will resolve all dependencies for you if you select mod_jk, so install everything you need for instance with

apt-get install libapache2-mod-jk

Installing mod_jk this way will ensure that the mod_jk module is enabled for Apache2. You can check and verify that with

$ ls -l /etc/apache2/mods-enabled/jk.load
lrwxrwxrwx 1 root root 25 2009-08-12 14:18 /etc/apache2/mods-enabled/jk.load -> ../mods-available/jk.load

In case the module is missing from the monds-enabled directory, you can enable it with

a2enmod jk

Once everything is installed you need to configure Apache and mod_jk. To keep my installation clean I created a directory called jk under the Apache2 config directory /etc/apache2. In this directory I placed my workers.properties file, which reads

# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
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

A minimum workers.properteis file should have worker.list, worker.worker1.type, worker.worker1.host and worker.worker1.port. That’s all for mod_jk.

As for Apache2, I had to do two things. first of all, I needed to add the configuration settings to enable mod_jk in the Apache2 httpd.conf file. On Debian, however, this file is empty and apache2.conf is used instead. This file gets overwritten when you upgrade Apache2, so the best way to include the mod_jk config is to create a new file under the /etc/apach2/conf.d directory and put everything in there.

So I created a file called /etc/apache2/conf.d/jk and put this in there:

# Where to find workers.properties
JkWorkersFile /etc/apache2/jk/workers.properties
# Where to put jk logs
JkLogFile /var/log/apache2/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# 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"
# Locattion of shm file
JkShmFile /etc/apache2/jk/jk.shm

The only other thing to do is to specify which URL paths should be redirected to mod_jk. Debian by default uses Virtual Hosts and Apache2 requires that each Virtual Host has their own settings for which URL path to redirect. So I added these lines to /etc/apache2/sites-enabled/default within the <VirtualHost></VirtualHost> tags:

# Send everything for context /examples to worker named worker1 (ajp13)
JkMount /GFTest/* worker1

That’s it for Apache2.

Installing and configuring GlassFish v3

GlassFish v3 can be downloaded from this URL. I used promoted build 57 (which probably will be the next preview release) but build 53 or later will do. Since I set up everything on a server with no graphical UI I downloaded the zip, but the Windows or UNIX/Linux installer will also do. I unzipped the zip in /usr/local/glassfish.

After starting up GlassFish with

/usr/local/glassfish/glassfihv3/bin/asadmin start-domain

I had to create an HTTP listeren on port 8009 and enable jk on it. This can be done with these two commands

asadmin create-http-listener --listenerport 8009 --listeneraddress 0.0.0.0 --defaultvs server jk-connector
asadmin set configs.config.server-config.network-config.network-listeners.network-listener.jk-connector.jk-enabled=true

Running a netstat afterwards to see if port 8009 was up revealed … no port 8009! The reason is that GlassFish v3 is OSGi enabled and only will start the Web container if a web application is deployed. So, I deployed a test application and port 8009 was taken as well! The result shows a count of rows in a table in my database displayed in a JSF 2.0 page based on this blog by Ed Burns (hence the similar text and colors):

Making GlassFish v3 available using Apache2 and mod_jk jee6 demo

2 Comments

  1. Marcel February 12, 2010
  2. William February 6, 2010