How to loadbalance a Glassfish cluster using the Apache Glassfish plugin


As an extension to the earlier post on how to setup a clusterred Apache config using mod_proxy.
Here is another option to consider.

First setup a decent Apache configuration :

<VirtualHost 10.0.0.30:80>
ServerName acc.backoffice.yenlo.nl
UseCanonicalName On

ErrorLog     /var/log/httpd/acc_backoffice_yenlo_error.log
CustomLog    /var/log/httpd/acc_backoffice_yenlo_access.log  combined

RewriteEngine on
# Redirect / to /BACKOFFICE
RewriteRule ^/$ /BACKOFFICE/ [R]
RewriteRule ^/backoffice(.*) /BACKOFFICE$1 [R]

# DENY ALL , except what is allowed by Locations
<Location />
Order Allow,Deny
</Location>

# Locations
<Location /BACKOFFICE>
Order Deny,Allow
Allow from all
</Location>
</VirtualHost>

We only disclose the BACKOFFICE application and will enclose all services threw a different vhost.

<VirtualHost 10.0.0.30:80>
ServerName  acc.services.yenlo.nl
UseCanonicalName On

# Timeout setting altered for CIOT Service
Timeout 1800

ErrorLog     /var/log/httpd/acc_services_yenlo_error.log
CustomLog    /var/log/httpd/acc_services_yenlo_access.log  combined

RewriteEngine on

# DENY ALL , except what is allowed by Locations
<Location />
Order Allow,Deny
</Location>

# Locations
<Location /UserManagementService>
Order Deny,Allow
Allow from all
</Location>
<Location /BriefService>
Order Deny,Allow
Allow from all
</Location>
</VirtualHost>

Now we need to setup the Glassfish Loadbalancing Plugin to be loaded to make Apache understand which Endpoints are available. Source for these instructions can be found here

Then make a file called loadbalance.xml and place it in /etc/httpd/conf/

<!DOCTYPE loadbalancer PUBLIC "-//Sun Microsystems Inc.//DTD Sun One Application Server 8.1//EN" "sun-loadbalancer_1_2.dtd">
<loadbalancer>
<cluster name="clacc-backoffice" policy="round-robin">
<instance name="inacc01-backoffice" enabled="true" disable-timeout-in-minutes="60" listeners="http://gfnode01:38080" weight="100"/>
<instance name="inacc02-backoffice" enabled="true" disable-timeout-in-minutes="60" listeners="http://gfnode02:38080" weight="100"/>
<web-module context-root="BriefService" enabled="true" disable-timeout-in-minutes="60" error-url="sun-http-lberror.html" />
<web-module context-root="UserManagementService" enabled="true" disable-timeout-in-minutes="60" error-url="sun-http-lberr.html" />
<web-module context-root="BACKOFFICE" enabled="true" disable-timeout-in-minutes="60" error-url="sun-http-lberror.html" />
<health-checker url="/" interval-in-seconds="10" timeout-in-seconds="30" />
</cluster>
<property name="reload-poll-interval-in-seconds" value="60"/>
<property name="response-timeout-in-seconds" value="240"/>
<property name="https-routing" value="true"/>
<property name="require-monitor-data" value="false"/>
<property name="active-healthcheck-enabled" value="true"/>
<property name="number-healthcheck-retries" value="3"/>
<property name="rewrite-location" value="true"/>
<property name="chunking-disabled" value="false" />
</loadbalancer>

Then load the plugin in your Apache configuration ( httpd.conf )

##BEGIN EE LB Plugin Parameters
LoadModule apachelbplugin_module modules/mod_loadbalancer.so
<IfModule mod_apache2lbplugin.cpp>
config-file "/etc/httpd/conf/loadbalancer.xml"
locale en
</IfModule>

One thought on “How to loadbalance a Glassfish cluster using the Apache Glassfish plugin

Comments are closed.