There are a couple of how-to guides for installing Glassfish 2 and getting started with it. This article links to some guides I considered worth reading and gives you additional information.
Basic Installation and setup
Before pointing you to a guide for the basic steps, I suggest to check out what’s the newest release of Glassfish at its download site. To download Glassfish 2 Update Release 2 (April 2008, English only, 54MB):
Although the official site for V2 UR2 has some basic installation instructions, I recommend Jasper Kalkers blog article Installing Glassfish 2 on ubuntu 7.10. Besides installing Java and Glassfish, Jasper also explains how to set up a service script to automatically start Glassfish with user privileges. Of course, Debian users must adjust the scripts a bit because
sudo is a Ubuntu-only command.
Virtuozzo vServer Memory Issues
If you try setup Glassfish in a shared server using Virtuozzo vServer, you may experience some weird memory issues when trying to run the ant setup script. Follow this blog article if you get errors like this:
/home/gtest/glassfish/setup.xml:156: The following error occurred while executing this line:
/home/gtest/glassfish/setup.xml:137: Execute failed: java.io.IOException: java.io.IOException: Cannot allocate memory
Change default passwords
Especially if your server is exposed to the Internet, you should secure Glassfish a little more. E.g. after the standard installation the admin console (port 4848) can be accessed by everyone who knows the default login admin/adminadmin. This can be changed in the admin console or using the
change-admin-password command inside the
asadmin console/command when the server is running.
You should also change the master password (default is “changeit”). This time the server (the domain)
should not be running:
By default, Glassfish listens to port 8080 for HTTP requests. The most popular ways to wire it to standard HTTP port 80 probably are:
- Apache using mod_jk
- authbind lets Glassfish to bind to port 80
- iptables redirection (Wikipedia has just the right example)
- Some proxy running on port 80 (like Squid)
- Some port forwarder utility
If Apache is running on your machine anyway, you could forward some URLs pattern to Glassfish using mod_jk (details). But you can easily run Glassfish stand alone if you do not need Apache. Thus, I deactivated the Apache service in favor of Glassfish because Apache would be just another system to be maintained.
Iptables and authbind both seem to be simple and robust solutions. I chose authbind because it is the only solution that allows Glassfish to actually listen to port 80 running as a non-root user. Note, that Linux normally requires processes listening to ports below 1024 running with superuser privileges, which is not recommended for security reasons. If you opt for authbind, you can configure Glassfish to use port 80 in the admin console. Look for http-listener-1 in the configuration section for HTTP. Here’s how to set up authbind for user glassfish (check the chown command if you want to use a different user).
apt-get install authbind
chmod 500 /etc/authbind/byport/80
chown glassfish /etc/authbind/byport/80
(Ubuntu users, don’t forget to prepend “sudo”)
One drawback to this approach is that starting Glassfish now requires calling authbind:
authbind –deep asadmin start-domain domain1
Some more links and tips
By now, your Glassfish server should be up and running. The following selection of resources may also be useful for your next steps:
- Sun’s documentation for Glassfish 2 UR2
- Automatic domain restart
- Glassfish IDE Plugins, e.g. for Eclipse 3.3
- If you get a NullPointerException when deploying from Eclipse with WTP 2.0.2, you need to install additional patches for WTP (bug report)
- If you have installed Sun’s JDK 6 (apt-get install sun-java6-jdk), Java will be installed in /usr/lib/jvm/java-6-sun-1.6.X.XX and will be linked from /usr/lib/jvm/java-6-sun
- Troubleshooting memory issues
- The official Ability to run on port 80/443 as non-root user enhancement request
- If you are crazy enough, you can try to run PHP inside inside Glassfish using Quercus