Install Oracle Glassfish on EC2

This is a guide on installing Oracle Glassfish on an AWS T1 Micro instance.

[ec2-user@ip-10-0-0-182 ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvde1 9.9G 1.8G 8.0G 19% /
none 296M 0 296M 0% /dev/shm
[ec2-user@ip-10-0-0-182 ~]$ cat /proc/meminfo | grep swap Swap
SwapCached: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
[ec2-user@ip-10-0-0-182 ~]$ sudo dd if=/dev/zero of=/swapfile bs=1M count=1200
425+0 records in
425+0 records out
445644800 bytes (446 MB) copied, 11.335 s, 39.3 MB/s
[ec2-user@ip-10-0-0-182 ~]$ sudo su - root
[root@ip-10-0-0-182 ~]# sudo dd if=/dev/zero of=/swapfile bs=1M count=1200
1200+0 records in
1200+0 records out
1258291200 bytes (1.3 GB) copied, 38.104 s, 33.0 MB/s
[root@ip-10-0-0-182 ~]# sudo mkswap /swapfile
mkswap: /swapfile: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 1228796 KiB
no label, UUID=95a705b9-b977-4718-865d-b1478c29a042
[root@ip-10-0-0-182 ~]# sudo swapon /swapfile
[root@ip-10-0-0-182 ~]# cat /proc/meminfo | grep Swap
SwapCached: 0 kB
SwapTotal: 1228792 kB
SwapFree: 1228792 kB
  • Next is to install the Java:
[root@ip-10-0-0-182 java]# pwd
/usr/java
[root@ip-10-0-0-182 java]# rpm -ivh ./tmp/jdk-7u45-linux-x64.rpm
Preparing... ########################################### [100%]
Unpacking JAR files...
rt.jar...
jsse.jar...
charsets.jar...
tools.jar...
localedata.jar...
jfxrt.jar...
[root@ip-10-0-0-182 java]# ls -lrt
drwxr-xr-x. 8 root root 4096 Feb 21 05:44 jdk1.7.0_45
lrwxrwxrwx. 1 root root 21 Feb 21 05:44 /usr/java/jdk1.7.0_45
lrwxrwxrwx. 1 root root 16 Feb 21 05:44 default -> /usr/java/latest
[root@ip-10-0-0-182 java]# cd /usr/java/jdk1.7.0_45/bin
[root@ip-10-0-0-182 bin]# ./java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
  • Edit the user profiles to set the JAVA variables:
[root@ip-10-0-0-182 ~]# vi .bash_profile .bashrc /etc/profile
JAVA_HOME=/usr/java/jdk1.7.0_45
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
  • Disable IP Tables
[root@ip-10-0-0-182]# service iptables stop
iptables: Flushing firewall rules: OK
iptables: Setting chains to policy ACCEPT: filter OK 
iptables: Unloading modules: OK 
[root@ip-10-0-0-182]# chkconfig iptables off

 

  • Create the glassfish user
[root@ip-10-0-0-182]# sudo add ususer --home /home/glassfish --system --shell /bin/bash glassfish
[root@ip-10-0-0-182]# sudo groupadd glassfishadm
[root@ip-10-0-0-182]# sudo usermod -a -G glassfishadm ec2-user
[root@ip-10-0-0-182]# cd /home
[root@ip-10-0-0-182 home]# mkdir glassfish
[root@ip-10-0-0-182 home]# chown glassfish:glassfishadm glassfish
[root@ip-10-0-0-182 home]# sudo su - glassfish
[bash-4.1$ pwd
/home/glassfish
[bash-4.1$ id
uid=498(glassfish) gid=498(glassfish) groups=498(glassfish) 
[bash-4.1$ vi .profile
JAVA_HOME=/usr/java/jdk1.7.0_45
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
export PS1="`hostname` glassfish :>"
[bash-4.1$ . ./.profile
ip-10-0-0-182 glassfish :>which java
/usr/java/jdk1.7.0_45/bin/java
ip-10-0-0-182 glassfish :>java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
ip-10-0-0-182 glassfish :>pwd
/home/glassfish
  • Install Glassfish
[root@ip-10-0-0-182 ]# sudo su - glassfish
ip-10-0-0-182 glassfish :>cp /tmp/ogs-3.1.2.2-unix.sh .
ip-10-0-0-182 glassfish :>ls -lrt
-rwxrwxr-x. 1 glassfish glassfishadm 62638958 Jan 14 04:39 ogs-3.1.2.2-unix.sh
ip-10-0-0-182 glassfish :>sh ogs-3.1.2.2-unix.sh -s
Extracting the installer archive...
Extracting the installer runtime...
Extracting the installer resources...
Extracting the installer metadata...
Welcome to GlassFish installer
Using the user defined JAVA_HOME : /usr/java/jdk1.7.0_45
Entering setup...
File 511/511
File 301/303
SETTING UP DOMAIN FOR SILENT INSTALL...
Executing /home/glassfish/glassfish3/glassfish/bin/asadmin --user admin --passwordfile - create-domain --savelogin --checkports=false --adminport 4848 --instanceport 8080 --domainproperties=jms.port=7676:domain.jmxPort=8686:orb.listener.port=3700:http.ssl.port=8181:orb.ssl.port=3820:orb.mutualauth.port=3920 domain1
/home/glassfish/glassfish3/glassfish/bin/asadmin --user admin --passwordfile - create-domain --savelogin --checkports=false --adminport 4848 --instanceport 8080 --domainproperties=jms.port=7676:domain.jmxPort=8686:orb.listener.port=3700:http.ssl.port=8181:orb.ssl.port=3820:orb.mutualauth.port=3920 domain1 Using port 4848 for Admin.
Using port 8080 for HTTP Instance.
Using port 7676 for JMS.
Using port 3700 for IIOP.
Using port 8181 for HTTP_SSL.
Using port 3820 for IIOP_SSL.
Using port 3920 for IIOP_MUTUALAUTH.
Using port 8686 for JMX_ADMIN.
Using default port 6666 for OSGI_SHELL.
Using default port 9009 for JAVA_DEBUGGER.
Distinguished Name of the self-signed X.509 Server Certificate is:
[CN=ip-10-0-0-182.eu-west-1.compute.internal,OU=GlassFish,O=Oracle Corporation,L=Santa Clara,ST=California,C=US]
Distinguished Name of the self-signed X.509 Server Certificate is:
[CN=ip-10-0-0-182.eu-west-1.compute.internal-instance,OU=GlassFish,O=Oracle Corporation,L=Santa Clara,ST=California,C=US]
No domain initializers found, bypassing customization step
Domain domain1 created.
Domain domain1 admin port is 4848.
Domain domain1 allows admin login as user "admin" with no password.
Login information relevant to admin user name [admin]
for this domain [domain1] stored at
[/home/glassfish/.asadminpass] successfully.
Make sure that this file remains protected.
Information stored in this file will be used by
asadmin commands to manage this domain.
Command create-domain executed successfully.
ip-10-0-0-182 glassfish :>cd glassfish3
[mip-10-0-0-182 glassfish :>pwd
/home/glassfish/glassfish3
ip-10-0-0-182 glassfish :>ls -rlt
total 272
-rw-r--r--. 1 glassfish glassfish 7620 Jul 11 2012 uninstall.sh
-rw-r--r--. 1 glassfish glassfish 223712 Jul 11 2012 uninstall.exe
drwxr-xr-x. 4 glassfish glassfish 4096 Jul 11 2012 pkg
drwxr-xr-x. 2 glassfish glassfish 4096 Jul 11 2012 toplink
drwxr-xr-x. 2 glassfish glassfish 4096 Jul 11 2012 oracle-jdbc-drivers
drwxr-xr-x. 3 glassfish glassfish 4096 Jul 11 2012 mysql-connector-java-commercial
drwxr-xr-x. 4 glassfish glassfish 4096 Jul 11 2012 javadb
drwxr-xr-x. 2 glassfish glassfish 4096 Jul 11 2012 bin
drwxr-xr-x. 5 glassfish glassfish 4096 Jul 11 2012 mq
drwxrwxr-x. 3 glassfish glassfish 4096 Feb 21 05:57 var
drwxr-xr-x. 11 glassfish glassfish 4096 Feb 21 05:57 glassfish
drwxr-xr-x. 5 glassfish glassfish 4096 Feb 21 05:57 install
drwxrwxr-x. 3 glassfish glassfish 4096 Feb 21 05:57 updatetool
ip-10-0-0-182 glassfish :> vi .profile
JAVA_HOME=/usr/java/jdk1.7.0_45
export JAVA_HOME
GLASSFISH_HOME=/home/oracle/
export GLASSFISH_HOME
PATH=$GLASSFISH_HOME/bin:$JAVA_HOME/bin:$PATH
export PATH
export PS1="`hostname` glassfish :>"
ip-10-0-0-182 glassfish :>. ./.profile
ip-10-0-0-182 glassfish :>which asadmin
~/glassfish3/bin/asadmin
  • Test Sop/Start of glassfish from command line
ip-10-0-0-182 glassfish :>asadmin start-domain domain1
Waiting for domain1 to start ..............
Successfully started the domain : domain1
domain Location: /home/glassfish/glassfish3/glassfish/domains/domain1
Log File: /home/glassfish/glassfish3/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.
ip-10-0-0-182 glassfish :>asadmin stop-domain domain1
Waiting for the domain to stop ...
Command stop-domain executed successfully.
  • Create a stop/start script
[root@ip-10-0-0-182]#  sudo vi /etc/init.d/glassfish
#!/bin/bash 
# description: Glassfish Start Stop Restart
# processname: glassfish
JAVA_HOME=/usr/java/jdk1.7.0_45
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
GLASSFISH_HOME=/home/glassfish/glassfish3/

case $1 in
start)
sh $GLASSFISH_HOME/bin/asadmin start-domain domain1
;;
stop)
sh $GLASSFISH_HOME/bin/asadmin stop-domain domain1
;;
restart)
sh $GLASSFISH_HOME/bin/asadmin stop-domain domain1
sh $GLASSFISH_HOME/bin/asadmin start-domain domain1
;;
esac
exit 0
[root@ip-10-0-0-182]# sudo chmod a+x /etc/init.d/glassfish
[root@ip-10-0-0-182]# /etc/init.d/glassfish start
starting glassfish from /home/glassfish/glassfish3/bin
Waiting for domain1 to start .............
Successfully started the domain : domain1
domain Location: /home/glassfish/glassfish3/glassfish/domains/domain1
Log File: /home/glassfish/glassfish3/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.
[root@ip-10-0-0-182]# /etc/init.d/glassfish startop
stopping glassfish from /home/glassfish/glassfish3/bin
Waiting for the domain to stop ..
Command stop-domain executed successfully.
  • Go back to the AWS console and open up the ports. Select EC2, Security Groups, Highlight your group, select Inbound and add ports 8080 and 4848 - Apply your changes. Check your URL - http://<your_host>:8080

  • Configure glassfish by first changing the master password
[root@ip-10-0-0-182 ]# sudo su - glassfish
[mip-10-0-0-182 glassfish :>asadmin start-domain fomain1domain1
Waiting for domain1 to start .............
Successfully started the domain : domain1
domain Location: /home/glassfish/glassfish3/glassfish/domains/domain1
Log File: /home/glassfish/glassfish3/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.
ip-10-0-0-182 glassfish :>asadmin change-admin-password
Enter admin user name [default: admin]> admin
Enter admin password> ##password is changeit##
Enter new admin password>
Enter new admin password again>
Command change-admin-password executed successfully.
ip-10-0-0-182 glassfish :>asadmin
Use "exit" to exit and "help" for online help.
asadmin> login
Enter admin user name [default: admin]> admin
Enter admin password>
Admin login information for host [localhost] and port [4848]
is being overwritten with credentials provided because the
--savelogin option was used during the create-domain command.
Login information relevant to admin user name [admin]
for host [localhost] and admin port [4848] stored at
[/home/glassfish/.asadminpass] successfully.
Make sure that this file remains protected.
Information stored in this file will be used by
asadmin commands to manage the associated domain.
Command login executed successfully.
asadmin> exit
Command multimode executed successfully.
ip-10-0-0-182 glassfish :>asadmin stop-domain domain1
Waiting for the domain to stop .....
Command stop-domain executed successfully.
  • Start glassfish and login as admin http://<your_host>:4848
[mip-10-0-0-182 glassfish :>./asadmin start-domain domain1
Waiting for domain1 to start ...............
Successfully started the domain : domain1
domain Location: /home/glassfish/glassfish3/glassfish/domains/domain1
Log File: /home/glassfish/glassfish3/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.
If you receive the "Secure Admin" warning below then we need to enable it:
  • Enable glassfish secure admin
ip-10-0-0-182 glassfish :>pwd
/home/glassfish/glassfish3/bin
ip-10-0-0-182 glassfish :>echo hostname
ip-10-0-0-182
ip-10-0-0-182 glassfish :>asadmin --host ip-10-0-0-182 --port 4848 enable-secure-admin
Enter admin user name> admin
Enter admin password for user "admin">
You must restart all running servers for the change in secure admin to take effect.
Command enable-secure-admin executed successfully.
ip-10-0-0-182 glassfish :>asadmin stop-domain domain1
Waiting for the domain to stop .....
Command stop-domain executed successfully.
[mip-10-0-0-182 glassfish :>./asadmin start-domain domain1
Waiting for domain1 to start ...............
Successfully started the domain : domain1
domain Location: /home/glassfish/glassfish3/glassfish/domains/domain1
Log File: /home/glassfish/glassfish3/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.

Login again http://<your_host>:4848 and you should be presented with the certificate message

Login with your admin user and password

  • Deploy an application
Open the Admin Console in a web browser if you have not done so already. In the left pane, click the Applications node to expand it.

Click Web Applications. You can see the list of deployed web applications, if any. Click Deploy.

Download the hello.war file and navigate to the directory to which you have downloaded the application.

Click OK

Now finally launch the application in another browser by going to url http://your-host:8080/hello/