How to Install WildFly (JBoss) on CentOS 7

Published on

7 min read

Install WildFly (JBoss) on CentOS 7

WildFly , formerly known as JBoss is a cross-platform open-source application runtime written in Java that helps you build amazing applications. WildFly is flexible, lightweight, and it is based on pluggable subsystems that can be added or removed as needed.

This tutorial explains how to install WildFly application server on CentOS 7.

Prerequisites

You’ll need to be logged in as a user with sudo access to be able to install packages on your CentOS system.

Step 1: Install Java OpenJDK

WildFly 9 requires Java SE 8 or later. In this tutorial we will install OpenJDK , the open-source implementation of the Java Platform which is the default Java development and runtime in CentOS 7.

Install the OpenJDK package by running:

sudo yum install java-1.8.0-openjdk-devel

Step 2: Create a User

Running WildFly as the root user is a security risk and not considered best practice.

To create a new system user and group named wildfly with home directory /opt/wildfly run:

sudo groupadd -r wildflysudo useradd -r -g wildfly -d /opt/wildfly -s /sbin/nologin wildfly

Step 3: Install WildFly

At the time of writing, the latest version of WildFly is 16.0.0. Before continuing with the next step you should check the download page for a new version. If there is a new version replace the WILDFLY_VERSION variable in the command below.

Download the WildFly archive in the /tmp directory using the following wget command:

WILDFLY_VERSION=16.0.0.Finalwget https://download.jboss.org/wildfly/$WILDFLY_VERSION/wildfly-$WILDFLY_VERSION.tar.gz -P /tmp

When the download is completed, unpack the tar.gz file and move it to the /opt directory:

sudo tar xf /tmp/wildfly-$WILDFLY_VERSION.tar.gz -C /opt/

Next, create a symbolic link wildfly that will point to the WildFly installation directory:

sudo ln -s /opt/wildfly-$WILDFLY_VERSION /opt/wildfly

WildFly will run under the wildfly user which needs to have access to the WildFly installation directory.

Change the directory ownership to user and group wildfly with the following chown command :

sudo chown -RH wildfly: /opt/wildfly

Step 4: Configure Systemd

The WildFly package includes files necessary to run WildFly as a service.

Start by creating a directory which will hold the WildFly configuration file:

sudo mkdir -p /etc/wildfly

Copy the configuration file to the /etc/wildfly directory:

sudo cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.conf /etc/wildfly/

This file allows you to specify the WildFly mode and bind address. By default, WildFly will run in a standalone mode and will listen on all interfaces. You can edit the file according to your needs.

/etc/wildfly/wildfly.conf
# The configuration you want to run
WILDFLY_CONFIG=standalone.xml

# The mode you want to run
WILDFLY_MODE=standalone

# The address to bind to
WILDFLY_BIND=0.0.0.0

Next copy the WildFly launch.sh script to the /opt/wildfly/bin/ directory:

sudo cp /opt/wildfly/docs/contrib/scripts/systemd/launch.sh /opt/wildfly/bin/

The scripts inside bin directory must have executable flag :

sudo sh -c 'chmod +x /opt/wildfly/bin/*.sh'

Copy the systemd unit file named to the /etc/systemd/system/ directory:

sudo cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.service /etc/systemd/system/

Notify systemd that we created a new unit file:

sudo systemctl daemon-reload

Start the WildFly service an enable it to be automatically started at boot time by running:

sudo systemctl start wildflysudo systemctl enable wildfly

Verify that the service is running:

sudo systemctl status wildfly
● wildfly.service - The WildFly Application Server
   Loaded: loaded (/etc/systemd/system/wildfly.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2019-03-01 20:13:39 UTC; 3s ago
 Main PID: 3680 (launch.sh)
   CGroup: /system.slice/wildfly.service

Step 5: Adjust the Firewall

If your server is protected by a firewall and you want to access the WildFly instance from the outside of the local network you also need to open port 8080.

Use the following commands to open the necessary port:

sudo firewall-cmd --zone=public --permanent --add-port=8080/tcpsudo firewall-cmd --reload
When running a WildFly application in a production environment most likely you will have a load balancer or reverse proxy and it’s a best practice to restrict access to port 8080 only to your internal network.

Step 6: Configure WildFly Authentication

Now that WildFly is installed and running the next step is to create a user who will be able to connect using the administration console or remotely using the CLI.

To add a new user use the add-user.sh script that is located the WildFly’s bin directory:

sudo /opt/wildfly/bin/add-user.sh

You’ll be asked what type of user do you wish to add:

What type of user do you wish to add? 
 a) Management User (mgmt-users.properties) 
 b) Application User (application-users.properties)
(a):

Select a and hit Enter:

Next, the script will prompt you to enter the details of the new user:

