Geoserver, Apache 2, Tomcat 6 and virtual hosts

Hello,
I just bought a virtual server running openSUSE 11.0, and I want to set it up as a webserver running PHP, Mono and JSP/Tomcat.

I successfully installed and configured Apache 2 with PHP and Mono, and I currently use name-based virtual hosts (it took me 4 days to find the bug in my configuration;)).

I installed tomcat6 package from YaST, and of course Apache’s mod_jk.

I ran a2enmod jk to enable mod_jk in Apache after setting the right tomcat paths in jk configuration files.

Now I’m very confused. Apache definitely handles name-based vhosts (I’m even able to run a Default.aspx home page), but I don’t know how to set up Geoserver (which is a .war file I put into /srv/tomcat6/webapps to work in a name-based virtual host. I would like it to be http://tomcat.zighinetto.org to test it, but I don’t know to do that. All the documentation I found has been confusing. I read about the <Host> tag in server.xml but I don’t know how to configure Apache for using Tomcat to handle request to that vhost.

I’m really, really confused. I have never worked with Tomcat and JSP since I’m an experienced PHP and ASP.NET developer.

Can somebody help me configure GeoServer for repsonding at http://tomcat.zighinetto.org?

Thank you in advance

When using mod_jk you just arrange for tomcat to run the app on some high port, usually something like 8080, on localhost (127.0.0.1), and then for Apache for proxy requests virtual host requests to that port using mod_jk. Apache does the virtual hosting here, tomcat doesn’t. Which means you can test the setup by going straight to http://localhost:8080/

Unfortunately, it doesn’t work. Tried to open http://my_ip:8080 with firewall properly configured: nothing. Tried “telnet localhost 8080” from SSH to check if that was just a firewall problem: still connection refused.

Tried “netstat -oan” and there is no trace of port 8080. Checked /etc/tomcat6/tomcat6.conf to make sure the configuration is OK, and CONNECTOR_PORT was correctly set to 8080.

Finally, I did the following:
*Stopped tomcat6 with /etc/init.d/tomcat6 stop
*Removed /var/lock/subsys/tomcat6
*Started tomcat6 again

When checking with “top” if Tomcat was running… no trace of it!!! :expressionless:
If I run “service tomcat6 status” I get “lock file found but no process running for pid 11748”

It simply means that you have not arranged for tomcat to listen on localhost:8080, as netstat shows no process listening there. Now you see why Java stuff psses me off, the config is so arcane. You have to fiddle with server.xml until you get it to listen on port 8080. Make sure the XML element you thing is active isn’t actually commented out with <!-- … → You could also look in the tomcat logs to see what the problem might be, IIRC it’s catalina.out and catalina.log you have to look at. Maybe you are missing some jars or something.

Get this working on localhost:8080 first and then the mod_jk is a piece of cake after that.

Ok, looks like I have no catalina*.log… (*find / | grep catalina.]log returns nothing)

cat /var/log/tomcat6/catalina.out
“Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.”

Unfortunately it’s not timestamped :frowning:
After this error I tried again clearing catalina.out (so when it will be recreated I’ll be sure those will be the latest events). Since I have only 64MB of RAM it should be a memory problem…OK…

Tried to shut down both MySQL and Apache to get another 20MB free (checked with top). Tried again


vpsville01:/var/log/tomcat6 # rm /var/lock/subsys/tomcat6 
vpsville01:/var/log/tomcat6 # service tomcat6 start
Starting tomcat6:                                            OK  ]
vpsville01:/var/log/tomcat6 # service tomcat6 status
lock file found but no process running for pid 19493
vpsville01:/var/log/tomcat6 # cat /var/log/tomcat6/catalina.out 
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

64MB is simply not enough. Java is a memory hog. Try 128 or even 256MB.

You’re definitely right

After shutting down all un-needed services


vpsville01:/var/log/tomcat6 # java
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

Thank you for your help.

I found the solution about running Tomcat.
In order to force Java to run with low memory (I just upgraded my server to 128MB of RAM and same problem) I created a wrapper. I want to share my solution with other people that might have my same problem. Here it is how to proceed:

*Find the java executable: it’s usually in /usr/bin, although it’s a symbolic link to the real executable
*Rename java to something else
*Create a bash script that runs the real java executable with -Xmx parameter and the original parameters supplied by the caller

Here are the commands to run as root:


# cd /usr/bin
# mv java xmjava
# touch java
# chmod +x java
# nano java

You can use nano, vi or ANY other editor you like. When in the editor, paste the following code:


#!/bin/bash

./xmjava -Xmx16m "$@"

Repeat the same with /etc/jre/alternatives/bin/java, also known as “$JAVA_HOME/bin/java”.
Replace the “16m” with the amount of megabytes you like, for example “32m”, “128m” etc.

To check if it works, try to run “java -version”. Here is what it did on my VPS:


marcus:/usr/bin # java -version
java version "1.6.0_0"
IcedTea6 1.4 (suse-24.4-i386) Runtime Environment (build 1.6.0_0-b14)
OpenJDK Client VM (build 14.0-b08, mixed mode)

So it works now. Running netstat -oan shows me the 8080 port is in listening status :wink:

No need to go through all that. Just edit /etc/tomcat6/tomcat6.conf and put the additional option in JAVA_OPTS.