Over a million developers have joined DZone.

Commissioning Glassfish 3 Application Servers on AWS EC2

· Cloud Zone

Download the Essential Cloud Buyer’s Guide to learn important factors to consider before selecting a provider as well as buying criteria to help you make the best decision for your infrastructure needs, brought to you in partnership with Internap.

Service Autonomy is one of the 8 key SOA design principals. One way that you can achieve better service autonomy and create more scalable services is to give each service it’s own hardware to play with. Cloud infrastructure like Amazon’s Elastic Compute Cloud (called EC2 for short) is designed to fill this need by alowing you to add hardware at short notice and scale it horizontally or vertically.

Unfortunately, none of the default machine instance types offered by Amazon EC2 at the time of writing included Glassfish 3 Java EE application servers as part of the basic install. This guide is intended to bridge that gap by showing you how you can commission your own basic Glassfish 3 installation using Amazon EC2.

Assumptions (before you start):

You’ve set yourself up with an amazon web services user account.
You can log into the AWS console and the EC2 sub-console.
You have followed Amazon’s AWS EC2 Getting Started Guide (Linux/Unix not Windows).
You have a security keypair already (part of the getting started tutorial).
You have used the browser based Java SSH client to ‘connect’ to a machine (part of the tutorial).

Warning about Free t1.Micro Instances:

Amazon’s EC2 t1.micro instances don’t meet the documented Glassfish server requirements. These instances have limited memory, cpu and bandwidth. You can run Glassfish on them, but they generally run out of memory quite quickly. On the plus side though, these t1.micro instances are free for the first year.

Steps For: Commissioning Glassfish 3 on AWS EC2.

1. Create a new EC2 machine instance using the Amazon Linux AMI (see screenshot). This is automatically EBS backed and can be 64 or 32 bit and based on a T1.Micro instance if you want to qualify for the Free service tier.

2. Once the instance has started, connect to it using the ‘connect’ option from the dropdown menu for the machine in the My Instances page.

3. Once connected, in the Java SSH client you’ll be prompted to apply a few patches to the machine using ‘sudo yum update’ command.

sudo yum update

4. If you try and run the ‘javac’ compiler command, you’ll get an error. This is because only the JRE is installed by default. To rectify this, install the full OpenJDK developer kit. Once done, the ‘javac’ command should be available. Glassfish will need this later.

sudo yum install java-1.6.0-openjdk-devel

5. Download Glassfish 3.1.2 & unzip it to the current location. Yon’t need sudo for these steps. If you use sudo, the domain won’t start properly if at all.

wget -c http://download.java.net/glassfish/3.1.2/release/glassfish-3.1.2.zip
unzip glassfish-3.1.2.zip

6. Configure Glassfish security so that you can use the built in web console. To do this we have to start the default domain, change the admin password, enable the secure admin feature and restart glassfish. To do all these things we need to start the ‘asadmin’ program that comes with glassfish…

asadmin> start-domain
asadmin> change-admin-password (initial is username:admin, password:[enter])
asadmin> enable-secure-admin (use the admin username and password which you just set)
asadmin> restart-domain
asadmin> exit

7. Open some ports for the EC2 instance security group so that you can see applications and the Glassfish console. Find the security group being used for your EC2 machine instance and enable ports 8080, 8181 and 4848 as per the following screenshot.

8. You should now be able to login to your Glassfish console. Find the ‘Public DNS’ name for this EC2 machine instance on the My Instances ‘details page’. Pop this address into a browser and append the Glassfish admin console port number on the end (4848). This will look like http://%5Byour public dns]:4848/ and after a few minutes (while the console starts) the console login screen should appear as per the screenshot below.

You should now be able to login using the admin username and password that you setup earlier and deploy applications to the Glassfish server. If you are new to Glassfish, try the Glassfish Quick Start Guide.

Optional Steps: Deploying the ‘Hello Duke’ sample web-app.

1. Stop the Glassfish server. From the asadmin program…

asadmin> stop-domain
asadmin> exit

2. Move to the autodeploy folder and download the sample application to it.

cd glassfish3/glassfish/domains/domain1/autodeploy
wget -c http://glassfish.java.net/downloads/quickstart/hello.war

3. Start the Glassfish server. From the asadmin program…

asadmin> start-domain

4: Try the sample application in your browser.

http://[your instance's public dns address here]:8080/hello

Finally, in your browser window, you should now see Java Duke and he’s asking you for your name…

The Cloud Zone is brought to you in partnership with Internap. Read Bare-Metal Cloud 101 to learn about bare-metal cloud and how it has emerged as a way to complement virtualized services.


Published at DZone with permission of Ben Wilcock, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}