How-to set up Glassfish 2 on Debian or Ubuntu
Geschrieben von: Markus Junginger in English, tags: authbind, Debian, Eclipse, Glassfish, How-to, iptables, Java 6, Port 80, Ubuntu, vServerThere 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):
wget http://java.net/download/javaee5/v2ur2/promoted/Linux/glassfish-installer-v2ur2-b04-linux.jar
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:
BUILD FAILED
/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.
asadmin change-admin-password
You should also change the master password (default is “changeit”). This time the server (the domain)
should not be running:
asadmin change-master-password
Port 80
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
touch /etc/authbind/byport/80
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


Einträge (RSS)
[...] Glassfish Installation möchte ich auf den englischsprachigen Artikel von Markus Junginger How-to set up Glassfish 2 on Debian or Ubuntu [...]
Yo.
h3po4 h3po4
hafuz.co.il hafuz.co.il
Yeah, thats a good idea, what you are doing here.
Good day.
Thanks for this howto. But there is problem with IPv6 support in authbind – do not work: this is not Java issue, just authbind.
As you can test with command: “authbind nc6 -l -p23″
Netcat is allowed to listen on IPv4 but not IPv6. With Java it is same → Glassfish is unable to start.
„Workaround“ is java option -Djava.net.preferIPv4Stack=true, but it disables IPv6 listening, so it is quite useless (you can use iptables forwarding instead).
I had the next problem (Solution at end):
glassfish@localhost:~$asadmin start-domain
Starting Domain domain1, please wait.
Default Log location is /opt/glassfish/domains/domain1/logs/server.log.
Redirecting output to /opt/glassfish/domains/domain1/logs/server.log
Timeout waiting for domain domain1 to go to starting state.
CLI156 Could not start the domain domain1.
Error detail:
java.rmi.server.ExportException: Listen failed on port: 0; nested exception is: java.net.SocketException: Invalid argument
..
Exception :
java.lang.RuntimeException: Admin Server Channel is not initialized
Information:
debian Squeeze AMD64 2.6.32
sun-java6-jdk 6.20-dlj-1
export JAVA_HOME=”/usr/lib/jvm/java-6-sun”
export PATH=”$PATH:/opt/glassfish/bin:/opt/glassfish/lib/ant/bin”
SOLUTION:
The problem was IPv4 and IPv6 Socket listeners, so an change the values:
Edir /etc/sysctl.d/bindv6only.conf
Change net.ipv6.bindv6only = 1 to net.ipv6.bindv6only = 0
Restart service
/etc/init.d/procps restart
Run: asadmin start-domain domain1
And VOILA!!
A found uit here http://forums.debian.net/viewtopic.php?f=5&t=47502