Tuesday, September 6, 2011

Clustering with JBoss mod_cluster and AS 7

Today I want to introduce you to JBoss mod_cluster. The Apache-based load balancer works similiar to mod_jk and mod_proxy, but is much more flexible. New application server nodes will introduce theirselves automatically to mod_cluster at runtime. There is no configuration like the worker.properties on mod_jk.

Why should I use mod_cluster?

Clustering was never easier, mod_cluster can balance heavy traffic on registered application server nodes. The web interface allows to enable or disable single applications for each node. If all nodes went down e.g. updating your application mod_cluster will provide a clean error code 503 (service temporary unavailable) page instead of just the default page is not available browser view. Another advantage is mod_cluster 1.1.x and AS 7 fits perfect together and work awesome after minimal amount of configuration.

Prepare Jboss AS 7 for clustering

First, open the configuration file standalone.xml of your Jboss AS 7 instance and add modcluster extension and subsystem on the provided sections:
<extension module="org.jboss.as.modcluster"/>
<subsystem xmlns="urn:jboss:domain:modcluster:1.0" />
Keep in mind to set up the http connector port properly. Since mod_cluster handle all requests for us, the port doesn't really matter and should be blocked by firewall anyways. The first application node could be run for example on http port 8085, the next one on 8086 and so on.

Quick Start mod_cluster

The Quick Start Guide provides simple steps to install mod_cluster on Windows and Linux. After some minutes mod_cluster should run on http port 80 and returns It Works page on request to http://localhost/. The upcoming mod_cluster configuration is a bit tricky especially for setting up multiple vhosts.

By default mod_cluster provides the application server cluster in each vhost, means other provided content will disappear as soon as the first application node registered to the mode_cluster manager. If you just want the cluster responding to a specific vhost add this additional parameter to your httpd.conf:
CreateBalancers 1

The manager listener should be pre-configurated by mod_cluster. Maybe you will have to change the ip address here:
<IfModule manager_module>
    ManagerBalancerName mycluster
        KeepAliveTimeout 300
        MaxKeepAliveRequests 0
        AdvertiseFrequency 5
        ServerAdvertise On
        <Location />
            Order deny,allow
            Allow from 127.0.0
Keep in mind to use if all application servers run on the same server as mod_cluster, otherwise use the internal server ip and allow an internal ip address range.

Next step is to configure the vhost for our cluster. The /mod_cluster_manager location should be only allowed from localhost or internal ip address range:
NameVirtualHost *:80

<VirtualHost *:80> 
    ServerAdmin info@domain.de
    ServerName www.domain.com
    ServerAlias www.domain.com

    ProxyPass / balancer://mycluster stickysession=JSESSIONID|jsessionid nofailover=On
    ProxyPassReverse / balancer://mycluster
    ProxyPreserveHost On

    <Location />
        Order deny,allow
        Allow from All

    <Location /mod_cluster_manager>
        SetHandler mod_cluster-manager
        Order deny,allow
        Deny from all
        Allow from 127.0.0

Next we could add additional vhosts. For example add a vhost to provide direct access to file structure (e.g. content repository) for the subdomain static.domain.com:
<VirtualHost *:80>
    ServerAdmin info@domain.com
    ServerName static.domain.com
    ServerAlias static.domain.com

    DocumentRoot /PRODUCTION/repository/
    <Directory /PRODUCTION/repository/>
        Options FollowSymLinks
        AllowOverride None
        Order Deny,Allow
        Allow from all

    ErrorLog "/PRODUCTION/mod_cluster/httpd/logs/error.log"

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog "/PRODUCTION/mod_cluster/httpd/logs/access.log" combined

Now start mod_cluster and application server nodes. You will see the following result:

www.domain.com -> Request via manager to any application node
static.domain.com -> Access to local directory /PRODUCTION/repository/

Jboss AS 7 and double slash redirect problem

The current version of mod_cluster has a bug with mixing ProxyPass and ProxyPassReverse, means double slashes occur on faces redirects. For example redirect to /test resolves in www.mydomain.com//test. Currently the parameter ProxyPreserveHost On could be used as workaround. For more informations about this bug follow MODCLUSTER-250.

Happy clustering :)

Important Links:

No comments:

Post a Comment