{{announcement.body}}
{{announcement.title}}

Building a Mission-Critical Open Source Java Platform - Installing WildFly

DZone 's Guide to

Building a Mission-Critical Open Source Java Platform - Installing WildFly

In this article we'll continue exploring how to build a mission-critical open source Java platform by installing WildFly and configure our platforms topology...

· Java Zone ·
Free Resource

In the previous article in this series introduced our thoughts on setting up a mission-critical open source Java platform using high availability in our Web layer. In this article we'll continue by installing WildFly and configure our platforms topology.


Note: the terminology in this article, where possible, has been adjusted from the traditional master / slave descriptions to master / subordinate. Some of the images displayed have not yet been updated and show the older terminology. 


Installing

Let’s start building the application layer of our environment.These settings will be performed on the following servers:

  • server-domain.mmagnani.lab - 10.0.0.193
  • server-subordinate-0.mmagnani.lab -10.0.0.194
  • server-subordinate-1.mmagnani.lab - 10.0.0.195
[root@server-domain ~]# cat /etc/redhat-release 
CentOS Linux release 8.2.2004 (Core)
[root@server-domain ~]# systemctl stop firewalld
[root@server-domain ~]# systemctl disable firewalld
[root@server-domain ~]# setenforce 0
[root@server-domain ~]# sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
[root@server-domain ~]# dnf install java-11-openjdk-devel.x86_64 vim wget unzip telnet -y
[root@server-domain ~]# mkdir -p /usr/local/wildfly
[root@server-domain ~]# wget https://download.jboss.org/wildfly/20.0.0.Final/wildfly-20.0.0.Final.zip -P /usr/local/wildfly
[root@server-domain ~]# cd /usr/local/wildfly
[root@server-domain ~]# unzip wildfly-20.0.0.Final.zip
[root@server-domain ~]# useradd -p `openssl passwd -1 wildfly` wildfly
[root@server-domain ~]# usermod -aG wildfly wildfly
[root@server-domain ~]# chown -R wildfly:wildfly /usr/local/wildfly/wildfly-20.0.0.Final
[root@server-domain ~]# vi /etc/systemd/system/wildfly.service

Description=WildFly 20.0.0
After=syslog.target network.target

[Service]
Type=simple
ExecStart=/usr/local/wildfly/wildfly-20.0.0.Final/bin/domain.sh

[Install]
WantedBy=multi-user.target

[root@server-domain ~]# systemctl enable wildfly
[root@server-domain ~]# reboot

Check that the WildFly process has gone up correctly:

[root@server-domain ~]# jps -m
1571 jboss-modules.jar -mp /usr/local/wildfly/wildfly-20.0.0.Final/modules 
##supressed

Now let’s set up “Subordinate 0”:

[root@server-subordinate-0 ~]# cat /etc/redhat-release 
CentOS Linux release 8.2.2004 (Core)
[root@server-subordinate-0 ~]# systemctl stop firewalld
[root@server-subordinate-0 ~]# systemctl disable firewalld
[root@server-subordinate-0 ~]# setenforce 0
[root@server-subordinate-0 ~]# sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
[root@server-subordinate-0 ~]# dnf install java-11-openjdk-devel.x86_64 vim wget unzip telnet -y
[root@server-subordinate-0 ~]# mkdir -p /usr/local/wildfly
[root@server-subordinate-0 ~]# wget https://download.jboss.org/wildfly/20.0.0.Final/wildfly-20.0.0.Final.zip -P /usr/local/wildfly
[root@server-subordinate-0 ~]# cd /usr/local/wildfly
[root@server-subordinate-0 ~]# unzip wildfly-20.0.0.Final.zip
[root@server-subordinate-0 ~]# useradd -p `openssl passwd -1 wildfly` wildfly
[root@server-subordinate-0 ~]# usermod -aG wildfly wildfly
[root@server-subordinate-0 ~]# chown -R wildfly:wildfly /usr/local/wildfly/wildfly-20.0.0.Final
[root@server-subordinate-0 ~]# vi /etc/systemd/system/wildfly.service

Description=WildFly 20.0.0
After=syslog.target network.target

[Service]
Type=simple
ExecStart=/usr/local/wildfly/wildfly-20.0.0.Final/bin/domain.sh

[Install]
WantedBy=multi-user.target

[root@server-subordinate-0 ~]# systemctl enable wildfly
[root@server-subordinate-0 ~]# reboot

Check that the WildFly process has gone up correctly:

[root@server-subordinate-0 ~]# jps -m
1968 jboss-modules.jar -mp /usr/local/wildfly/wildfly-20.0.0.Final/modules
##supressed

And now let’s set up “Subordinate 1”:

