ggkmath
ggkmath

Reputation: 4246

access web container through Apache webserver Port 80 using mod_jk?

I installed GlassFish 3.1.1 and set it up to work with Apache Webserver 2.2.x using mod_jk. Everything works great when using port 8080. For example, an example hello.war application deployed on GlassFish runs fine from:

http://www.mydomain.com:8080/hello/

My question is, what do I need to change (or add) such that I can access the hello.war application using an address like this (and using port 80; so I can eventually close port 8080):

http://www.mydomain.com/hello/

The goal is to have all external traffic pass through Apache webserver port 80 to access GlassFish. Using this site's instructions as inspiration, I modified httpd.conf to include the following lines (inside the pre-existing VirtualHost tags for www.mydomain.com)

JkMount /hello/* worker1
JkMount /hello worker1

Then I restart Apache webserver and go to:

http://www.mydomain.com/hello

and the website hangs (spinning wheel for 30s). What could be the problem? There's no firewall between Apache and Glassfish, no loadbalance, and no clustering. It's a new CentOS 6.2 server with all fresh installs.

For reference, my httpd.conf file includes the following (among other things):

LoadModule jk_module /etc/httpd/modules/mod_jk.so
JkWorkersFile /etc/httpd/conf/workers.properties
JkLogFile /etc/httpd/logs/mod_jk.log
JkLogLevel debug
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
...
Listen 0.0.0.0:80

and the glassfish-jk.properties file is:

worker.list=worker1
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009

UPDATE: 2/11/2012 8:30pm I fixed the original problem posted above. The problem occurred because (1) there was a GlassFish bug (see Kevin's answer below for this discovery), and (2) I had somehow managed inadvertently to setup multiple http listeners that were listening to the same port 8009. When I deleted all of the listeners and then created the one listener I wanted, I was able to solve the original intent of this posting. However upon viewing the server.log, I see another problem...

When I bring up the GlassFish server, I issue the following commands (note: port 4850 is simply an administration web-console provided by GlassFish; it needs to be there for some commands (not sure exactly which ones) but it doesn't seems to hurt anything by being there for all of them):

# ./asadmin
asadmin> asadmin start-domain --port 4850
asadmin> deploy /path/to/file/hello.war --port 4850
asadmin> create-http-listener --listenerport 8009 --listeneraddress 0.0.0.0 --defaultvs server gf_listener --port 4850 
asadmin> create-network-listener --protocol http-listener-1 --listenerport 8009 --jkenabled true jk-connector --port 4850
asadmin> set server-config.network-config.network-listeners.network-listener.jk-connector.jk-configuration-file=/home/glassfish/glassfish3/glassfish/domains/domain1/config/glassfish-jk.properties --port 4850
asadmin> restart-domain --port 4850

The above commands are taken directly from the GlassFish Administration Guide (click on PDF link, turn to page 150. This starts the section "To enable mod_jk", specifically see steps 5 and 6 on page 151).

I've included a snippet from the GlassFish server log below showing one type of SEVERE error and a WARNING for max threads too low.

[#|2012-02-11T20:23:23.666-0800|INFO|glassfish3.1.1|javax.enterprise.system.core.com.sun.enterprise.v3.services.impl|_ThreadID=14;_ThreadName=Thread-2;|Grizzly Framework 1.9.36 started in: 43ms - bound to [0.0.0.0:8080]|#]
[#|2012-02-11T20:23:23.666-0800|INFO|glassfish3.1.1|javax.enterprise.system.core.com.sun.enterprise.v3.services.impl|_ThreadID=11;_ThreadName=Thread-2;|Grizzly Framework 1.9.36 started in: 6ms - bound to [0.0.0.0:3700]|#]
[#|2012-02-11T20:23:23.666-0800|INFO|glassfish3.1.1|javax.enterprise.system.core.com.sun.enterprise.v3.services.impl|_ThreadID=12;_ThreadName=Thread-2;|Grizzly Framework 1.9.36 started in: 24ms - bound to [0.0.0.0:4850]|#]
[#|2012-02-11T20:23:23.668-0800|INFO|glassfish3.1.1|javax.enterprise.system.core.com.sun.enterprise.v3.services.impl|_ThreadID=15;_ThreadName=Thread-2;|Grizzly Framework 1.9.36 started in: 2ms - bound to [0.0.0.0:7676]|#]
[#|2012-02-11T20:23:23.691-0800|INFO|glassfish3.1.1|javax.enterprise.system.core.com.sun.enterprise.v3.admin.adapter|_ThreadID=10;_ThreadName=Thread-2;|The Admin Console is already installed, but not yet loaded.|#]
[#|2012-02-11T20:23:23.781-0800|INFO|glassfish3.1.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=10;_ThreadName=Thread-2;|WEB0169: Created HTTP listener [http-listener-1] on host/port [0.0.0.0:8080]|#]
[#|2012-02-11T20:23:23.788-0800|INFO|glassfish3.1.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=10;_ThreadName=Thread-2;|WEB0169: Created HTTP listener [http-listener-2] on host/port [0.0.0.0:8181]|#]
[#|2012-02-11T20:23:23.793-0800|INFO|glassfish3.1.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=10;_ThreadName=Thread-2;|WEB0169: Created HTTP listener [admin-listener] on host/port [0.0.0.0:4850]|#]
[#|2012-02-11T20:23:23.803-0800|INFO|glassfish3.1.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=10;_ThreadName=Thread-2;|WEB0170: Apache mod_jk/jk2 attached to virtual-server [server]  listening on port [8,009]|#]
[#|2012-02-11T20:23:23.806-0800|INFO|glassfish3.1.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=10;_ThreadName=Thread-2;|WEB0170: Apache mod_jk/jk2 attached to virtual-server [server]  listening on port [8,009]|#]
[#|2012-02-11T20:23:23.826-0800|INFO|glassfish3.1.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=10;_ThreadName=Thread-2;|WEB0171: Created virtual server [server]|#]
[#|2012-02-11T20:23:23.828-0800|INFO|glassfish3.1.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=10;_ThreadName=Thread-2;|WEB0171: Created virtual server [__asadmin]|#]
[#|2012-02-11T20:23:24.316-0800|INFO|glassfish3.1.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=10;_ThreadName=Thread-2;|WEB0172: Virtual server [server] loaded default web module []|#]
[#|2012-02-11T20:23:24.416-0800|SEVERE|glassfish3.1.1|org.apache.jk.server.JkMain|_ThreadID=10;_ThreadName=Thread-2;|No class name for worker.worker1 worker|#]
[#|2012-02-11T20:23:24.416-0800|SEVERE|glassfish3.1.1|org.apache.jk.server.JkMain|_ThreadID=10;_ThreadName=Thread-2;|No class name for worker.worker1 worker|#]
[#|2012-02-11T20:23:24.416-0800|SEVERE|glassfish3.1.1|org.apache.jk.server.JkMain|_ThreadID=10;_ThreadName=Thread-2;|No class name for worker worker|#]
[#|2012-02-11T20:23:24.416-0800|SEVERE|glassfish3.1.1|org.apache.jk.server.JkMain|_ThreadID=10;_ThreadName=Thread-2;|No class name for worker.worker1 worker|#]
[#|2012-02-11T20:23:24.417-0800|INFO|glassfish3.1.1|org.apache.jk.common.ChannelSocket|_ThreadID=10;_ThreadName=Thread-2;|JK: ajp13 listening on /0.0.0.0:8009|#]
[#|2012-02-11T20:23:24.426-0800|WARNING|glassfish3.1.1|org.apache.tomcat.util.threads.ThreadPool|_ThreadID=10;_ThreadName=Thread-2;|threadpool.max_threads_too_low|#]
[#|2012-02-11T20:23:24.428-0800|INFO|glassfish3.1.1|org.apache.jk.server.JkMain|_ThreadID=10;_ThreadName=Thread-2;|Jk running ID=0 time=0/25  config=null|#]
[#|2012-02-11T20:23:24.434-0800|SEVERE|glassfish3.1.1|org.apache.jk.server.JkMain|_ThreadID=10;_ThreadName=Thread-2;|No class name for worker.worker1 worker|#]
[#|2012-02-11T20:23:24.434-0800|SEVERE|glassfish3.1.1|org.apache.jk.server.JkMain|_ThreadID=10;_ThreadName=Thread-2;|No class name for worker.worker1 worker|#]
[#|2012-02-11T20:23:24.435-0800|SEVERE|glassfish3.1.1|org.apache.jk.server.JkMain|_ThreadID=10;_ThreadName=Thread-2;|No class name for worker worker|#]
[#|2012-02-11T20:23:24.435-0800|SEVERE|glassfish3.1.1|org.apache.jk.server.JkMain|_ThreadID=10;_ThreadName=Thread-2;|No class name for worker.worker1 worker|#]
[#|2012-02-11T20:23:24.435-0800|INFO|glassfish3.1.1|org.apache.jk.common.ChannelSocket|_ThreadID=10;_ThreadName=Thread-2;|JK: ajp13 listening on /0.0.0.0:8009|#]
[#|2012-02-11T20:23:24.436-0800|WARNING|glassfish3.1.1|org.apache.tomcat.util.threads.ThreadPool|_ThreadID=10;_ThreadName=Thread-2;|threadpool.max_threads_too_low|#]
[#|2012-02-11T20:23:24.436-0800|INFO|glassfish3.1.1|org.apache.jk.server.JkMain|_ThreadID=10;_ThreadName=Thread-2;|Jk running ID=0 time=0/3  config=null|#]
and so on...

Anyone know how to eliminate the SEVERE errors for No class name for worker.worker1 worker, and how to eliminate threadpool.max_threads_too_low WARNING?

Which thread pool are they referring to? For example, when I type: asadmin> list-threadpools server, I get the following:

admin-thread-pool
http-thread-pool
thread-pool-1

I changed the http-thread-pool size from the default of 5 to a value of 200, then restarted GlassFish and looked at the server.log file and... nothing changes (still get same error message above). The max threads for admin-thread-pool is 50 and for thread-pool-1 is 200. Any ideas how to fix this?

Upvotes: 2

Views: 4579

Answers (2)

ggkmath
ggkmath

Reputation: 4246

Finally figured out what was the problem with help from the GlassFish open-source forum (summarized below for others to reference). In the original posting above, I used:

Problem #1 (broken AJP connection between mod_jk and GlassFish, original posted problem)

# ./asadmin
asadmin> asadmin start-domain --port 4850
asadmin> deploy /path/to/file/hello.war --port 4850
asadmin> create-http-listener --listenerport 8009 --listeneraddress 0.0.0.0 --defaultvs  server gf_listener --port 4850 
asadmin> create-network-listener --protocol http-listener-1 --listenerport 8009 --jkenabled true jk-connector --port 4850
asadmin> set server-config.network-config.network-listeners.network-listener.jk-connector.jk-configuration-file=/home/glassfish/glassfish3/glassfish/domains/domain1/config/glassfish-jk.properties --port 4850
asadmin> restart-domain --port 4850

This came from the Administrator's Guide. While the HTML file is correct here (http://docs.oracle.com/cd/E18930_01/html/821-2416/gfaad.html), if you select PDF and go to page 151, step 5 uses a variable called listener-name. However, this listener-name must agree with the use of jk-connector in step 6. Thus either listener-name must be jk-connector in step 5, or jk-connector in step 6 must be listener-name in step 5. In my case (see original posting code above), I set listener-name to gf_listener in step 5 and used jk-connector in step 6. This created the situation where two listeners were listening on the same port, which isn't allowed. A better solution is to simply avoid issuing the create-http-server command, which is deprecated and shown only for backward compatibility (although not documented as such).

Problem #2 (SEVERE errors noted above)

The other problem is that the worker properties must go into the file ~/apache/conf/worker.properties, and all connector attributes (e.g. and NO worker properties) go into the domain-dir/conf/glassfish-jk.properties file. This is confusing because the PDF document above page 153 example 6-7 explicitly states This example shows a workers.properties or glassfish-jk.properties file that is set for load balancing... where they show setting worker properties in the glassfish-jk.properties file. This is wrong (given the directory structure and commands used above in the same document).

Problem #3 (WARNING noted above for thread pool)

I eliminated the WARNING for threadpool.max_threads_too_low because I had mistakenly increased the Default configuration rather than the Server configuration's settings in the web console (after I increased the server configuration's settings the warning went away). Increasing this value can be done at the command line or even easier using the web admin console (Configuration > server-config > thread pools). The command line way is:

configs.config.server-config.thread-pools.thread-pool.http-thread-pool.max-thread-pool-size=200

for 200 threads (example).

Solution:

Here's my final and complete bring-up for GlassFish:

asadmin> start-domain
asadmin> deploy /home/glassfish/apps/hello.war
asadmin> create-network-listener --protocol http-listener-1 --listenerport 8009 --jkenabled true jk-connector
asadmin> set server-config.network-config.network-listeners.network-listener.jk-connector.jk-configuration-file=/home/glassfish/glassfish3/glassfish/domains/domain1/config/glassfish-jk.properties
asadmin> restart-domain

Note: there's no create-jvm-options setting (as found in admin guide PDF above, step 7) since this relates to http-listener which is not used here anymore.

Upvotes: 1

souser
souser

Reputation: 6124

What is your context root ? Does you app respond to uri "/glassfish-test" or "/hello" ?

If it is "/hello", try something simple first and after it works you can attempt the redirect

JkMount /hello/* worker1

Update : Just saw your error message. Make sure that glassfish is indeed listening on port 8009.

Upvotes: 2

Related Questions