Commissioning Glassfish 3 application servers on AWS EC2
Join the DZone community and get the full member experience.Join For Free
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…
./glassfish3/glassfish/bin/asadmin 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…
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…
about the author.
ben wilcock is a freelance soa certified architect with a reputation for delivering exceptional service oriented architectures. you can read his blog at http://benwilcock.wordpress.com/ or contact him via his website at http://www.soagrowers.com/ “.
Published at DZone with permission of Ben Wilcock, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.