[root@server-subordinate-1 ~]# cat /etc/redhat-release 
CentOS Linux release 8.2.2004 (Core)
[root@server-subordinate-1 ~]# systemctl stop firewalld
[root@server-subordinate-1 ~]# systemctl disable firewalld
[root@server-subordinate-1 ~]# setenforce 0
[root@server-subordinate-1 ~]# sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
[root@server-subordinate-1 ~]# dnf install java-11-openjdk-devel.x86_64 vim wget unzip telnet -y
[root@server-subordinate-1 ~]# mkdir -p /usr/local/wildfly
[root@server-subordinate-1 ~]# wget https://download.jboss.org/wildfly/20.0.0.Final/wildfly-20.0.0.Final.zip -P /usr/local/wildfly
[root@server-subordinate-1 ~]# cd /usr/local/wildfly
[root@server-subordinate-1 ~]# unzip wildfly-20.0.0.Final.zip
[root@server-subordinate-1 ~]# useradd -p `openssl passwd -1 wildfly` wildfly
[root@server-subordinate-1 ~]# usermod -aG wildfly wildfly
[root@server-subordinate-1 ~]# chown -R wildfly:wildfly /usr/local/wildfly/wildfly-20.0.0.Final
[root@server-domain wildfly]# vi /etc/systemd/system/wildfly.service

Description=WildFly 20.0.0
After=syslog.target network.target

[Service]
Type=simple
ExecStart=/usr/local/wildfly/wildfly-20.0.0.Final/bin/domain.sh

[Install]
WantedBy=multi-user.target

[root@server-subordinate-1 ~]# systemctl enable wildfly
[root@server-subordinate-1 ~]# reboot

Check that the WildFly process has gone up correctly:


[root@server-subordinate-1 ~]# jps -m
1948 jboss-modules.jar -mp /usr/local/wildfly/wildfly-20.0.0.Final/modules
##supressed

It is! Finally we have Wildfly running in Domain Mode on all three servers.

Configuring the Master/Subordinate Architecture

This part of the setup will need a little more hard work because requires attention to detail but don’t worry, let’s go step by step.

The first step is to set the variables correctly so WildFly can understand where our settings are and what we want to do with them.

Edit the domain.conf file and add the binding settings for the JAVA_OPTS variable:

##around line 50
[root@server-domain ~]# vim /usr/local/wildfly/wildfly-20.0.0.Final/bin/domain.conf

if [ "x$JAVA_OPTS" = "x" ]; then
   JAVA_OPTS="-Xms64m -Xmx512m -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true"
   JAVA_OPTS="$JAVA_OPTS -Djboss.modules.system.pkgs=$JBOSS_MODULES_SYSTEM_PKGS -Djava.awt.headless=true"
   
   #Add this line
   JAVA_OPTS="$JAVA_OPTS -Djboss.bind.address.management=10.0.0.193 -Djboss.bind.address=10.0.0.193"
else
##supressed

Restart wildfly service and open the server URL and note that WildFly is running and accessible: http://10.0.0.193:8080

[root@server-domain ~]# systemctl restart wildfly


The next step is to create/update a management user and a directory for the domain to starting the configuration of WildFly server topology.

[root@server-domain ~]# cd /usr/local/wildfly/wildfly-20.0.0.Final/bin
[root@server-domain ~]# ./add-user.sh 

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

Enter the details of the new user to add.
Using realm 'ManagementRealm' as discovered from the existing property files.
Username : admin
User 'admin' already exists and is disabled, would you like to... 
 a) Update the existing user password and roles 
 b) Enable the existing user 
 c) Type a new username
(a): a
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 : Redhat*#2
Re-enter Password : Redhat*#2
What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[  ]: 
Updated user 'admin' to file '/usr/local/wildfly/wildfly-20.0.0.Final/standalone/configuration/mgmt-users.properties'
Updated user 'admin' to file '/usr/local/wildfly/wildfly-20.0.0.Final/domain/configuration/mgmt-users.properties'
Updated user 'admin' with groups  to file '/usr/local/wildfly/wildfly-20.0.0.Final/standalone/configuration/mgmt-groups.properties'
Updated user 'admin' with groups  to file '/usr/local/wildfly/wildfly-20.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="UmVkaGF0KiMy" />

Take note of the , this will be used to configure the Subordinate connection.

Now create a new directory called “master” based on the “domain” directory.

[root@server-domain ~]# pwd
/usr/local/wildfly/wildfly-20.0.0.Final
[root@server-domain ~]# cp -Rap domain master

Edit again the domain.conf file and add the configuration dir settings for the JAVA_OPTS variable:

##around line 50
[root@server-domain ~]# vim /usr/local/wildfly/wildfly-20.0.0.Final/bin/domain.conf

if [ "x$JAVA_OPTS" = "x" ]; then
   JAVA_OPTS="-Xms64m -Xmx512m -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true"
   JAVA_OPTS="$JAVA_OPTS -Djboss.modules.system.pkgs=$JBOSS_MODULES_SYSTEM_PKGS -Djava.awt.headless=true"
   
   #Edit this line
   JAVA_OPTS="$JAVA_OPTS -Djboss.bind.address.management=10.0.0.193 -Djboss.bind.address=10.0.0.193 -Djboss.domain.base.dir=/usr/local/wildfly/wildfly-20.0.0.Final/master"
else
##supressed

Restart wildfly service and access the management URL by logging in with user “admin” and previously updated password: http://10.0.0.193:9990

[root@server-domain ~]# systemctl restart wildfly

In the management console you will notice that we are still using the standard topology but we will work on it in the next steps.

Edit the domain.xml file and update the existing groups. The groups must be called “marketing” and “accounting” that will use the “full-ha” profile and “full-ha-sockets”.

[root@server-domain ~]# pwd
/usr/local/wildfly/wildfly-20.0.0.Final
[root@server-domain ~]# vim master/configuration/domain.xml 
##around line 1895
    <server-groups>
        <server-group name="marketing" profile="full-ha">
            <jvm name="default">
                <heap size="64m" max-size="512m"/>
            </jvm>
            <socket-binding-group ref="full-ha-sockets"/>
        </server-group>
        <server-group name="accounting" profile="full-ha">
            <jvm name="default">
                <heap size="64m" max-size="512m"/>
            </jvm>
            <socket-binding-group ref="full-ha-sockets"/>
        </server-group>
    </server-groups>
##suppressed

Save the domain.xml file.

Edit again the domain.conf file and add the configuration file settings for the JAVA_OPTS variable:

##around line 50
[root@server-domain ~]# vi /usr/local/wildfly/wildfly-20.0.0.Final/bin/domain.conf

if [ "x$JAVA_OPTS" = "x" ]; then
   JAVA_OPTS="-Xms64m -Xmx512m -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true"
   JAVA_OPTS="$JAVA_OPTS -Djboss.modules.system.pkgs=$JBOSS_MODULES_SYSTEM_PKGS -Djava.awt.headless=true"
   
   #Edit this line
   JAVA_OPTS="$JAVA_OPTS -Djboss.bind.address.management=10.0.0.193 -Djboss.bind.address=10.0.0.193 -Djboss.domain.base.dir=/usr/local/wildfly/wildfly-20.0.0.Final/master -Djboss.host.default.config=host-master.xml"
else
##suppressed

Restart the wildfly service.

[root@server-domain ~]#  systemctl restart wildfly

Note that now a new topology will be presented:

The next step is to create the configuration of “Subordinate 0” and connect it to “Master”.

[root@server-subordinate-0 ~]# pwd
/usr/local/wildfly/wildfly-20.0.0.Final
[root@server-subordinate-0 ~]# cp -Rap domain subordinate0

Edit the host-slave.xml file. Add subordinate name and update the existing servers. The servers must be called “server-marketing-0” and “server-accounting-0”. Servers must belong to their own group: Marketing and Accounting.

[root@server-subordinate-0 ~]# vim subordinate0/configuration/host-slave.xml 
<?xml version='1.0' encoding='UTF-8'?>
##around line 3
<host xmlns="urn:jboss:domain:13.0" name="subordinate0">
    <extensions>
##suppressed
##around line 89
    <servers>
        <server name="server-marketing-0" group="marketing"/>
        <server name="server-accounting-0" group="accounting">
            <socket-bindings port-offset="100"/>
        </server>
    </servers>
##suppressed

We also have to set the user and “secret” created in the master so we can connect the “Subordinate 0”.

In this same host-slave.xml file add the secret and user:

##around line 13
        <security-realms>
            <security-realm name="ManagementRealm">
                <server-identities>
                    <secret value="UmVkaGF0KiMy" />
##supress
##around line 65
    <domain-controller>
        <remote security-realm="ManagementRealm" username="admin">
            <discovery-options>
                <static-discovery name="primary" protocol="${jboss.domain.master.protocol:remote+http}" host="${jboss.domain.master.address}" port="${jboss.domain.master.port:9990}"/>
##suppressed

Edit again the domain.conf file and add the configuration file settings for the JAVA_OPTS variable:

