Skip to main content

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 jk-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 >>

Comments

Thanks for the article and discussions. Though a simple ...

Thanks for the article and discussions.
Though a simple configuration I''d like to see samples which include cases where you would want to load balance against a cluster, like this:

JkMount /examples/* loadbalancer

Then of course, you would need:
worker.loadbalancer.balance_workers=worker1,worker2

Has anyone tried mod_cluster, instead?

Cheers All!

Does open source Glassfish 3.1 also support auto-apply ...

Does open source Glassfish 3.1 also support auto-apply feature ? Also, where will I find the binary for Apache HTTP server ?

Running GlassFish V3 with

Hi Amy,
thanks for your article... I have configured and it's works good with jsp webapp, but with JSF webapp sometimes the page is not completely loaded on my browser.. Have you an idea?

Thanks

Glassfish v3 + cluster + Apache

Hello Amy. I have a Glassfish v3.1 installation with a cluster that use two machines. Each node have a cluster instance and my configuration runs properly with an application deployed. The problem is that I don't know how configure Apache as load balancer, like I did in Glassfish v2 (example: http://blogs.sun.com/jluehe/entry/supporting_apache_loadbalancer_with_gl...). I know that Glassfish already has support to mod_jk, but I didn't find documentation about this subject. Thanks for your help. Pablo Nobrega pablonobrega2004@gmail.com

AJP connector not initialized?

Thanks for the guide, seems to work fine for me, but I noticed something wierd that might be a bug..

The AJP connector in glassfish seems to initialize only when I access the admin web interface (port 4848). If I restart the server the AJP connector is not initialized and Apache reports "Service Temporarily Unavailable". As soon as I access the admin interface at port 4848 the AJP connector starts working.. BR Gustav

Two Domains on onehost

I have a problem with the Jk listener when running two separate domains on one host: The JK listener for the second domain does not come up. It does not log anything, it's just not there. Is this a known limitation, or am I doing anything wrong?

There isn't a known

There isn't a known limitation.  How are you creating jk listener on two domains on one host?  You can send your full steps to glassfish users alias [1] or file an issue [2] to determine if it's a bug or user error.

[1] users@glassfish.dev.java.net

[2] https://glassfish.dev.java.net/servlets/ProjectIssues

Done. Thanks.

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

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

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

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

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).

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.

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

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 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

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

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

I even get this problem with http://download.java.net/glassfish/v3/nightly/glassfish-v3-web-b52-06_25...

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?

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.

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

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!!!

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 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

Build Failed

Hi, I'm having a problem when I try to do a 'run-deploy'.
I write:

$ ant -f build.xml run-deploy

and i have this response

Buildfile: build.xml

-pre-init:

-init-private:

-init-user:

-init-project:

-init-macrodef-property:

-do-init:

-post-init:

-init-check:

-init-macrodef-javac:

-init-macrodef-junit:

-init-macrodef-java:

-init-debug-args:

-init-macrodef-nbjpda:

-init-macrodef-nbjsdebug:

-init-macrodef-debug:

-init-taskdefs:

init:

-init-cos:

deps-module-jar:

deps-ear-jar:

deps-jar:

-pre-pre-compile:

-pre-compile:

-copy-manifest:

-copy-persistence-xml:

-copy-webdir:

library-inclusion-in-archive:

library-inclusion-in-manifest:

-do-compile:

-post-compile:

compile:

compile-jsps:

-do-compile-single-jsp:

-pre-dist:

-do-tmp-dist-with-manifest:

-do-tmp-dist-without-manifest:

-pre-run-deploy:

-pre-nbmodule-run-deploy:

-run-deploy-nb:

-init-deploy-ant:

-init-cl-deployment-env:


-parse-sun-web:
[copy] Copying 1 file to /tmp
[delete] Deleting: /tmp/gfv31346929056


-no-parse-sun-web:

-add-resources:

-deploy-ant:
[echo] Deploying dist/myProject.war
[get] Getting: http://localhost:38035/__asadmin/deploy?path=/home/rodolfo/myProject/dis...
[get] To: /tmp/gfv31081734299
[get] Error opening connection java.io.FileNotFoundException: http://localhost:38035/__asadmin/deploy?path=/home/rodolfo/myProject/dis...
[get] Error opening connection java.io.FileNotFoundException: http://localhost:38035/__asadmin/deploy?path=/home/rodolfo/myProject/dis...
[get] Error opening connection java.io.FileNotFoundException: http://localhost:38035/__asadmin/deploy?path=/home/rodolfo/myProject/dis...
[get] Can't get http://localhost:38035/__asadmin/deploy?path=/home/rodolfo/myProject/dis... to /tmp/gfv31081734299


BUILD FAILED
/home/rodolfo/myProject/nbproject/ant-deploy.xml:50: Can't get http://localhost:38035/__asadmin/deploy?path=/home/rodolfo/myProject/dis... to /tmp/gfv31081734299

Total time: 1 second