GlassFish 3.1 Milestone 2 was released this week, download the zip file.

TOTD #138 provide simple instructions to get you started with Milestone 1 and you can follow similar steps to get started with Milestone 2 as well. A more detailed blog on the new functionality (SSH Provisioning and Dynamic App Deployment) is coming as well.

In order to test the newly added clustering capabilities of GlassFish 3.1, I decided to run Milestone 2 build on a Ubuntu 10.04 instance on Amazon EC2. My host operating system is Mac OS X and even though the steps are defined at multiple locations (mentioned below) but complete set of steps were missing. This Tip Of The Day (TOTD) shows how get started with running a GlassFish 3.1 build on Ubuntu 10.04 instance on Amazon EC2.

This TOTD consulted the following blogs:

Twitterverse was very helpful and Divyen helped smoothen the rough edges!

Lets get started!

  1. In your home directory, create a new ".ec2" directory.
  2. Generate SSH Key & X.509 certificates
    1. Generate X.509 certificates key
      1. Go to your AWS account and click on "Security Credentials".
      2. In "Access Credentials" section, click on "X.509 Certificates" and click on "Create a new Certificate". Make sure to download the private key file and X.509 certificate in ".ec2" directory as "cert-xxxxxx.pem" and "pk-xxxxxxx.pem".
    2. SSH key - Public AMIs can be accessed using an ssh key. Give the following command in ".ec2" directory:
      ec2-add-keypair ec2-keypair > ec2-keypair.pem
      This will generate the SSH key in the file "ec2-keypair.pem".
  3. EC2 API Tools
    1. Download Amazon EC2 API Tools from here and unzip them in ".ec2" directory.
    2. Move "lib" and "bin" directory from the extracted directory to ".ec2" directory.
  4. Create ".ec2.profile" file in ".ec2" directory and add the contents:
    export EC2_HOME=~/.ec2 export PATH=$PATH:$EC2_HOME/bin export EC2_PRIVATE_KEY=`ls $EC2_HOME/pk-*.pem` export EC2_CERT=`ls $EC2_HOME/cert-*.pem` export EC2_URL=https://ec2.us-west-1.amazonaws.com
    The last line sets the default zone to US-West-1. The AMI id used later is from this region. Source this file by giving the following command in ".ec2" directory:
    source ".ec2.profile"
  5. On your firewall, authorize port 22 for SSH and 8080 for HTTP access for GlassFish on your firewall as: ec2-authorize default -p 22 ec2-authorize default -p 8080
  6. Obtain the public IP address of Ubuntu instance as:
    ec2-describe-instances RESERVATION r-XXXXXXXX XXXXXXXXXXXX default INSTANCE i-XXXXXXXX ami-c597c680 ec2-XX-XX-XX-XX.us-west-1.compute.amazonaws.com ip-XX-XX-XX-XX.us-west-1.compute.internal running ec2-keypair 0 m1.small 2010-06-24T16:23:44+0000 us-west-1a aki-XXXXXXXX monitoring-disabled XX-XX-XX-XX XX-XX-XX-XX
    The address "ec2-XX-XX-XX-XX.us-west-1.compute.amazonws.com" is the public IP address and will be used for ssh next.
  7. SSH to the ready Ubuntu instance as:
    ssh -i ec2-keypair.pem ubuntu@ec2-XX-XX-XX-XX.us-west-1.compute.amazonaws.com
  8. Install JDK 6 on Ubuntu
    1. Add the Ubuntu partner repository as: sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
    2. Update the list of packages as:
      sudo apt-get update
    3. Install JDK 6 as: sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk
    4. Add "/usr/lib/jvm/java-6-sun" to the top of "/etc/jvm" file. This file defines the default system JVM search order.
  9. Install "unzip" package as:
    sudo apt-get install unzip
  10. Download & start GlassFish 3.1
    1. Download GlassFish 3.1 Milestone 2 as:
      wget http://dlc.sun.com.edgesuite.net/gla...sh-3.1-b06.zip
    2. Unzip the downloaded zip file as:
      unzip glassfish-3.1-b06.zip
    3. Start GlassFish as:
      ./glassfishv3/glassfish/bin/asadmin start-domain --verbose
    4. And now your default web page is accessible at "http://ec2-XX-XX-XX-XX.us-west-1.compute.amazonws.com:8080".
  11. Finally terminate the instance as:
    ec2-terminate-instances i-XXXXXXXX
How are you using GlassFish in the cloud ?

Technorati: totd glassfish ubuntu amazon ec2 cloud osxtips



Read More about [TOTD #141: Running GlassFish 3.1 on Ubuntu 10.04 AMI on Amazon EC2...