Miles to go …

June 24, 2010

TOTD #141: Running GlassFish 3.1 on Ubuntu 10.04 AMI on Amazon EC2

Filed under: General — arungupta @ 11:48 am

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:

  • Starting Amzon EC2 with Mac OS X
  • EC2 Starters Guide on Ubuntu
  • Ubuntu 10.04 LTS Daily Build – Amazon Published EC2 AMIs
  • Ubuntu Linux Install Sun JDK and JRE
  • How to install Sun Java on Ubuntu 10.04 LTS

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. Run the instance as:
    ec2-run-instances ami-c597c680 -k ec2-keypair
    
  7. 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.

  8. SSH to the ready Ubuntu instance as:
    ssh -i ec2-keypair.pem [email protected]
    

  9. 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. Make sure the recently added JDK is at the top of JVM search order by giving the command:
      sudo update-java-alternatives -s java-6-sun
      

      This command adds "/usr/lib/jvm/java-6-sun" to the top of "/etc/jvm" file.

  10. Install "unzip" package as:
    sudo apt-get install unzip
    
  11. Download & start GlassFish 3.1
    1. Download GlassFish 3.1 Milestone 2 as:
      wget http://dlc.sun.com.edgesuite.net/glassfish/3.1/promoted/glassfish-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".
  12. 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

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
Related posts:
  1. TOTD #142: GlassFish 3.1 – SSH Provisioning and Start/Stop instance/cluster on local/remote machines
  2. TOTD #92: Session Failover for Rails applications running on GlassFish
  3. TOTD #21: Metro 1.1 with GlassFish v2 UR1 and NetBeans 6
  4. TOTD #18: How to Build The GlassFish v3 Gem for JRuby ?
  5. TOTD #152: GlassFish Installer – Typical and Custom installation

4 Comments »

  1. Good stuff, but I’d recommend a small change: Instead of manually updating the /etc/jvm file in step 9.4, you should use the following: "sudo update-java-alternatives -s java-6-sun", which is documented here: https://help.ubuntu.com/community/Java.

    Comment by Chad S — June 25, 2010 @ 5:10 am

  2. Thanks for the tip Chad,

    Updated the blog with that change.

    Comment by Arun Gupta — June 25, 2010 @ 11:21 am

  3. The installation is the real sticking point for me; is there really still no .dpkg or .rpm for Glassfish v3 yet?

    Untarring binaries is not fun at cloud scale.

    Comment by Dick Davies — July 19, 2010 @ 3:29 am

  4. I wondered why you need to get the Sun Java6 from a non-standard repository instead of the OpenJDK which is available in the default repositories?

    Found an incompatability?

    Comment by Thorbjørn Ravn Andersen — September 24, 2010 @ 4:16 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.
Powered by WordPress