 |
Running GlassFish with Apache httpd
Posted by jfarcand on March 17, 2006 at 10:30 AM | Comments (53)
Quick blog to update the way you can front GlassFish with Apache httpd. Starting with build 41, all Jakarta Commons classes has been renamed from org.apache.* to com.sun.org.apache.* . Since mod_jk uses some of those classes, you need to add a couple of Jakarta Commons packages to make it works. Let's do it steps by steps:
(1) First, install mod_jk
Next steps is to configure httpd.conf and worker.properties. For example, add in /etc/httpd/conf/httpd.conf:
LoadModule jk_module /usr/lib/httpd/modules/mod_jk.so
JkWorkersFile /etc/httpd/conf/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 /glassfish-test/* worker1
The add in your /etc/httpd/conf/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.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
Start httpd.
(2) Copy, from a fresh Tomcat 5.5.16 installation
cp $CATALINA_HOME/server/lib/tomcat-ajp.jar
$GLASSFISH_HOME/lib/.
Next, copy commons-logging.jar and commons-modeler.jar from the Jakarta Commons site under to $GLASSFISH_HOME/lib/.
(3) Then enable mod_jk by adding:
$GLASSFISH_HOME/bin/asadmin create-jvm-options -Dcom.sun.enterprise.web.connector.enableJK=8009
Then start GlassFish. That's it!
technorati: httpd glassfish
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
How does one create two instances of glassfish and use the above. Could you also cover that? This will allow two or more instances to be loadbalanced by apache in front.
Posted by: sg112326 on March 17, 2006 at 11:10 AM
-
Nice, now how about an example with IIS? I know i'd really appreciate it.
Posted by: rabbe on March 17, 2006 at 12:38 PM
-
Thanks :-)
I will add an example of your two questions as soon as I get a chance (Monday most probably). I want to test it before sayingi t works :-)
-- Jeanfrancois`
Posted by: jfarcand on March 17, 2006 at 01:14 PM
-
How does this compare with the AJP connector in Tomcat?
Are there parameters involved like connection Timeout (http://tomcat.apache.org/tomcat-5.5-doc/config/ajp.html)?
In tomcat the default timeout is unlimited which sucks in production, how is JK behaving with Glassfish?
Posted by: hdupre on March 20, 2006 at 02:08 PM
-
to hdupre: This is the same AJP connector, but I didn't exposed all the parameters....from you comment, I guess I should. Should not be difficult to implement.
Posted by: jfarcand on March 20, 2006 at 02:25 PM
-
Thanks, But i keep getting 400 errors on the response in the mod_jk.log. The last entry is [debug] jk_handler::mod_jk.c (1969): Service finished with status=400 for worker=worker1. Any help would be appreciated. The platform is FC5.
Posted by: toddf58 on April 01, 2006 at 06:01 PM
-
The build that gives the 400 errors is 42. I will try it on on 41. today. Thanks..
Posted by: toddf58 on April 02, 2006 at 10:13 AM
-
Todd, you are right. Something is broken in build 42. I' investigating righ now.
-- Jeanfrancois
Posted by: jfarcand on April 03, 2006 at 09:12 AM
-
If there is any thing that I can do to help, just let me know. Thanks
Posted by: toddf58 on April 03, 2006 at 08:18 PM
-
todd, the next nightly build (and next promoted builds (FCS and next) will have the fix. Try it and let me know.
Thanks!
Posted by: jfarcand on April 04, 2006 at 02:40 PM
-
Jean, The nightly build works with both mod_jk and mod_proxy_jk on apache 2.2 linux. Thanks.......Todd
Posted by: toddf58 on April 05, 2006 at 11:36 AM
-
I've tried this and just get 503 errors everywhere it should be forwarding
Posted by: rgalgon on July 10, 2006 at 01:09 PM
-
rgalgom, can you post you configuration/build info on users@glassfish.dev.java.net . Will be more easy to debug.
Posted by: jfarcand on July 10, 2006 at 01:53 PM
-
Is the AJP Connector configurable in the lastest build?
I need to set "tomcatAuthentication=false" in the connector. Thanks, Ellen
Posted by: ekraffmiller on July 11, 2006 at 11:24 AM
-
Not yet. But patches are welcome :-) It should be very easy to fix this, but unfortunatly I don't have the cycle right now. I recommend you file an RFE. The fix will needs to be implemented in class glassfish/appserv-core/src/java/com/sun/enterprise/web/PEWebContainer.java
Posted by: jfarcand on July 11, 2006 at 11:59 AM
-
i think it should be mentioned that mod_proxy_ajp is probably the better way to go if you're using apache 2.2 or greater. i've posted an example here.
Posted by: gk5885 on July 18, 2006 at 09:40 PM
-
Thanks Gregory! I've send an email to theaquarium@sun.com so your entriy get listed on this blog.
Posted by: jfarcand on July 19, 2006 at 07:22 AM
-
GlassFish now supports configurable AJP Connector. You can use a properties file to configure the connector. Check out my quick blog
Posted by: amyroh on August 15, 2006 at 02:00 PM
-
Hi Jean-Francois
I have had a hard time trying to get this to work on windows, i had just about followed and tried all the information i could find on this. I have it working now but only if i am logged in to the asadmin GUI. Once i request the URL for the admin i see in the server log that every thing is doing what it should do. and i can request a jsp page and all works.
I suppose i am looking for a quick answer to this before wadding through the documentation for the server. I would like to ask why the jvm parameter -Dcom.sun.enterprise.web.connector.enableJK=8009
only works when i call the asadmin?
regards chainy
Posted by: chainy on September 16, 2006 at 11:15 AM
-
The easiest way for you to enable it is to manually edit ${glassfish.home}/domains/domains1/conf/domain.xml and add:
<jvm-options>-Dcom.sun.enterprise.web.connector.enableJK=8009</jvm-options>.
. -- Jeanfrancois
Posted by: jfarcand on September 18, 2006 at 06:04 AM
-
Hi
I have checked the domain.xml for the entry and it all ready exsits. I have another question though in your example could you tell me what version of apache you are using, only the setup i did on windows following your example works now. Now i need to do this on linux box and once i put mod_jk stuff in apache will not start. when i go to download mod_jk for linux there is not a version for apache 2.2.3 on 2.0 and these don't work. I have tried the proxy_ajp and that works on glassfish v1 b48 but not on the latest build of v2. But i have found that the proxy_ajp forwards everything to glassfish where with the mod_jk you can set up for just .jsp and let apache handle all static content.
Posted by: chainy on September 18, 2006 at 06:45 AM
-
Hum....I was using Apache 2.2.x and mod_jk 1.2.1x (17 or 18...don't redcall exactly). What exception are you seeing in the Apache log?
Posted by: jfarcand on September 18, 2006 at 06:57 AM
-
Hi i am not getting anything it will not start at all. for the mod_jk would i not need a version for apache 2.2.x. Only as i mentioned i can only find versions for 2.0.x and i am thinking this is what is causing the problem. There is a version of the mod_jk for apache 2.2.x on windows but not for linux, not that i can seem to find on apache tomcat-connector site anyway.
Kind regards Chainy
Posted by: chainy on September 18, 2006 at 07:10 AM
-
Hi,
Thanks for this blog!
I have try to get it work with your information.
But it don't work for me.
I get this error in "mod_jk.log":
[Sun Oct 01 13:29:21 2006] [5737:22208] [error] init_jk::mod_jk.c (2450): Initializing shm:/etc/httpd/logs/jk-runtime-status errno=13
[Sun Oct 01 13:29:21 2006] [5737:22208] [debug] uri_worker_map_open::jk_uri_worker_map.c (361): rule map size is 2
[Sun Oct 01 13:29:21 2006] [5737:22208] [debug] uri_worker_map_add::jk_uri_worker_map.c (298): wildchar rule /*.jsp=worker1 was added
Do you now what is wrong?
I am running: glassfish_9.0-b48
Regards,
Ove
Posted by: ovjo122 on October 01, 2006 at 05:39 AM
-
OK GlassFish v2 has suffered a regression recently. I've fixed the problem and the fix will be available with build 21.
ovjo122, do you know if GlassFish gets invoked? Note that you are using Grizzly v1, which doesn't suffer issue 1205. Thanks for the feedback! -- Jeanfrancois
Posted by: jfarcand on October 03, 2006 at 09:13 AM
-
Hi,
I followed the instructions in the blog, but, I am guess it is not working for me. I see following error message in glassfish server log. So, it appears that apache is redirecting requests to glassfish, but, there is some error there :-
[#|2006-10-11T20:01:37.527-0700|INFO|sun-appserver-pe9.1|org.apache.jk.server.JkCoyoteHandler|_ThreadID=13;_ThreadName=TP-Processor2;|Error servicing request R( /glassfish-test/)
java.lang.NullPointerException
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:653)
at java.lang.Thread.run(Thread.java:595)
|#]
Please help.
I also noticed in the comments that you talked about posting a couple of examples in March :-
***********
Thanks :-) I will add an example of your two questions as soon as I get a chance (Monday most probably). I want to test it before sayingi t works :-) -- Jeanfrancois`
Posted by: jfarcand on March 17, 2006 at 01:14 PM
***********
Could you please point me to those examples?
Thanks for sharing your wisdom :).
-Anand
Posted by: anand_akela on October 11, 2006 at 08:09 PM
-
Please ignore my last post. It started working after I installated V2 build 21 of glassfish.
Thanks again.
-Anand
Posted by: anand_akela on October 11, 2006 at 10:58 PM
-
For people that want to do load balancing, take a look at Daniel's blog here:
http://blogs.sun.com/dadelhardt/entry/loadbalancing_with_mod_jk_and_glassfish
Thanks Daniel!
Posted by: jfarcand on December 13, 2006 at 09:31 AM
-
Great guide Jeanfrancois - I followed everything through step by step but kept getting internal server errors from apache. Errors reported in the mod_jk log meant I had to dig around and change the workers.properties file and couldn't use yours above. All fixed now :-) but does anyone know why I couldn't get away with ... worker.worker1.host=localhost.localdomain and only... worker.worker1.localhost=localhost.localdomain will work ? ?
Posted by: matthewjburton on January 31, 2007 at 03:29 PM
-
Hi Matthew....might be a good question to ask in users@tomcat.apache.org. I'm sure some jk expect will know why. Thanks!
Posted by: jfarcand on February 07, 2007 at 01:14 PM
-
Hi,
I tried the step to enable glassfish listen on 8009 for JK it worked fine yesterday after the install. I reinstalled glassfish and the followed the steps given by you, but now it doesn't work .
Any methods to troubleshoot. I can see the added values under /glassfish/domains/config/domain.xml
Posted by: nnaga on February 22, 2007 at 07:04 AM
-
Hum...this is not easy to debug. Can you give more information. Is the request delivered to GlassFish?
Posted by: jfarcand on February 23, 2007 at 01:55 PM
-
Yes, glassfish works absolutely fine, tried creating and removing JVM options to include JK, everytime either it says sucessfully created or sucessfully deleted. Respective changes are also available on the config XML's(domain.xml). But the virtual listener for JK to enable 8009 is not getting created. The only difference between the two installations were, first installation happened as Linux root user and next as a normal user "glassfish" but this mustn't affect in any way as the owner of the GlassFish installation directory is "glassfish" user and when domain.xml is getting modified when I create/delete JVM options I don't thing there are any permissions issues also. Every single functionality is working fine except JK, just wondering why the virtual listener is not getting created.
Posted by: nnaga on February 26, 2007 at 12:24 AM
-
i feel like an idiot for asking this but what is "glassfish-test"
Posted by: huggy77 on May 16, 2007 at 06:58 AM
-
glassfish-test is the context path of an application. Hence doing http://localhost:8080/glassfish-test will works, but also http://localhost/glassfish-test also but will be serviced via Apache instead.
Posted by: jfarcand on May 16, 2007 at 08:52 AM
-
so context path would be the directory holding the jsp pages to serve? would i need the server.xlm file in there?
Posted by: huggy77 on May 16, 2007 at 10:14 AM
-
can you have multiple directories serving jsp? Then let apache handle the addressing through virtual sites?
Posted by: huggy77 on May 16, 2007 at 10:24 AM
-
almost there... when adding the JVM optioni at the end using asadmin i get the following... CLI137 Command create-jvm-options failed.
Posted by: huggy77 on May 16, 2007 at 01:17 PM
-
tried using the password file:
./asadmin create-jvm-options --user admin --passwordfile /home/root/glassfish.password -Dcom.sun.enterprise.web.connector.enableJK=8009 --- tried using root as the user as well
Posted by: huggy77 on May 16, 2007 at 01:18 PM
-
it keeps telling me bad user or password
Posted by: huggy77 on May 16, 2007 at 01:18 PM
-
it worked... i added the jvm thru the gui - i will try and post what i did on the ubuntu forum - i will add the link here so you can check it out...
Posted by: huggy77 on May 16, 2007 at 01:28 PM
-
do i need to have a working version of tomcat running on my box to get this to work... also the links to the jar files are not working...
Posted by: huggy77 on September 18, 2007 at 07:50 PM
-
I spent several hours trying to configure Apache httpd to front my glassfish server. Your instruction is straight forward but I just couldn't get it working. I was using tomcat-ajp.jar from tomcat 5.5.25. Finally, I use the tomcat-ajp.jar from tomcat 5.5.23 and everything works.
I believe tomcat-ajp.jar in the latest release of tomcat 5.5 (ie. version 5.5.25 as of today) does not work with glassfish. Futhermore, Tomcat 6 does not even have tomcat-ajp.jar anymore. Does anyone know going forward, will mod_jk be supported on glassfish? Seems like this compatibility is already broken.
Posted by: choywk on November 13, 2007 at 04:04 PM
-
@choywk: I can confirm your statement. Works fine with the 5.5.23 tomcat-ajp.jar
The newer one does not work (causes NoSuchMethodExceptions to appear in your glassfish server log)
Your posting was a life-saver though, I was about to give up...
I'll store that 5.5.23 tomcat-ajp.jar deep inside the vault ;-)
Posted by: geertv on December 15, 2007 at 09:10 AM
-
I am trying to configure the glassfish UR1 release (v2ur1-b109d) on windows.
Using Apache 2.2.6, with mod_jk-1.2.26-httpd-2.2.4 (The current latest 2.2.x compatible version, I believe)
I have added the three jars including tomcat-ajp (from a 5.5.23 tomcat).
Using the configuration templates above, I think I should be able to see my deployed applications at the URL: http://apacheserver/glassfish-test/MyContextRoot.
However I can only get 400 errors which appear from the logs to have been returned from the glassfish instance.
(As with the previous posters the 5.5.25 version of tomcat-ajp fails to connect to the server.)
Does anybody have this working with UR1 and if so could you indicate the versions of apache server, mod_jk and tomcat jars that you are using?
Posted by: icarr on January 02, 2008 at 07:08 AM
-
My mistake, mod_jk passes the request on including the /glassfish_test/ therefore this must be in the context root of the deployed app! So above versions do work together.
I did get issues from one of the deployed applications when I put a commons-logging in the glassfish/lib directory as instructed. So took the source for tomcat 5.5.23 and rebuilt the jk jar components against the rebased 'commons' components in glassfish. Which means I don't need to deploy another commons-logging or commons-modeller.
Posted by: icarr on January 03, 2008 at 09:23 AM
-
Thanks for the comments! If you have a chance, can you blog or sent what you did to users@glassfish.dev.java.net? I'm sure a lot of people will like reading what you did.
Thanks!!! -- Jeanfrancois
Posted by: jfarcand on January 07, 2008 at 03:06 PM
-
can we confirm that if we follow the instructions above with the 5.5.23 tomcat source this will work????
i had issues months ago - but i love the glassfish project and i want to use it...
Posted by: huggy77 on February 08, 2008 at 10:25 AM
-
Instead of connecting to apache and sending certain types of requests to GlassFish, is it possible to connect to Glassfish and send certain types of requests to apache? Since we will be using Glassfish as the server for our main java netbeans projects, we'd also like to use it to host our subversion (svn) repositories. However, as far as I can tell, subversion is built to work only with apache httpd or it's own server svnserve. Since Glassfish is running with Apache httpd, it should therefore be possible to use it as a server for subversion, correct? In testing locally, I believe I got the above setup working correctly. I can connect to my repository by adding the below code to the httpd.conf file:
DAV svn
SVNPath D:/svn_repo/repos
In netbeans, I can access the repository through: http://localhost/repos/ or using http://my ip address/repos.
Does this mean I am accessing the repository strictly through Apache and not glassfish? Is there a way of viewing logs in glassfish to see if a connection has been made? I really appreciate any help/suggestions! Thanks!!
Posted by: twheeler on February 11, 2008 at 02:23 PM
-
Hi huggy77 & twheeler :-) Can you post your questions on users@glassfish.dev.java.net? That way your are 100% to get a response if I'm swamped :-) Thanks!
Posted by: jfarcand on February 11, 2008 at 02:27 PM
-
Hi jean-francois. I tried posting on users@glassfish.dev.java.net, but for some reason I can't subsribe. I send a blank email as suggested, but I never receive the confirmation email to reply to.....
Posted by: twheeler on February 13, 2008 at 12:22 PM
-
i can confirm that as long as you use the tomcat files from version 5.5.23, this works...
I used:
httpd-2.2.8
commons-modeler-2.0.1
commons-logging-1.1.1
glassfish-installer-v2ur1-b09d
apache-tomcat-5.5.23
mod_jk from tomcat-connectors-1.2.26
i am not sure if my firewall is too tight but check it out:
http://www.market-si.com/hello/
Posted by: huggy77 on February 14, 2008 at 11:41 AM
-
This piece of advice seems a bit out-dated; Apache documentation clearly states that
worker.worker1.cachesize=10
worker.worker1.cache_timeout=600
are deprecated.
With Glassfish 2.1 and Apache 2.2 the above configuration seemed to cause premature time-outs in conjunction with long-lasting MySQL/JDBC transactions leading to HTTP 500 errors (and hanging DB transactions).
Posted by: jonin on April 11, 2008 at 04:53 AM
|