How To Install GlassFish on AlmaLinux 9 | Best Java Server

Posted on

How To Install GlassFish on AlmaLinux 9 | Best Java Server

How To Install GlassFish on AlmaLinux 9 | Best Java Server

This comprehensive guide, brought to you by Orcacore, will walk you through the process of How To Install GlassFish on AlmaLinux 9. GlassFish is a powerful, open-source application server that provides a reliable platform for deploying Java EE applications. Originally started by Sun Microsystems, the GlassFish project is now sponsored by Oracle Corporation, with the supported version known as Oracle GlassFish Server. Being free software, GlassFish is dual-licensed under the Common Development and Distribution License (CDDL) and the GNU General Public License (GPL) with the classpath exception. This makes it a great choice for developers looking for a robust and flexible Java server. Let’s explore How To Install GlassFish on AlmaLinux 9.

Steps To Install and Configure GlassFish on AlmaLinux 9

Before you begin, ensure you have the following prerequisites:

  • A server running AlmaLinux 9.
  • A non-root user with sudo privileges.
  • A basic firewall configured.

If you haven’t already done so, you can follow our guide on Initial Server Setup with AlmaLinux 9.

1. Installing Java for GlassFish Setup

GlassFish requires Java to be installed on your server. Follow these steps:

First, update your local package index:

sudo dnf update -y

Next, install the EPEL (Extra Packages for Enterprise Linux) repository:

sudo dnf install epel-release -y

Now, install Java (OpenJDK 11) on AlmaLinux 9:

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

Verify the Java installation by checking the version:

java -version

You should see output similar to this:

**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)

2. Install GlassFish on AlmaLinux 9

Let’s proceed with the installation of GlassFish:

Create a dedicated user for GlassFish:

sudo useradd -s /sbin/nologin glassfish

Check the latest version of GlassFish from the GlassFish Downloads Page.

Download the GlassFish installer (adjust the version number as needed):

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

Extract the downloaded file:

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

Set the correct permissions for the GlassFish user:

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

Create a Systemd Unit File For GlassFish

Create a systemd unit file to manage the GlassFish service. Open the file using your preferred text editor (e.g., 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

Save and close the file.

Reload the systemd daemon to apply the changes:

sudo systemctl daemon-reload

Start the GlassFish service:

sudo systemctl start glassfish

Enable GlassFish to start on boot:

sudo systemctl enable glassfish

Check the status of the GlassFish service:

sudo systemctl status glassfish

The output should indicate that the service is active and running:

**Output**
● glassfish.service - GlassFish Server v6.2.5
     Loaded: loaded (/usr/lib/systemd/system/glassfish.service; enabled; vendor>
     Active: **active** (**running**) since Mon 2022-09-26 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
...

3. Configure GlassFish on AlmaLinux 9

Assuming you have enabled firewalld, allow GlassFish ports on the firewall:

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

Reload the firewall to apply the new rules:

sudo firewall-cmd --reload

Change GlassFish Default Admin Password

Change the default admin password for security reasons:

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

Follow the prompts to set the new password.

Enter admin user name [default: admin]>admin
Enter the admin password>
Enter new admin password>
Enter new admin password again>
Command change-admin-password executed successfully.

Enable Secure Login For GlassFish Admin Console

Enable secure login for the GlassFish admin console:

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

Enter your username and password when prompted.

**Output**
Command enable-secure-admin executed successfully.

Restart GlassFish to apply the changes:

sudo systemctl restart glassfish

4. Access GlassFish Admin Console

Access the GlassFish admin console by navigating to the following URL in your web browser:

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

Enter your GlassFish admin username and password to log in.

You should now see the GlassFish Admin console.

Conclusion

You have successfully learned How To Install GlassFish on AlmaLinux 9. GlassFish provides a robust platform for deploying Java EE applications.

Alternative Solutions for Installing GlassFish on AlmaLinux 9

While the above method details a standard installation process, here are two alternative approaches you can consider:

1. Using Docker:

Docker provides a containerized environment for running applications, ensuring consistency across different environments. Using Docker to deploy GlassFish simplifies the setup process and isolates the application server from the host system.

  • Explanation: Docker images are pre-configured environments containing the necessary software and dependencies. You can use a pre-built GlassFish Docker image or create your own Dockerfile to customize the installation. This method eliminates the need for manual installation steps and ensures reproducibility.

  • Code Example (Docker):

    First, install Docker on AlmaLinux 9:

    sudo dnf install docker-ce -y
    sudo systemctl start docker
    sudo systemctl enable docker

    Then, pull the official GlassFish Docker image from Docker Hub:

    docker pull eclipse/glassfish:latest

    Run the GlassFish container:

    docker run -d -p 8080:8080 -p 4848:4848 eclipse/glassfish:latest

    This command starts a GlassFish container in detached mode, mapping the host’s port 8080 to the container’s port 8080 (for web applications) and the host’s port 4848 to the container’s port 4848 (for the admin console). You can then access the GlassFish admin console via http://your-server-ip-address:4848. This method makes it easier to How To Install GlassFish on AlmaLinux 9.

2. Using SDKMAN!:

SDKMAN! (Software Development Kit Manager) is a tool for managing multiple versions of software development kits on Unix-like systems. It can be used to install and manage GlassFish, providing a convenient way to switch between different GlassFish versions.

  • Explanation: SDKMAN! simplifies the installation process by automating the download, extraction, and configuration of GlassFish. It also allows you to easily switch between different versions of GlassFish, which can be useful for testing and development purposes.

  • Code Example (SDKMAN!):

    First, install SDKMAN! on AlmaLinux 9:

    curl -s "https://get.sdkman.io" | bash
    source "$HOME/.sdkman/bin/sdkman-init.sh"

    Then, install GlassFish using SDKMAN!:

    sdk install glassfish

    This command installs the latest version of GlassFish. To specify a particular version, you can use:

    sdk install glassfish <version>

    For example:

    sdk install glassfish 6.2.5

    After the installation is complete, start GlassFish:

    asadmin start-domain

    You can access the GlassFish admin console via http://localhost:4848. This is another way to How To Install GlassFish on AlmaLinux 9.

These alternative solutions offer different approaches to installing and managing GlassFish on AlmaLinux 9, providing flexibility and ease of use depending on your specific requirements. Whether you choose to use Docker or SDKMAN!, you can streamline the installation process and ensure consistency across different environments.