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

Building a Mission-Critical Open Source Java Platform - The Web Layer

DZone 's Guide to

Building a Mission-Critical Open Source Java Platform - The Web Layer

Currently the Java platform is one of the most consolidated in the world, much of this is due to platform's ability to support other languages such as Kotlin...

· Java Zone ·
Free Resource

Currently the Java platform is one of the most consolidated in the world, much of this is due to platform's ability to support other languages such as Kotlin, Groovy and Scala, etc. Thousands of web and mobile applications are developed using the platform as a base. The Java platform has changed a lot in recent years and probably will keep evolving.

In parallel with these changes, we see the evolution application servers, that increasingly offer highly complex features such as load balancing components, smart asynchronous messaging, transaction control and many other technologies facilitating application development and standardization. They also provide a stable and scalable infrastructure for mission critical applications. One of the biggest challenges for application servers is to couple highly complex services, making them stable and flexible.

If you want a high availability, scalable environment with no vendor lock-in, WildFly is an open source community option. 

Wildfly

WildFly is an open source application server that is 100% compliant with the Java EE EE 8 specification. In previous versions of Java EE even using only a few technologies for application development, we were required to deal with all the features deployed on the server. . To solve this problem from Java EE 6, the concept of profile was inserted, which aims to create configurations with specific responsibilities, such as the Web Profile that has technologies for web development.

In this architecture we will use Wildfly with the "full-ha" profile to meet our Clustering and Balancing needs.

Domain Mode x Standalone Mode

Wildfly has two types of architecture known as "Standalone Mode" and "Domain Mode". In standalone mode we can work with a single instance very similar to older (JBoss) versions such as JBoss AS 5 and JBoss AS 6.

The major problem with using Standalone Mode is decentralized administration which can cause a lot of headache when replicating the settings on each server.

To solve this problem we have Domain Mode in which all configurations are centralized in a component known as master and the servers are distributed in the subordinates using the configurations obtained from the connection between master and subordinate.

When we start Wildfly in Domain Mode in the default configuration we have at least four processes. One Host Controller, one Process Controller and two Servers.

  • Domain Controller: is the one who controls domain management. Here are the settings that are shared between instances that are in this domain

  • Process Controller: is of great importance because he is responsible for creating the instances and also the Host Controller that we will talk about next. Process Controller should not be confused with an instance, it is simply a process in the JVM

  • Host Controller: As a Domain Controller, Host Controller also coordinates domain instances. He is responsible for doing something similar to Farm Deployment, ie he distributes the deployment file to all instances of the domain

  • Servers: These are the instances themselves, where are the deployed applications. An important point is that each server is a Java process

Among the benefits of using Domain Mode we can cite include:

  • Centralized management;
  • Centralized configuration;
  • Deploy centralized;
  • Centralized maintenance;
  • High availability management

You can find more information in the administration guide.

Architecture

We will use two servers with keepalived + VIP to achieve high availability with Apache Web Servers. In addition we will use a Domain to act as master and another as Backup and to support our applications, two host controllers with two servers each, totaling four Wildfly instances.

You can see our architecture in the following image:

All this lab is running on the very reliable oVirt virtualization platform. You can learn more about oVirt here: ovirt.org

Let's get started by installing and configuring keepalived and Apache Web Server high availability, and of course getting the Mod_cluster setup ready. These settings will be performed on the following servers:

  • apache-httpd-01.mmagnani.lab - 10.0.0.191
  • apache-httpd-02.mmagnani.lab - 10.0.0.192
  • VIP - 10.0.0.190

To make it easier to understand where I am executing each command, I will use the prefix of the servers on each line.

These steps must be performed on both Apache Web Servers:

Apache Web Server - apache-httpd-01.mmagnani.lab