[root@server-subordinate-0 ~]# vim /usr/local/wildfly/wildfly-20.0.0.Final/bin/domain.conf
##around line 50
if [ "x$JAVA_OPTS" = "x" ]; then
   JAVA_OPTS="-Xms64m -Xmx512m -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true"
   JAVA_OPTS="$JAVA_OPTS -Djboss.modules.system.pkgs=$JBOSS_MODULES_SYSTEM_PKGS -Djava.awt.headless=true"

   ##Add this line
   JAVA_OPTS="$JAVA_OPTS -Djboss.domain.base.dir=/usr/local/wildfly/wildfly-20.0.0.Final/subordinate0 -Djboss.host.default.config=host-slave.xml -Djboss.domain.master.address=10.0.0.193 -Djboss.bind.address=10.0.0.194"
else
##suppressed

Restart the wildfly service:

[root@server-subordinate-0 ~]#  systemctl restart wildfly

In the “Host Master” logs you can see the “Host subordinate 0” connection log.

[root@server-domain ~]# tail -f /usr/local/wildfly/wildfly-20.0.0.Final/master/log/host-controller.log
2020-07-06 16:39:04,153 INFO  [org.jboss.as.domain.controller] (Host Controller Service Threads - 24) WFLYHC0019: Registered remote slave host "subordinate0", JBoss WildFly Full 20.0.0.Final (WildFly 12.0.1.Final)

Open the management console to see the updated topology: http://10.0.0.193:9990/console

Now perform the same procedure for “Subordinate 1”.

[root@server-subordinate-1 ~]# pwd
/usr/local/wildfly/wildfly-20.0.0.Final
[root@server-subordinate-1 ~]# cp -Rap domain subordinate1

Edit the host-slave.xml file. Add subordinate name and update the existing servers. The servers must be called “server-marketing-1” and “server-accounting-1”. Servers must belong to their own group: Marketing and Accounting.

[root@server-subordinate-1 ~]# vim subordinate1/configuration/host-slave.xml 
<?xml version='1.0' encoding='UTF-8'?>
##around line 3
<host xmlns="urn:jboss:domain:13.0" name="subordinate1">
    <extensions>
##suppressed
##around line 89
    <servers>
        <server name="server-marketing-1" group="marketing"/>
        <server name="server-accounting-1" group="accounting">
            <socket-bindings port-offset="100"/>
        </server>
    </servers>
##suppressed

We also have to set the user and “secret” created in the master so we can connect the “Subordinate 1”.

In this same host-slave.xml file add the secret and user:

##around line 13
        <security-realms>
            <security-realm name="ManagementRealm">
                <server-identities>
                   <secret value="UmVkaGF0KiMy" />
##supress
##around line 65
    <domain-controller>
        <remote security-realm="ManagementRealm" username="admin">
            <discovery-options>
                <static-discovery name="primary" protocol="${jboss.domain.master.protocol:remote+http}" host="${jboss.domain.master.address}" port="${jboss.domain.master.port:9990}"/>
##suppressed

Edit again the domain.conf file and add the configuration file settings for the JAVA_OPTS variable:

[root@server-subordinate-1 ~]# vim /usr/local/wildfly/wildfly-20.0.0.Final/bin/domain.conf
##around line 50
if [ "x$JAVA_OPTS" = "x" ]; then
   JAVA_OPTS="-Xms64m -Xmx512m -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true"
   JAVA_OPTS="$JAVA_OPTS -Djboss.modules.system.pkgs=$JBOSS_MODULES_SYSTEM_PKGS -Djava.awt.headless=true"

   ##Add this line
   JAVA_OPTS="$JAVA_OPTS -Djboss.domain.base.dir=/usr/local/wildfly/wildfly-20.0.0.Final/subordinate1 -Djboss.host.default.config=host-slave.xml -Djboss.domain.master.address=10.0.0.193 -Djboss.bind.address=10.0.0.195"
else
##suppressed

Restart the wildfly service:

[root@server-subordinate-1 ~]#  systemctl restart wildfly

In the “Host Master” logs you can see the “Host Subordinate 1” connection log.

[root@server-domain ~]# tail -f /usr/local/wildfly/wildfly-20.0.0.Final/master/log/host-controller.log
2020-07-06 16:48:27,522 INFO  [org.jboss.as.domain.controller] (Host Controller Service Threads - 24) WFLYHC0019: Registered remote slave host "subordinate1", JBoss WildFly Full 20.0.0.Final (WildFly 12.0.1.Final)

Open the management console again to see the updated topology: http://10.0.0.193:9990/console

Now we have our topology with One Host Master, Two Host Subordinates and Four WildFly Instances. In the next article, we'll be tuning Wildfly before deploying our application.

Topics:
application server, ha, install, java, jboss, open source, redhat, tutorial, wildfly

Published at DZone with permission of Mauricio Magnani . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}