Monday, May 2, 2011

JBoss load-balanced cluster on a thumbdrive

I spent a little bit of time getting a JBoss cluster running on my development machine and then configuring a Apache 2.2.17 server to load balance between the 2 node cluster. Here is how I did it.

I had to enable the following modules on Apache:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule status_module modules/mod_status.so


Then, I had to setup the rules for the balancing Apache proxy at the end of the conf/httpd.conf file:
ProxyReceiveBufferSize 4096
<proxy balancer://ajpcluster>
  BalancerMember ajp://test.local.host:8109
  BalancerMember ajp://test.local.host:8209
</proxy>
<location /jconsole>
  ProxyPass balancer://ajpcluster/jconsole stickysession=JSESSIONID|jsessionid nofailover=On
  ProxyPassReverse balancer://ajpcluster/jconsole
</location>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Redirect / /jconsole
RedirectMatch ^/(?i)admin   /jconsole
RedirectMatch ^/(?i)status   /jconsole


Then, I needed to enable the conf/mod-jk.conf file, update the http.conf to reflect this, and add this VirtualHost:
<virtualHost localhost>
  ServerName localhost
  JkMount /jconsole loadbalancer
  JkMount /jconsole/* loadbalancer
</virtualHost>


Then, I needed a conf/uriworkermap.properties file:
# Simple worker configuration file
# Mount the Servlet context to the ajp13 worker
#    Example
#    Mapping the URI /myapp1 and everything under /myapp1/:
#    /myapp1|/*=myworker-a
/jconsole|/*=loadbalancer
/jkstatus|/*=jkstat


Then, I needed a conf/workers.properties for mod-jk:
# Define list of workers that will be used
# The configuration directives are valid
# for the mod_jk version 1.2.18 and later
worker.list=loadbalancer,jkstat
# Define Node1
worker.ports1.port=8109
worker.ports1.host=127.0.0.1
worker.ports1.type=ajp13
worker.ports1.lbfactor=1
worker.ports1.prepost_timeout=10000
worker.ports1.connect_timeout=10000
worker.ports1.ping_mode=A
worker.ports1.connection_pool_size=10
# Define Node2
worker.ports2.port=8209
worker.ports2.host=127.0.0.1
worker.ports2.type=ajp13
worker.ports2.lbfactor=1
worker.ports2.prepost_timeout=10000
worker.ports2.connect_timeout=10000
worker.ports2.ping_mode=A
worker.ports1.connection_pool_size=10
# Load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=ports1,ports2
# Status worker for managing load balancer
worker.jkstat.type=status


And, that is basically it. You can download my portable , self extracting zip file, of my Tomcat and JBoss cluster running on "localhost". Just unzip and read the readme file enclosed. It works as-is , by navigating to the app called "http://test.local.host" after you have it running.

Download zip archive here.

No comments:

Post a Comment