[root@apache-httpd-01 ~]# cat /etc/redhat-release 
CentOS Linux release 8.2.2004 (Core)
[root@apache-httpd-01 ~]# dnf update -y
[root@apache-httpd-01 ~]# dnf install httpd -y
[root@apache-httpd-01 ~]# echo "Web Server 01" > /var/www/html/index.html
[root@apache-httpd-01 ~]# systemctl enable httpd
[root@apache-httpd-01 ~]# systemctl stop firewalld
[root@apache-httpd-01 ~]# systemctl disable firewalld
[root@apache-httpd-01 ~]# setenforce 0
[root@apache-httpd-01 ~]# sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
[root@apache-httpd-01 ~]# dnf install keepalived -y
[root@apache-httpd-01 ~]# systemctl enable keepalived
[root@apache-httpd-01 ~]# rm -Rf /etc/keepalived/keepalived.conf
[root@apache-httpd-01 ~]# vi /etc/keepalived/keepalived.conf
### Active Server
vrrp_script chk_httpd {

  script "pidof httpd"
  interval 2
}
vrrp_instance VI_1 {

  interface ens3
  state MASTER
  advert_int 2
  virtual_router_id 51
  priority 100
  authentication {

    auth_type PASS
    auth_pass SimplePassword
  }
  unicast_src_ip addr:10.0.0.191
  unicast_peer {

    10.0.0.192
  }
  track_script {

    chk_httpd
  }
  virtual_ipaddress {

    10.0.0.190
  }
}
[root@apache-httpd-01 ~]# systemctl restart httpd 
[root@apache-httpd-01 ~]# systemctl restart keepalived 

Apache Web Server - apache-httpd-02.mmagnani.lab

[root@apache-httpd-02 ~]# cat /etc/redhat-release 
CentOS Linux release 8.2.2004 (Core)
[root@apache-httpd-02 ~]# dnf update -y
[root@apache-httpd-02 ~]# dnf install httpd -y
[root@apache-httpd-01 ~]# echo "Web Server 02" > /var/www/html/index.html
[root@apache-httpd-02 ~]# systemctl enable httpd
[root@apache-httpd-02 ~]# systemctl stop firewalld
[root@apache-httpd-02 ~]# systemctl disable firewalld
[root@apache-httpd-02 ~]# setenforce 0
[root@apache-httpd-02 ~]# sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
[root@apache-httpd-02 ~]# dnf install keepalived -y
[root@apache-httpd-02 ~]# systemctl enable keepalived
[root@apache-httpd-02 ~]# rm -Rf /etc/keepalived/keepalived.conf

Edit the file and leave it as below (replace as per your settings).

[root@apache-httpd-02 ~]# vi /etc/keepalived/keepalived.conf
### Passive Server
vrrp_script chk_httpd {

  script "pidof httpd"
  interval 2
}
vrrp_instance VI_1 {

  interface ens3
  state BACKUP
  advert_int 2
  virtual_router_id 51
  priority 50
  authentication {

    auth_type PASS
    auth_pass SimplePassword
  }
  unicast_src_ip 10.0.0.192
  unicast_peer {

    10.0.0.191
  }
  track_script {

    chk_httpd
  }
  virtual_ipaddress {

    10.0.0.190
  }
}
[root@apache-httpd-02 ~]# systemctl restart httpd 
[root@apache-httpd-02 ~]# systemctl restart keepalived 

Now open the browser and enter the VIP IP which in this case is 10.0.0.190. Note that the request was directed to Apache Web Server 01.

For a quick test, turn off Apache Web Server 01 and see that our backup server is responding:

[root@apache-httpd-01 ~]# shutdown now

Next we'll start Mod_cluster configuration and plug it in WildFly.

Compiling and Configuring Mod_cluster

The best way to get updated binaries for CentoS 8 is by compiling. I know this can cause some stress but follow the steps below that everything will be very simple.

