Skip to content

Latest commit

 

History

History
190 lines (126 loc) · 5.26 KB

README.md

File metadata and controls

190 lines (126 loc) · 5.26 KB

Running Java EE on AWS EC2

Stack:

  • EC2
  • GlassFish 4.1
  • OpenJDK 1.8.0_131

Provisioning AWS infrastructure

  • Log to AWS EC2 Console and Click on Launch Instance:

alt text

  • Select the AMI of your choice. In this demo we will use Ubuntu.

alt text

  • Select the Instance Type and click "Next: Configure Instance Details"

alt text

  • Take all the default values, but make sure that "Auto-assign Public IP" is set to Enable. Click "Next: Add Storage"

alt text

  • Take all the default values. Click "Next: Add Tags"

alt text

  • Always tag your AWS resources. Click "Next: Configure Security Group"

alt text

  • Create a new Security Group. Security Group acts as a virtual firewall that controls the traffic for one or more EC2 instances. In this case we need to:

    • Allow SSH incoming traffic
    • Allow web traffic on port 8080 for the Cargo Tracker application
    • Allow web traffic on port 4848 for GlassFish Admin Console

    Note: As displayed in the Warning box, opening ports to the whole world (0.0.0.0) is not a recommended approach and it is only used for the purposes of this demo

  • Click "Review and Launch"

alt text

  • Review your configuration. Click "Launch"

alt text

  • Select a key pair that will later be used to SSH to the Linux server. Click "Launch Instances"

    For more information on key Pairs check the References link: AWS Key Pairs

alt text

  • Your instance will be provisioned, usually in a few minutes. Click "View Instances"

alt text

  • Wait until the EC2 instance finishes the provisioning process, moving the Status Check from "initializing" ...

alt text

  • To "2/2 checks passed". With this, we are ready to setup GlassFish!

alt text

GlassFish setup

  • Find the EC2 instance Public IP address:

alt text

  • Open your favorite command line and SSH to the EC2 instance:
ssh -v -i rbortoloto_oregon_keypair.pem ubuntu@34.212.44.118

Install Java

  • Pick your JRE

OpenJDK

sudo apt-get update
sudo apt-get install default-jre

Oracle JDK

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
  • Check Java Version
# Check version
java -version

# Find java home
sudo update-alternatives --config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
Nothing to configure.
  • Setup JAVA_HOME
# Update environment
sudo echo "JAVA_HOME=/etc/environment" >> /etc/environment
source /etc/environment

# Validate
echo $JAVA_HOME
/usr/lib/jvm/java-8-openjdk-amd64

GlassFish

  • Download GlassFish:
wget http://download.java.net/glassfish/4.1.2/release/glassfish-4.1.2.zip
  • Unzip the downloaded file and enter the folder: cd glassfish4. Start the default domain:
bin/asadmin start-domain
Waiting for domain1 to start ......
Successfully started the domain : domain1
domain  Location: /home/ubuntu/glassfish4/glassfish/domains/domain1
Log File: /home/ubuntu/glassfish4/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.
  • Enable Secure Admin to access the DAS remotely:
# Change the default GlassFish admin user password (empty/none)
bin/asadmin change-admin-password

# Enable secure admin
bin/asadmin enable-secure-admin

# Restart the domain
bin/asadmin restart-domain
  • Open the browser pointing to the EC2 Instance public IP address on port 4848:

alt text

Deploying the Cargo Tracker application

  • Deploy the war file
# Download the war file for deployment
wget https://github.com/rstrazza/cargotracker-war/cargo-tracker.war

# From the Glassfish home folder, deploy the artifact
ubuntu@ip-172-31-47-128:~/glassfish4$ bin/asadmin deploy ~/cargo-tracker.war
Enter admin user name>  admin
Enter admin password for user "admin">
Application deployed with name cargo-tracker.
Command deploy executed successfully.
  • Open the browser pointing to the EC2 Instance public IP address on port 8080:

alt text

References