Wednesday, March 7, 2012

Glassfish 3.1.2 on Ubuntu 11.10

These are the steps I took to install Glassfish 3.1.2 on Ubuntu 11.10.

I should point out that I used a Proxmox KVM virtual server for this.  I first tried an OpenVZ virtual server but kept running into an error: "There is a process already using the admin port 4848 -- it probably is another instance of a GlassFish server."  After some googling I decided this error had something to do with the networking which is significantly different on OpenVZ than KVM so I abandoned the OpenVZ container and created a KVM virtual host.

These steps are a combination of two other guides in order to provide an internal Glassfish server that is password protected (here and here).

Before I began I installed Ubuntu 11.10 server (64-bit) on the Proxmox KVM virtual machine and updated to the latest available updates then backed-up the virtual machine.

  1. Install Java (I chose the natively available version of Java, openjdk):
  2. ~# sudo apt-get install openjdk-7-jdk
  3. Install the unzip utility (not included by default in Ubuntu 11.10):
  4. ~# sudo apt-get install unzip
  5. Create user and group to install and run Glassfish (I chose glassfish and glassfishadm):
  6. ~# sudo adduser --home /home/glassfish --system --shell /bin/bash glassfish
    ~# sudo groupadd glassfishadm
    ~# sudo usermod -a -G glassfishadm glassfish
  7. Change to glassfish user:
  8. ~# sudo su - glassfish
  9. Get Glassfish zip:
  10. ~# wget
  11. Unzip glassfish and move it to root of glassfish user home folder:
  12. ~# unzip
    ~# mv glassfish3/* .

    ~# rm -r glassfish3
    ~# rm
  13. Change owner and group of entire folder:
  14. ~# chown -R glassfish *
    ~# chgrp -R glassfishadm *
  15. Exit glassfish user:
  16. ~# exit
  17. Create script to start and stop Glassfish server at /etc/init.d/glassfish.  This script will use the glassfish user to start and stop the Glassfish instance so that it does not run as root:
  18. #!/bin/bash

    case "$1" in
        su - glassfish -c "/home/glassfish/bin/asadmin start-domain domain1"
        su - glassfish -c "/home/glassfish/bin/asadmin stop-domain domain1"
        su - glassfish -c "/home/glassfish/bin/asadmin stop-domain domain1"
        su - glassfish -c "/home/glassfish/bin/asadmin start-domain domain1"
        echo "usage: $0 {start|stop|restart}"


    exit 0
  19. Set script to run at boot:
  20. ~# sudo chmod u+x /etc/init.d/glassfish
    ~# sudo update-rc.d glassfish defaults
  21. Set admin password (default password for admin is blank):
  22. ~# sudo su - glassfish -c "/home/glassfish/bin/asadmin --user admin change-admin-password"
    Enter admin password> _

    Enter new admin password>
    Enter new admin password again>
    Command change-admin-password executed successfully.
  23. Set security on Glassfish:
  24. ~# sudo su - glassfish -c "/home/glassfish/bin/asadmin enable-secure-admin"
  25. Start the server:
  26. ~# sudo /etc/init.d/glassfish start