[root@apache-httpd-01 ~]# dnf install git make cmake gcc gcc-c++ apr-util apr-devel apr-util-devel httpd-devel -y
[root@apache-httpd-01 ~]# cd /tmp
[root@apache-httpd-01 ~]# git clone https://github.com/modcluster/mod_cluster.git
[root@apache-httpd-01 ~]# cd mod_cluster
[root@apache-httpd-01 ~]# git checkout 1.3.x
[root@apache-httpd-01 ~]# cd native
[root@apache-httpd-01 ~]# mkdir build
[root@apache-httpd-01 ~]# cd build
[root@apache-httpd-01 build]# cmake ../ -G "Unix Makefiles"
[root@apache-httpd-01 build]# make

Copy the newly built modules to the Apache Web Server module directory:

[root@apache-httpd-01 ~]# pwd
/tmp/mod_proxy_cluster/native/build
[root@apache-httpd-01 ~]# cp modules/mod_proxy_cluster.so /etc/httpd/modules/
[root@apache-httpd-01 ~]# cp modules/mod_cluster_slotmem.so /etc/httpd/modules/
[root@apache-httpd-01 ~]# cp modules/mod_manager.so /etc/httpd/modules/
[root@apache-httpd-01 ~]# cp modules/mod_advertise.so /etc/httpd/modules/

These same files must be copied to the Apache Web Server 02 module directory.

[root@apache-httpd-01 ~]# scp modules/mod_cluster_slotmem.so root@10.0.0.192:/etc/httpd/modules/
[root@apache-httpd-01 ~]# scp modules/mod_proxy_cluster.so root@10.0.0.192:/etc/httpd/modules/
[root@apache-httpd-01 ~]# scp modules/mod_manager.so root@10.0.0.192:/etc/httpd/modules/
[root@apache-httpd-01 ~]# scp modules/mod_advertise.so root@10.0.0.192:/etc/httpd/modules/

The mod_proxy_balancer should be disabled when mod_cluster is used. To do this simply on Apache Web Server 01 edit the 00-proxy.conf file and comment the line referring to this module.

[root@apache-httpd-01 ~]# vi /etc/httpd/conf.modules.d/00-proxy.conf
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so

Do the same for Apache Web Server 02:

[root@apache-httpd-02 ~]# vi /etc/httpd/conf.modules.d/00-proxy.conf
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so

Now is the time to create the Mod_Cluster configuration file. On Apache Web Server 01 create the file mod_cluster.conf and add the configuration information:

[root@apache-httpd-01 ~]# vi /etc/httpd/conf.d/mod_cluster.conf
LoadModule proxy_cluster_module modules/mod_proxy_cluster.so
LoadModule cluster_slotmem_module modules/mod_cluster_slotmem.so
LoadModule manager_module modules/mod_manager.so
LoadModule advertise_module modules/mod_advertise.so

MemManagerFile cache/mod_cluster

<IfModule manager_module>

  Listen 9090
  ManagerBalancerName mycluster
  Maxcontext 200
  Maxnode 200
  Maxhost 200
  ProxyTimeout 600
  CreateBalancers 1

  <VirtualHost *:9090>

      <Directory />
          Require all granted
      </Directory>

      <Location />
        Require all granted
      </Location>

    KeepAliveTimeout 300
    MaxKeepAliveRequests 0
    EnableMCPMReceive on
    AllowDisplay On

    <Location /mod_cluster_manager>
       SetHandler mod_cluster-manager
       Require all granted
    </Location>

  </VirtualHost>
</IfModule>

Now copy the file to Apache Web Server 02.

[root@apache-httpd-01 ~]# scp /etc/httpd/conf.d/mod_cluster.conf root@10.0.0.192:/etc/httpd/conf.d/

reboot both servers to make sure everything is going up correctly.

[root@apache-httpd-01 ~]# reboot
[root@apache-httpd-02 ~]# reboot

Access the VIP IP again on the Mod Cluster port and context: http://10.0.0.190:9090/mod_cluster_manager. Note that Mod Cluster settings have been loaded successfully.


The first part of the setup is done. Of course it's not cool to disable selinux / firewalld, but it's just to make our demo life easier. In a production environment, security should be taken seriously. Next up in this series, we'll be installing WildFly.

Topics:
application server, centos, developers, ha, 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 }}