Enter the details of the new user to add.
Using realm 'ManagementRealm' as discovered from the existing property files.
Username : linuxize
Password recommendations are listed below. To modify these restrictions edit the add-user.properties configuration file.
 - The password should be different from the username
 - The password should not be one of the following restricted values {root, admin, administrator}
 - The password should contain at least 8 characters, 1 alphabetic character(s), 1 digit(s), 1 non-alphanumeric symbol(s)
Password : 
Re-enter Password : 
What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[  ]: 
About to add user 'linuxize' for realm 'ManagementRealm'
Is this correct yes/no? yes
Added user 'linuxize' to file '/opt/wildfly-16.0.0.Final/standalone/configuration/mgmt-users.properties'
Added user 'linuxize' to file '/opt/wildfly-16.0.0.Final/domain/configuration/mgmt-users.properties'
Added user 'linuxize' with groups  to file '/opt/wildfly-16.0.0.Final/standalone/configuration/mgmt-groups.properties'
Added user 'linuxize' with groups  to file '/opt/wildfly-16.0.0.Final/domain/configuration/mgmt-groups.properties'
Is this new user going to be used for one AS process to connect to another AS process? 
e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server EJB calls.
yes/no? yes
To represent the user add the following to the server-identities definition <secret value="UGFuMjNkZWo3NyNA" />

The new user will be added to the properties files used for authentication.

Step 6: Test the WildFly Installation

To access the default WildFly page, open your browser and type: http://<your_domain_or_IP_address>:8080

Assuming the installation is successful, a screen similar to the following will appear:

WildFly

Step 7: Access WildFly Administration Console

Command-Line Interface

To access the WildFly Administration Console from the command line you can use the jboss-cli.sh script.

Navigate to the WildFly’s bin directory and run the script with the --connect option:

cd /opt/wildfly/bin/./jboss-cli.sh --connect

You will be asked to enter your administrative username and password (created in step 6):

Authenticating against security realm: ManagementRealm
Username: linuxize
Password:

Once you login the console prompt will change to [standalone@localhost:9990 /]. Type help to get a list of commands and command syntax.

From here, you can deploy and undeploy your applications, manage users and groups and configure and monitor WildFly server.

Web Interface

If you prefer to manage your server from the GUI, WildFly also provides a web-based console.

By default, the WildFly administration console is available only from localhost at http://localhost:9990/console. Sign in using the user you have created in step 6.

WildFly Administration Console

If you want to access the console from remote locations you’ll need to make small modifications to the wildfly.service, wildfly.conf and launch.sh files.

Open the wildfly.conf and append WILDFLY_CONSOLE_BIND=0.0.0.0 at the end of the file.

/etc/wildfly/wildfly.conf
# The configuration you want to run
WILDFLY_CONFIG=standalone.xml

# The mode you want to run
WILDFLY_MODE=standalone

# The address to bind to
WILDFLY_BIND=0.0.0.0

# The address console to bind to
WILDFLY_CONSOLE_BIND=0.0.0.0

Open the launch.sh and edit the highlighted lines:

/opt/wildfly/bin/launch.sh
#!/bin/bash

if [ "x$WILDFLY_HOME" = "x" ]; then
    WILDFLY_HOME="/opt/wildfly"
fi

if [[ "$1" == "domain" ]]; then
    $WILDFLY_HOME/bin/domain.sh -c $2 -b $3 -bmanagement $4
else
    $WILDFLY_HOME/bin/standalone.sh -c $2 -b $3 -bmanagement $4
fi

Restart the service for changes to take effect:

sudo systemctl restart wildfly

Open the wildfly.service and edit the highlighted lines:

/etc/systemd/system/wildfly.service
[Unit]
Description=The WildFly Application Server
After=syslog.target network.target
Before=httpd.service

[Service]
Environment=LAUNCH_JBOSS_IN_BACKGROUND=1
EnvironmentFile=-/etc/wildfly/wildfly.conf
User=wildfly
LimitNOFILE=102642
PIDFile=/var/run/wildfly/wildfly.pid
ExecStart=/opt/wildfly/bin/launch.sh $WILDFLY_MODE $WILDFLY_CONFIG $WILDFLY_BIND $WILDFLY_CONSOLE_BIND
StandardOutput=null

[Install]
WantedBy=multi-user.target

Create the /var/run/wildfly directory and set correct permissions:

sudo mkdir /var/run/wildfly/sudo chown wildfly: /var/run/wildfly/

Notify systemd that the unit file was changed:

sudo systemctl daemon-reload

Restart the WildFly service by executing:

sudo systemctl restart wildfly

Assuming that port 9990 is not blocked in your firewall, you should be able to access the WildFly administration console at http://<your_domain_or_IP_address>:9990/console.

Conclusion

You have successfully installed WildFly on your CentOS 7 system. You can now visit the official WildFly Documentation and learn more about the WildFly features.

If you hit a problem or have feedback, leave a comment below.