TOTD #141: Running GlassFish 3.1 on Ubuntu 10.04 AMI on Amazon EC2
GlassFish 3.1 Milestone 2 was released this week, download the [URL="http://dlc.sun.com.edgesuite.net/glassfish/3.1/promoted/glassfish-3.1-b06.zip"]zip file[/URL].
[URL="http://blogs.sun.com/arungupta/entry/totd_138_glassfish_3_1"]TOTD #138[/URL] 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 [B]T[/B]ip [B]O[/B]f [B]T[/B]he [B]D[/B]ay (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:
[LIST] [*][URL="http://www.robertsosinski.com/2008/01/26/starting-amazon-ec2-with-mac-os-x/"]Starting Amzon EC2 with Mac OS X[/URL] [*][URL="https://help.ubuntu.com/community/EC2StartersGuide"]EC2 Starters Guide on Ubuntu[/URL] [*][URL="http://uec-images.ubuntu.com/releases/10.04/release/"]Ubuntu 10.04 LTS Daily Build - Amazon Published EC2 AMIs[/URL] [*][URL="http://www.cyberciti.biz/faq/howto-ubuntu-linux-install-configure-jdk-jre/"]Ubuntu Linux Install Sun JDK and JRE[/URL] [*][URL="http://www.clickonf5.org/linux/how-install-sun-java-ubuntu-1004-lts/7777"]How to install Sun Java on Ubuntu 10.04 LTS[/URL] [/LIST] [URL="http://twitter.com/#search?q=ubuntu%20arungupta"]Twitterverse[/URL] was very helpful and [URL="http://blogs.sun.com/divyen/"]Divyen[/URL] helped smoothen the rough edges!
Lets get started!
[LIST=1] [*]In your home directory, create a new ".ec2" directory. [*] Generate SSH Key & X.509 certificates[LIST=1] [*] Generate X.509 certificates key[LIST=1] [*]Go to your [URL="http://aws.amazon.com/account/"]AWS account[/URL] and click on "Security Credentials". [*]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". [/LIST] [*] 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". [/LIST] [*] EC2 API Tools[LIST=1] [*]Download Amazon EC2 API Tools from [URL="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=351&categoryID=88"]here[/URL] and unzip them in ".ec2" directory. [*]Move "lib" and "bin" directory from the extracted directory to ".ec2" directory. [/LIST] [*] 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" [*] 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 [*] Obtain the public IP address of Ubuntu instance as:
[B]ec2-describe-instances[/B] 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. [*] SSH to the ready Ubuntu instance as:
ssh -i ec2-keypair.pem [email]ubuntu@ec2-XX-XX-XX-XX.us-west-1.compute.amazonaws.com[/email] [*] Install JDK 6 on Ubuntu[LIST=1] [*] Add the Ubuntu partner repository as: sudo add-apt-repository "deb [url]http://archive.canonical.com/[/url] lucid partner" [*] Update the list of packages as:
sudo apt-get update [*] Install JDK 6 as: sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk [*]Add "/usr/lib/jvm/java-6-sun" to the top of "/etc/jvm" file. This file defines the default system JVM search order. [/LIST] [*] Install "unzip" package as:
sudo apt-get install unzip [*] Download & start GlassFish 3.1[LIST=1] [*] Download GlassFish 3.1 Milestone 2 as:
wget [url]http://dlc.sun.com.edgesuite.net/glassfish/3.1/promoted/glassfish-3.1-b06.zip[/url] [*] Unzip the downloaded zip file as:
unzip glassfish-3.1-b06.zip [*] Start GlassFish as:
./glassfishv3/glassfish/bin/asadmin start-domain --verbose [*]And now your default web page is accessible at "http://ec2-XX-XX-XX-XX.us-west-1.compute.amazonws.com:8080". [/LIST] [*] Finally terminate the instance as:
ec2-terminate-instances i-XXXXXXXX [/LIST] How are you using GlassFish in the cloud ?
Technorati: [URL="http://technorati.com/tags/totd"]totd[/URL] [URL="http://technorati.com/tags/glassfish"]glassfish[/URL] [URL="http://technorati.com/tags/ubuntu"]ubuntu[/URL] [URL="http://technorati.com/tags/amazon"]amazon[/URL] [URL="http://technorati.com/tags/ec2"]ec2[/URL] [URL="http://technorati.com/tags/cloud"]cloud[/URL] [URL="http://technorati.com/tags/osxtips"]osxtips[/URL]
[url=http://blogs.sun.com/arungupta/entry/totd_141_running_glassfish_3]Read More about [TOTD #141: Running GlassFish 3.1 on Ubuntu 10.04 AMI on Amazon EC2...[/url]