TOTD #141: Running GlassFish 3.1 on Ubuntu 10.04 AMI on Amazon EC2
By arungupta on Jun 24, 2010
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
Lets get started!
- In your home directory, create a new ".ec2" directory.
Generate SSH Key & X.509 certificates
Generate X.509 certificates key
- Go to your AWS account 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".
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".
- Generate X.509 certificates key
EC2 API Tools
- Download Amazon EC2 API Tools from here and unzip them in ".ec2" directory.
- Move "lib" and "bin" directory from the extracted directory to ".ec2" directory.
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:
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
Run the instance as:
ec2-run-instances ami-c597c680 -k ec2-keypair
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.
SSH to the ready Ubuntu instance as:
ssh -i ec2-keypair.pem ubuntu@ec2-XX-XX-XX-XX.us-west-1.compute.amazonaws.com
Install JDK 6 on Ubuntu
Add the Ubuntu partner repository as:
sudo add-apt-repository "deb http://archive.canonical.com/ 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
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
- Add the Ubuntu partner repository as:
Install "unzip" package as:
sudo apt-get install unzip
Download & start GlassFish 3.1
Download GlassFish 3.1 Milestone 2 as:
Unzip the downloaded zip file as:
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".
- Download GlassFish 3.1 Milestone 2 as:
Finally terminate the instance as:
How are you using GlassFish in the cloud ?