CentOSLinuxTutorials

How To Install GlassFish on CentOS 7

Install GlassFish on CentOS 7

In this tutorial, we will show you how to install and configuration of GlassFish on your CentOS 7. For those of you who didn’t know, GlassFish is a popular app server that can run java based web applications for you. GlassFish 4.1 release supports the latest Java Platform: Enterprise Edition 7. It supports Enterprise JavaBeans, JPA, JavaServer Faces, JMS, RMI, JavaServer Pages, servlets, etc.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple. I will show you the step-by-step installation of GlassFish on CentOS 7.

Prerequisites

  • A server running one of the following operating systems: CentOS 7.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install GlassFish on CentOS 7

Step 1. First of all, make sure that all packages are up to date.

yum -y update

Step 2. Install Java JDK 8 on CentOS 7.

At the time of writing this tutorial, the latest Java JDK version was JDK 8u45. First, let us download the latest Java SE Development Kit 8 release from its official download page or use the following commands to download from a shell:

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/8u45-b14/jdk-8u45-linux-x64.tar.gz"
tar xzf jdk-8u45-linux-x64.tar.gz

After extracting the archive file use the alternatives command to install it. alternatives command is available in chkconfig package:

cd /opt/jdk1.8.0_45/
alternatives --install /usr/bin/java java /opt/jdk1.8.0_45/bin/java 2
alternatives --config java
There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  1           /opt/jdk1.7.0_71/bin/java
 + 2           /opt/jdk1.8.0_25/bin/java
   3           /opt/jdk1.8.0_45/bin/java

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

At this point, JAVA 8 (JDK 8u45) has been successfully installed on your system. We also recommend setting up the javac and jar commands path using alternatives:

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

Checking Installed java version:

root@idroot.us ~# java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

Step 3. Install GlassFish.

GlassFish should not run under root privileges, to run it as a non-root user we will create a user glassfish. If you wish to run glassfish as root simply skip this step and perform everything as root, however, I strongly discourage that. The user’s home directory will be the glassfish directory:

adduser \
   --comment 'Glassfish User' \
   --home-dir /home/glassfish \
   glassfish

Download the latest stable version of GlassFish, At the moment of writing this article it is version 4.1:

su - glassfish
wget http://download.java.net/glassfish/4.1/release/glassfish-4.1.zip
unzip glassfish-4.1.zip
rm -f glassfish-4.1.zip

Switch back to the root user:

exit

Step 4. Create systemd service.

To create a new systemd service for GlassFish, open your editor of choice, and create a new file:

nano /etc/systemd/system/glassfish.service

Add the following code lines:

Unit]
Description = GlassFish Server v4.1
After = syslog.target network.target

[Service]
User=glassfish
ExecStart = /usr/bin/java -jar /home/glassfish/glassfish4/glassfish/lib/client/appserver-cli.jar start-domain
ExecStop = /usr/bin/java -jar /home/glassfish/glassfish4/glassfish/lib/client/appserver-cli.jar stop-domain
ExecReload = /usr/bin/java -jar /home/glassfish/glassfish4/glassfish/lib/client/appserver-cli.jar restart-domain
Type = forking

[Install]
WantedBy = multi-user.target

Start the glassfish server and set it to start automatically on boot:

systemctl enable glassfish.service
systemctl start glassfish.service

Verify the unit started:

journalctl -f -u glassfish.service

Step 5. Configure firewall rule for GlassFish.

firewall-cmd --zone=pubic --add-port=8080/tcp --permanent  
firewall-cmd --permanent --add-port=4848/tcp
firewall-cmd --reload

Step 6. Accessing GlassFish.

GlassFish will be available on HTTP port 8080 by default and also port 4848 by the administration. Open your favorite browser and navigate to http://yourdomain.com:8080 or http://server-ip:4848 and complete the required steps to finish the installation. If you are using a firewall, please open ports 8080 and 4848 to enable access to the control panel.

Congratulations! You have successfully installed GlassFish. Thanks for using this tutorial for installing GlassFish on CentOS 7 system. For additional help or useful information, we recommend you to check the official GlassFish website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button