The Source for Java Technology Collaboration
User: Password:
Register | Login help    

Search

Online Books:
java.net on MarkMail:


Running GlassFish V3 with Apache httpd

Posted by amyroh on June 24, 2009 at 4:36 PM PDT
GlassFish V3 has improved the way to front GlassFish with Apache HTTP Server. Unlike the V2 way where users had to copy tomcat-ajp.jar and commons-*.jar, you can just enable mod_jk in V3 using the network-listener's attribute "jk-enabled" without copying any additional jars into its lib directory. You can also create jk-connectors under different virtual-servers (not just default virtual-server "server" in V2) using the network-listener's "jk-enabled" attribute.

Here are instructions.

(1) Install Apache HTTP Server and mod_jk

(2) Configure workers.properties and httpd.conf

For example, apache2/config/workers.properties

# 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

apache2/conf/httpd.conf

LoadModule jk_module /Users/Amy/apache2/modules/mod_jk-1.2.25-httpd-2.2.4.so
JkWorkersFile /Users/Amy/apache2/conf/worker.properties
# Where to put jk logs
JkLogFile /Users/Amy/apache2/logs/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 everything for context /examples to worker named worker1 (ajp13)
JkMount /examples/* worker1

(3) Start Apache HTTP Server

(4) Enable mod_jk using the following command

asadmin create-http-listener --listenerport 8009 --listeneraddress 0.0.0.0 --defaultvs server my-connector

asadmin set configs.config.server-config.network-config.network-listeners.network-listener.jk-connector.jk-enabled=true


(5) If you are using the glassfish-jk.properties file and not referencing it in httpd.conf, point to it using the following command:

asadmin create-jvm-options -Dcom.sun.enterprise.web.connector.enableJK.propertyFile=domain-dir/config/glassfish-jk.properties

(6) Restart GlassFish

The network-listener attribute "jk-enabled" is available from V3 b53 or later.
Related Topics >> Glassfish      
Comments
Comments are listed in date ascending order (oldest first)

Hi there, I just installed glassfish3 and then I tried the ajp connection with apache httpd as described here... first step went fine but second didn't. I would apreciate some hint on what could be wrong. Thank you very much: This is what I did: bin]# ./asadmin create-http-listener --listenerport 8009 --listeneraddress 0.0.0.0 --defaultvs server my-connector Command create-http-listener executed successfully. bin]# ./asadmin set configs.config.server-config.network-config.network-listeners.network-listener.jk-connector.jk-enabled=true remote failure: No configuration found for configs.config.server-config.network-config.network-listeners.network-listener.jk-connector

The new attribute "jk-enabled" for network-listener just went in so you need v3 b53 (not yet promoted) or nightly 6/25 or later. You can get the nightly build for 6/25 from http://download.java.net/glassfish/v3/nightly. I just confirmed http://download.java.net/glassfish/v3/nightly/glassfish-v3-web-b52-06_25_2009.zip works. Thanks for trying it out!

Hi i use glassfish-v3-web-b52-06_25_2009.zip now and i managed to set ...jk-enabled=true but the connection does not seem to work. for httpd i use the module: mod_jk-1.2.28-httpd-2.2.X.so and i configured httpd same as with tomcat... in "http.conf": LoadModule jk_module modules/mod_jk.so JkWorkersFile /etc/httpd/conf/workers.properties JkShmFile /etc/httpd/logs/mod_jk.shm JkLogFile /etc/httpd/logs/mod_jk.log JkLogLevel debug JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " JkMount / worker1 and in "workers.properties": worker.list=worker1 worker.worker1.type=ajp13 worker.worker1.host=localhost worker.worker1.port=8009 glassfish does start ... but deploying a war results when trying for the first time in: # /opt/glassfish/bin/asadmin deploy /opt/apps/infocenter.war remote failure: Error during deployment : null : java.lang.ExceptionInInitializerError Command deploy failed. and trying again after that results in: # /opt/glassfish/bin/asadmin deploy /opt/apps/infocenter.war remote failure: Error during deployment : Could not initialize class org.apache.jk.server.JkCoyoteHandler : java.lang.NoClassDefFoundError: Could not initialize class org.apache.jk.server.JkCoyoteHandler Command deploy failed. although i copied the tomcat-ajp.jar into $GLASSFISH_HOME/lib do you have any idea? thanx so much in advance!!!

ok i still had to copy the tomcat-ajp.jar ... now it seems to work ...

ralphrmartin, You're absolutely right. The connector name should be consistent. asadmin create-http-listener --listenerport 8009 --listeneraddress 0.0.0.0 --defaultvs server my-connector asadmin set configs.config.server-config.network-config.network-listeners.network-listener.my-connector.jk-enabled=true Thanks for the correction.

I'm using build 55, but ./asadmin set configs.config.server-config.network-config.network-listeners.network-listener.jk-connector.jk-enabled=true still gives remote failure: No configuration found for configs.config.server-config.network-config.network-listeners.network-listener.jk-connector What's up?

OK. There is a typo on the first line. asadmin create-http-listener --listenerport 8009 --listeneraddress 0.0.0.0 --defaultvs server my-connector should say asadmin create-http-listener --listenerport 8009 --listeneraddress 0.0.0.0 --defaultvs server jk-connector

bjoerntietjens, V3 already includes necessary classes from tomcat-ajp.jar. You shouldn't need to copy tomcat-ajp.jar.

Amy, I have a problem with jk. I've downloaded b55 and your two steps work without errors. however, when I start the app server, there is no listener on port 8009 and nothing also on the app server log. When I remove the jk-enabled="true" from the network listerner, then the listerner starts without problems, I can see it both on the logs and with the browser access. The problem exists when there is jk-enabled="true" in the network listener. Any ideas why? Thanks, Jerry

Jerry, There's a regression with b55 and I just fixed the issue. The listener on port 8009 should start either way and jk-enabled attribute isn't working with b55. Please try with tomorrow's nightly and let me know if you still have problems. Amy

Amy, I've installed b59, but after I follow your instructions and restart the server I get the following error: ... (snip) ... SEVERE: Caused by: org.apache.commons.logging.LogConfigurationException: java.lang.ClassCastException: org.apache.commons.logging.impl.LogFactoryImpl cannot be cast to org.apache.commons.logging.LogFactory SEVERE: at org.apache.commons.logging.LogFactory.newFactory(LogFactory.java:506) SEVERE: at org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:350) SEVERE: at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:381) SEVERE: at org.apache.jk.server.JkCoyoteHandler.(JkCoyoteHandler.java:81) SEVERE: ... 43 more SEVERE: Caused by: java.lang.ClassCastException: org.apache.commons.logging.impl.LogFactoryImpl cannot be cast to org.apache.commons.logging.LogFactory SEVERE: at org.apache.commons.logging.LogFactory.newFactory(LogFactory.java:504) SEVERE: ... 46 more Any clues? Jerry

Hi Jerry, I just tried it using b59 and it is working for me. [#|2009-08-19T13:39:05.420-0700|INFO|glassfish|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=11;_ThreadName=Thread-2;|Apache mod_jk/jk2 attached to virtual-server server listening on port: 8009|#] [#|2009-08-19T13:39:05.443-0700|INFO|glassfish|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=11;_ThreadName=Thread-2;|Created virtual server server|#] [#|2009-08-19T13:39:05.445-0700|INFO|glassfish|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=11;_ThreadName=Thread-2;|Created virtual server __asadmin|#] [#|2009-08-19T13:39:05.449-0700|INFO|glassfish|org.jvnet.hk2.osgiadapter|_ThreadID=11;_ThreadName=Thread-2;|Started bundle org.glassfish.deployment.dol [87]|#] [#|2009-08-19T13:39:05.900-0700|INFO|glassfish|org.jvnet.hk2.osgiadapter|_ThreadID=11;_ThreadName=Thread-2;|Started bundle org.glassfish.web.core [126]|#] [#|2009-08-19T13:39:05.947-0700|INFO|glassfish|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=11;_ThreadName=Thread-2;|Virtual server server loaded system default web module|#] [#|2009-08-19T13:39:06.086-0700|INFO|glassfish|org.apache.jk.common.ChannelSocket|_ThreadID=11;_ThreadName=Thread-2;|JK: ajp13 listening on /0.0.0.0:8009|#] I'm wondering if we have the same bundle. I got my b59 from http://download.java.net/glassfish/v3/promoted/glassfish-v3-web-preview-... Let me know if you still have issues with the above bundle. Thanks, Amy

Michal

Amy,

1) I've downloaded http://download.java.net/glassfish/v3-prelude/release/glassfish-v3-prelu...

2) unzipped

3) started server

4) executed:

bin/asadmin create-http-listener --listenerport 8009 --listeneraddress 0.0.0.0 --defaultvs server my-connector

Command create-http-listener executed successfully.

5) executing:

bin/asadmin set configs.config.server-config.network-config.network-listeners.network-listener.my-connector.jk-enabled=true
remote failure: No configuration found for configs.config.server-config.network-config.network-listeners.network-listener.my-connector

Command set failed.

I haven't downloaded the web preview, but the full bundle. I'll try the web preview and let you know. Maybe this is an issue of the full bundle. (http://download.java.net/glassfish/v3/promoted/latest-glassfish-unix.sh is what I downloaded).

I tried with the full bundle - http://download.java.net/glassfish/v3/promoted/latest-glassfish.zip and runs ok for me.

I Uninstalled the previous servers and did a clean install and everything seems to work correctly now. Thanks Amy for all the help. Jerry

Hi Amy, let me explain the issue I'm facing. First of all I'm using Glassfish B60 build (for linux). I followed all your steps and all it works properly only if there is a simple application deployed (webapp that does not use any logging framework). If I try to deploy some webapps (like liferay) that use their common-logging files, I receive the error: SEVERE: Caused by: org.apache.commons.logging.LogConfigurationException: java.lang.ClassCastException: org.apache.commons.logging.impl.LogFactoryImpl cannot be cast to org.apache.commons.logging.LogFactory Then, If I disable the JK connector, all works properly. Any hints? Thanks a lot! fb

Can you file an issue [1] with your webapp which uses commons logging framework? You can assign the issue to me, I'll take a look at it. [1] https://glassfish.dev.java.net/servlets/ProjectIssues Thanks, Amy

Done. Thanks.

older versions

The instructions here actually appear to work: http://www.java.net/blog/2008/08/27/fronting-glassfish-v3-apache-httpd