Install and Configure GlassFish on Rocky Linux 8

In this tutorial, we intend to teach you How To Install and Configure GlassFish on Rocky Linux 8.

GlassFish is a free, open-source software application server (under CDDL * and GNU GPL licenses), and free that was developed by Sun Microsystems (now Oracle). It implements technologies defined in the Java EE platform of this company and allows running apps that support this specification.

Steps To Install and Configure GlassFish on Rocky Linux 8

To install GlassFish, 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 8.

Installing Java on Rocky Linux 8

To set up GlassFish on Rocky Linux 8 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

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

sudo dnf install java-11-openjdk-devel

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" 2022-07-19 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.16.0.8-1.el8_6) (build 11.0.16+8-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.16.0.8-1.el8_6) (build 11.0.16+8-LTS, mixed mode, sharing)

Installing GlassFish on Rocky Linux 8

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

sudo useradd -s /sbin/nologin 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:

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/

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:

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

Then, start your GlassFish service on Rocky Linux 8 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 8 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 p>
   Active: active (running) since Thu 2022-09-01 06:25:48 EDT; 19s ago
 Main PID: 90152 (java)
    Tasks: 101 (limit: 11413)
   Memory: 338.4M
   CGroup: /system.slice/glassfish.service
           └─90152 /usr/lib/jvm/java-11-openjdk-11.0.16.0.8-1.el8_6.x86_64/bin/>

Configure GlassFish on Rocky Linux 8

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

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 8 to apply the changes:

sudo systemctl restart glassfish

Access GlassFish Administration 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.

GlassFish login screen

Enter your GLassFish admin username and password and you will see the GlassFish Admin interface:

GlassFish console

Conclusion

At this point, you learn to Install and Configure GlassFish on Rocky Linux 8.

Hope you enjoy it.

You may be interested in these articles:

Install and Configure Nextcloud on Rocky Linux 8

How To Install Brotli Compression on Rocky Linux 8

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!