How To Install GlassFish on Rocky Linux 9

This guide intends to show you How To Install and Configure GlassFish on Rocky Linux 9.

GlassFish is an open-source, freely available, Java EE (called J2EE formerly) application server. Like all Java EE-compliant application servers, GlassFish provides the necessary libraries to develop and deploy Java applications compliant with Java EE specifications. Java EE technologies include Servlets, JavaServer Pages (JSPs), JavaServer Faces (JSF), Enterprise JavaBeans (EJBs), and the Java Messaging Service (JMS).

Steps To Install and Configure GlassFish on Rocky Linux 9

To complete this guide, you must log in to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, you can follow our guide the Initial Server Setup with Rocky Linux 9.

Install Java on Rocky Linux 9

To set up GlassFish on Rocky Linux 9, you need Java installed on your server. First, update your local package index with the following command:

sudo dnf update

Then, you need to install the Epel release on your server with the command below:

sudo dnf install epel-release -y

Now install Java on Rocky Linux 9 with the following command:

sudo dnf install java-11-openjdk-devel -y

When your installation is completed, verify your Java installation by checking its version:

java -version

In your output you will see:

Output
openjdk version "11.0.16.1" 2022-08-12 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.16.1.1-1.el9_0) (build 11.0.16.1+1-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.16.1.1-1.el9_0) (build 11.0.16.1+1-LTS, mixed mode, sharing)

Set up GlassFish on Rocky Linux 9

To install GlassFish, you need to create a user for your GlassFish with the following command:

sudo useradd -s /sbin/nologin glassfish

Download GlassFish

Now check the latest version of GlassFish from the GlassFish Downloads Page.

Then, you need to download the GlassFish installer with the following command:

sudo wget https://download.eclipse.org/ee4j/glassfish/glassfish-6.2.5.zip

Remember to replace the version of GlassFish that you have checked in the above command.

Extract your downloaded file with the command below:

sudo unzip -d /opt/ glassfish-6.2.5.zip

Here you need to set the correct permissions for the GlassFish user with the following command:

sudo chown -R glassfish:glassfish /opt/glassfish6/

Create Systemd Unit File For GlassFish

Next, you need to create a systemd unit file for GlassFish. Create and open the file with your favorite text editor, here we use vi editor:

sudo vi /usr/lib/systemd/system/glassfish.service

Add the following contents to the file:

[Unit]
Description = GlassFish Server v6.2.5
After = syslog.target network.target

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

[Install]
WantedBy = multi-user.target

When you are done, save and close the file.

reload the systemd daemon to apply the new changes with the following command:

sudo systemctl daemon-reload

Start and Enable GlassFish Service

Then, start your GlassFish service on Rocky Linux 9 with the following command:

sudo systemctl start glassfish

To enable GlassFish to start at boot run the following command:

sudo systemctl enable glassfish

Now you can check that your GlassFish service is active and running on Rocky Linux 9 with the command below:

sudo systemctl status glassfish

In your output you will see:

Output
● glassfish.service - GlassFish Server v6.2.5
     Loaded: loaded (/usr/lib/systemd/system/glassfish.service; enabled; vendor>
     Active: active (running) since Sat 2023-01-06 06:48:24 EDT; 16s ago
   Main PID: 16744 (java)
      Tasks: 98 (limit: 23609)
     Memory: 383.2M
        CPU: 16.098s
     CGroup: /system.slice/glassfish.service
...

Configure Firewall For GlassFish

We assumed that you have enabled firewalld from the requirements. At this point, you need to allow GlassFish ports on the Rocky Linux firewall with the command below:

sudo firewall-cmd --add-port={4848,8080,8181}/tcp --permanent 

Then, reload the firewall to apply the new rules:

sudo firewall-cmd --reload

Configure GlassFish on Rocky Linux 9

By default, GlassFish has no password. For more security, you need to set a password for the GlassFish admin user. To do this, run the following command:

sudo /opt/glassfish6/bin/asadmin --port 4848 change-admin-password

You will be asked to set the admin username as shown below:

Enter admin user name [default: admin]>admin

Next, you will be asked to enter the existing admin password, just press enter to continue:

Enter the admin password>

Here you will be asked to enter the new admin password. Enter your password and press enter. In your output you will see:

Output
Command change-admin-password executed successfully.

It’s recommended to enable secure login for the GlassFish admin console with the following command:

sudo /opt/glassfish6/bin/asadmin --port 4848 enable-secure-admin

You need to enter your username and password, in your output you will see:

Output 
Command enable-secure-admin executed successfully.

Restart your GlassFish on Rocky Linux 9 to apply the changes:

sudo systemctl restart glassfish

Access GlasFish Admin Web Console

At this point, you can access the GlassFish admin console by typing your server’s IP address in your web browser followed by 4848:

http://your-server-ip-address:4848

You will see the GlassFish Administration console login screen. Enter your GLassFish admin username and password and click Login.

GlassFish login screen
GlassFish Login Screen

Now you can see your GlassFish Admin console on Rocky Linux 9.

GlassFish dashboard
GlassFish Console

That’s it, you are done.

Coclusion

At this point, you have learned to Install and Configure GlassFish on Rocky Linux 9.

Hope you enjoy it.

You may be interested in these articles:

Install Python 3.11 on Rocky Linux 9

How To Install PHP 8.2 on Rocky Linux 9

Install Caddy Web Server on Rocky Linux 8

Install and Use htop command on Rocky Linux 8

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular