Multiple instances of AS on OSX

29 September 2008

java jboss osx

Rysiek asked me to elucidate my clustering on OSX...

By default, it seems that OSX provides exactly 1 localhost address, unlike RHEL. I normally make use of when I'm deploying on Linux, and figured I'd do the same on OSX.

To accomplish this, you need to create some new localhost IPs to play with.

sudo ifconfig lo0 alias up
sudo ifconfig lo0 alias up
sudo ifconfig lo0 alias up

Now, when you run your AS with ./, just pass -b or -b etc, and the entire stack will bind to that IP address.

At this point, I'm allowing each AS instance to share a work directory and such, which is probably not exactly the safest thing to be doing. Normally each cluster node would be a discrete machine with its own JBOSS_HOME.

For the apache config, in /private/etc/apache2/httpd.conf, I uncommented the line to allow vhost file loading:

# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf

Then, in the httpd-vhosts.conf file I fixed it up to include my virtual host for the head-end load-balancing stuff.

The <VirtualHost> is only barely conformant, and even the DocumentRoot is gratuitous, really. It looks like this:

<VirtualHost *:80>
  ServerName app.local.ballast
  DocumentRoot "/Users/bob/public_html"

  RewriteEngine on

  RewriteMap    lb      'prg:/Users/bob/bin/load_balancer local.ballast 1 3'
  RewriteRule   ^/(.*)$ ${lb:$1}           [P,L]

What that is doing is passing each requested path to the load_balancer script I've borrowed from I-don't-know-'where. It returns an augmented URL pointing to one of my localhost-bound nodes.

#!/usr/bin/env perl
## -- load balancing script

$| = 1;

$name   = $ARGV[0];         # the hostname base
$first  = $ARGV[1];         # the first server (not 0 here, because 0 is myself)
$last   = $ARGV[2];         # the last server in the round-robin

$cnt = 0;
while (<STDIN>) {
    $server = sprintf("node%d.%s", $cnt+$first, $name);
    $cnt = (($cnt+1) % ($last+1-$first));
    print "http://$server:8080/$_";

If a path of /foo/bar is handed to it on STDIN, it'll return something in the format of http://node1.local.ballast:8080/foo/bar or http://node2.local.ballast:8080/foo/bar.

Through the magic of /etc/hosts those friendly names point to the localhost bound AS cluster nodes, along with app.local.ballast pointing to good old traditional, where httpd is normally listening. That's my head-end from the httpd-vhosts.conf.       localhost app.local.ballast      node1.local.ballast      node2.local.ballast      node3.local.ballast

Fire up a browser and I surf to http://app.local.ballast/, apache answers, and immediately and invisibly proxies the request to port 8080 of one of my localhost-bound JBoss AS instances.