high-availability apps

2 min read

DevOps engineers and IT operators always need to setup load-balancing on WildFly for web applications in their systems.

Benefits of using the Apache web server with WildFly

Advantages

  • Speed: Apache web server is faster at serving static context.
  • Security: Apache web server can become a smart proxy server. WildFly can be configured to accept connections from a single IP (the server hosting Apache).
  • Load balancing and clustering: Using Apache as front-end, DevOps engineer can distribute traffic to multiple WildFly server instances. For example, if one of the servers fails, the communication transparently continues to another node in the cluster.

Using the mod_jk library

The mod_jk library is a common solution to front WildFly with the Apache web server.

image

Installing Apache

sudo apt-get update
sudo apt-get install -y apache2

Installing mod_jk

sudo apt-get install libapache2-mod-jk

Confirm that the module has been enabled

sudo apache2ctl -M

Modify the virtual host within for the default configuration file: default

Directory: /etc/apache2/sites-enabled

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    JkMount /* loadbalancer
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

     ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Forward all URLs, unmount one or two URLs so that static data can be served from Apache web server.

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        JkMount /* loadbalancer
        JkUmount /images/* loadbalancer

        <Directory />
                Options FollowSymLinks
                AllowOverride None
         </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

workers.properties

Directory: /etc/libapache2-mod-jk

# Define worker list
worker.list=loadbalancer,jkstatus
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=192.168.0.1
worker.worker1.port=8009  

# Set properties for worker2 (ajp13)
worker.worker2.type=ajp13
worker.worker1worker12.host=192.168.0.2
worker.worker1worker12.port=8009
worker.worker1.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=worker1,worker2

Restart Apache web server

sudo /etc/init.d/apache2 restart

Default configuration in the ha profiles: defines the AJP connector

standalone.xml

<subsystem xmlns="urn:jboss:domain:undertow:1.1">
    <buffer-cache name="default"/>
    <server name="default-server">
        <ajp-listener name="ajp" socket-binding="ajp"/>
        <http-listener name="default" socket-binding="http"/>
        ...
    </server>
</subsystem>

socket-binding-group

<socket-binding-group name="standard-sockets" default-interface="public" port-offset="0">
    <socket-binding name="management-http" interface="management" port="9990"/>
    <socket-binding name="management-https" interface="management" port="9993"/>
    <socket-binding name="ajp" port="8009"/>
    ...
</socket-binding-group>

Configuring mod_proxy

Install and enable mod_proxy

sudo apt-get install libapache2-mod-proxy-html
sudo a2enmod proxy-http

Forward an application with context path of /app*

ProxyPass         /app  http://localhost:8080/app
ProxyPassReverse  /app  http://localhost:8080/app
Orestis Pantazos

Orestis Pantazos

DevOps Engineer