Install and Configure GlassFish on AlmaLinux 8

In this article, we want to teach you How To Install and Configure GlassFish on AlmaLinux 8.

GlassFish is the open-source application server provided by Sun Microsystems for the applied science platform in Java.
It is fast, secure, production quality, high expandability, leading Java EE containers in the industry.

How To Install and Configure GlassFish on AlmaLinux 8

Before you start to install GlassFish, you need to 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 article the Initial Server Setup with AlmaLinux 8.

Now follow the steps below to install GlassFish on AlmaLinux 8.

Install Java on AlmaLinux 8

To set up GlassFish on AlmaLinux 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 AlmaLinux 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.13" 2021-10-19 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.13+8-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.13+8-LTS, mixed mode, sharing)

Set up GlassFish on AlmaLinux 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.3.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.3.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.3
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 AlmaLinux 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 AlmaLinux 8 with the command below:

sudo systemctl status glassfish

In your output you will see:

Output
glassfish.service - GlassFish Server v6.2.3
Loaded: loaded (/usr/lib/systemd/system/glassfish.service; enabled; vendor p>
Active: active (running) since Tue 2021-12-14 04:05:21 EST; 8s ago
Main PID: 89884 (java)
Tasks: 96 (limit: 11409)
Memory: 360.6M
CGroup: /system.slice/glassfish.service
└─89884 /usr/lib/jvm/java-11-openjdk-11.0.13.0.8-3.el8_5.x86_64/bin/>

Configure GlassFish on AlmaLinux 8

We assumed that you have enabled firewalld from the requirements. At this point, you need to allow GlassFish ports on AlmaLinux 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 AlmaLinux 8 to apply the changes:

sudo systemctl restart glassfish

Access GlasFish Web Interface

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 Admin console

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

GlassFish Admin interface

Conclusion

At this point, you learn to set up and configure GlassFish on AlmaLinux 8.

Hope you enjoy using it.

May this article about Set up and Configure GlassFish on Debian 11 be useful for you.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!