Published January 12, 2018 by

Install Glassfish Server in CentOS/Redhat

Prerequisites

Before Installing GlassFish server, you need to install following items on your server:
  • Java/JDK
  • unzip
  • wget
Install unzip and wget

If you are already installed unzip,wget and java so skip this step. Otherwise, you can install it using the following command.

# yum install unzip -y
# yum install wget -y


Install Java in CentOS/Redhat

# cd /opt

# 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/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.tar.gz"

# tar xzf jdk-8u161-linux-x64.tar.gz

After extracting java file use alternatives command to install it. alternatives command is available in chkconfig package.

# cd /opt/jdk1.8.0_161/
# alternatives --install /usr/bin/java java /opt/jdk1.8.0_161/bin/java 2
# alternatives --config java


There is 1 program that provides 'java'.

  Selection    Command

-----------------------------------------------

*+ 1           /opt/jdk1.8.0_161/bin/java

Enter to keep the current selection[+], or type selection number: 1

Setup javac and jar commands path using alternatives:

# alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_161/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_161/bin/javac 2
# alternatives --set jar /opt/jdk1.8.0_161/bin/jar
# alternatives --set javac /opt/jdk1.8.0_161/bin/javac

Check Java Version

# java -version


Set Java Environment Variable

Setup JAVA_HOME, JRE_HOME and PATH environment variables

# export JAVA_HOME=/opt/jdk1.8.0_161
# export JRE_HOME=/opt/jdk1.8.0_161/jre

Also insert above environment variables in /etc/environment file.


Install GlassFish Server

Change to the directory where you want to install the GlassFish server


OR

# wget http://download.java.net/glassfish/4.1.2/release/glassfish-4.1.2.zip

Unzip glassfish-4.1.2.zip

# unzip glassfish-4.1.2.zip
# rm -rf glassfish-4.12.zip

Start GlassFish Server

# /usr/share/glassfish4/glassfish/bin/asadmin start-domain domain1


Now the glassfish server is started. Glassfish server by default runs on 4848 port. Before login, you need to change the admin password and redirect to secure port.

# /usr/share/glassfish4/bin/asadmin change-admin-password


Here it will ask for admin name, admin password, new admin password, confirm admin password. Remember glassfish default admin password is blank.


# /usr/share/glassfish4/bin/asadmin enable-secure-admin


Here it will ask for admin name, admin password gives this details and restarts glassfish.

Restart GlassFish Server

# /usr/share/glassfish4/glassfish/bin/asadmin restart-domain domain1


Now you can access URL: your_ip_address:4848 and log in with credentials.



After login GlashFish server Console appears.


Stop GlassFish Server

# /usr/share/glassfish4/glassfish/bin/asadmin stop-domain domain1


Channge Admin Password/Forgot Admin Password

To reset the admin password in glassfish replace the file content of domain\config\admin-keyfile with the following:

admin;{SSHA256}UV9EsTaoxzAdtxiNMKTkb3g0WjnoUBEBgpDQIGSdOu8QhprFoWiSCw==;asadmin

This will give you a username of 'admin' and password 'changeit'. After changing the file you need to restart the service.