Friday, January 29, 2016

Install GlassFish Server on Cent OS VPS

Install JDK

Create a directory where you want to install JDK:
# mkdir /usr/java
Change to the directory:
# cd /usr/java
Download the latest stable JDK (32 bit or 64 bit):
wget -- no-cookies -- no-check- certificate -- header "Cookie:
gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" “http://download.oracle.com/otn-pub/java/jdk/8u25- b17/jdk-8u25-linux- i586.tar.gz”
Unpack the downloaded JDK file into the newly created directory:
# tar -xzf jdk-8u25- linux-i586.tar.gz
Set the PATH for the JDK installation by editing your ‘~/.bash_profile’ file

and adding the following lines:
JAVA_HOME=/usr/java/jdk1.8.0_25
PATH=$JAVA_HOME/bin:$PATH
After setting the PATH variable, execute:
# .bash_profile
Or you can simply exit and open the command prompt again.
Check if the PATH is set correctly:
# echo $JAVA_HOME

Install the GlassFish Server

Change to the directory where you want to install the GlassFish application:
# cd /opt
Download the latest GlassFish zip installation file:
# wget http://download.java.net/glassfish/4.1/release/glassfish-4.1.zip
Unpack the downloaded zip file:
# unzip glassfish-4.1.zip
Usually the zip file is extracted to a directory called ‘/glassfish4′
Since it is not recommended to run the glassfish process as root, we need to add group and user for the GlassFish application:
# groupadd glassfish
# useradd -s /bin/bash -g glassfish glassfish
# chown -R glassfish: /opt/glassfish4/
Change the password for the ‘glassfish’ user:
# passwd glassfish
Changing password for user glassfish.
New password:
Create a start/stop/restart script:

#!/usr/bin/env bash
# description: Glassfish start/stop/restart
# processname: glassfish
# chkconfig: 2445 20 80
JAVA_HOME=/usr/java/jdk1.7.0_05
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
GLASSFISH_HOME=/opt/glassfish3/glassfish/
GLASSFISH_USER=glassfish

case $1 in
start)
    su $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin start-domain domain1"
;;
stop)
    su $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin stop-domain domain1"
;;
restart)
    su $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin stop-domain domain1"
    su $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin start-domain domain1"
;;
esac
exit 0

Save the script and make it executable:
# chmod +x /etc/init.d/glassfish
If you want to start up your GlassFish application on boot execute the following commands:
# chkconfig --add glassfish
# chkconfig glassfish on
To start/stop/restart Glassfish use the command:
# /etc/init.d/glassfish start/stop/restart
Once the installation is completed, you can open the default GlassFish homepage at http://domain.com:8080 or the GlassFish admin console at http://domain.com:4848 
To access GlassFish admin 
Go to the ‘bin’ directory in Glashfish directory
Change the password of admin this way:
./asadmin -- host localhost -- port 4848 change-admin-password
It will prompt you with user, type "admin", admin password, retype admin password.

Once this is done, enable the security with the following command:
./asadmin -- host localhost -- port 4848 enable-secure-admin
(Default admin password is [empty])

References:
https://www.rosehosting.com/blog/install-glassfish- on-a- centos-6- vps/
https://ivan-site.com/2012/05/download- oracle-java- jre-jdk- using-a- script/
http://stackoverflow.com/questions/8619063/glassfish-3- 1-1- how-to- enable-secure-admin- for-different- domains
http://www.howtogeek.com/102468/a-beginners- guide-to- editing-text- files-with-vi/

Video