In this tutorial, we will show you how to install GlassFish on CentOS 8. For those of you who didn’t know, GlassFish is a popular app server that can run java based web applications for you. GlassFish 5 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 and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of GlassFish on a CentOS 8.
Prerequisites
- A server running one of the following operating systems: CentOS 8.
- 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 theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install GlassFish on CentOS 8
Step 1. First, let’s start by ensuring your system is up-to-date.
sudo dnf clean all sudo dnf update
Step 2. Installing OpenJDK.
Currently, there are two LTS versions of OpenJDK – OpenJDK 8 and OpenJDK 11. You can also install both Java versions on any system and use them as per your requirements.
- Installing OpenJDK 11.
sudo dnf install java-11-openjdk-devel
- Installing OpenJDK 8.
sudo dnf install java-1.8.0-openjdk-devel
Verify Java version:
java -version
Step 3. Installing Glassfish on CentOS 8.
First, create a user for Glassfish:
useradd -s /sbin/nologin glassfish
Next, download the latest stable version of GlassFish, At the moment of writing this article it is version 5:
wget http://download.oracle.com/glassfish/5.0/release/glassfish-5.0.zip unzip -d /opt/ glassfish-5.0.zip
Assign the ownership of /opt/glassfish5
the directory to glassfish users:
chown -R glassfish:glassfish /opt/glassfish5/
Step 4. Create systemd service.
Now we create systemd
service (glassfish.service) for the Glassfish server:
nano /usr/lib/systemd/system/glassfish.service
Add the following code lines:
[Unit] Description = GlassFish Server v5.0 After = syslog.target network.target [Service] User = glassfish ExecStart = /usr/bin/java -jar /opt/glassfish5/glassfish/lib/client/appserver-cli.jar start-domain ExecStop = /usr/bin/java -jar /opt/glassfish5/glassfish/lib/client/appserver-cli.jar stop-domain ExecReload = /usr/bin/java -jar /opt/glassfish5/glassfish/lib/client/appserver-cli.jar restart-domain Type = forking [Install] WantedBy = multi-user.target
Save changes and exit the file and start the glassfish server also set it to start automatically on boot:
sudo systemctl start glassfish.service sudo systemctl enable glassfish.service
Step 5. Configure Firewall.
Open HTTP port in the firewall:
sudo firewall-cmd --add-port={4848,8080,8181}/tcp --permanent sudo firewall-cmd --reload
Step 6. Accessing GlassFish Web Interface.
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://your-domain.com:8080
or http://server-ip-address:4848
and complete the required steps to finish the installation.
Congratulations! You have successfully installed GlassFish. Thanks for using this tutorial for installing the GlassFish 5 in the CentOS 8 system. For additional help or useful information, we recommend you to check the official GlassFish website.