How to configure failover for JBoss AS 5?

Solution 1:

You need to have an apache or iis fronting the cluster.

Basically you use mod_jk, mod_proxy_ajp or mod_cluster to do manage the failover and stickyness of the sessions.

Now lets say you have 2 jboss servers (192.168.1.2 and 192.168.1.3) and 1 apache 2.2.x and you want to use mod_jk for the sake of simplicity (if you want 2 apaches to do HA at the http layer you need a load balancer of some kind).

The first thing is you download mod_jk 1.2.30 as it offers better capabilities for node failed node detection. and put it into the modules directory of the apache server_root.

then you go to the httpd.conf and add:

LoadModule jk_module modules/mod_jk-1.2.30-httpd-2.2.3.so

next thing you do is create a file called workers.properties with the following content

worker.list=loadbalancer,status
worker.template.port=8009
worker.template.type=ajp13
worker.template.ping_mode=A
worker.template.reply_timeout=90000
worker.template.socket_connect_timeout=10000
worker.template.connection_pool_size=150
worker.template.socket_keepalive=true

worker.node1.reference=worker.template
worker.node1.host=192.168.1.2

worker.node2.reference=worker.template
worker.node2.host=192.168.1.3

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
worker.loadbalancer.sticky_session=True

worker.status.type=status

Then in the httpd.conf file you add the following lines:

JkWorkersFile conf/workers.properties
JkWatchdogInterval 60
JkMount /* loadbalancer
JkLogFile logs/mod_jk.log

then in go to the jboss config for 192.168.1.2

in the file JBOSS_HOME/server/all/deploy/jbossweb.sar/server.xml

<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node1">

and replace or modify this:

<Connector protocol="AJP/1.3" port="8009" address="${jboss.bind.address}"
     redirectPort="8443" />

with this:

<Connector port="8009" address="${jboss.bind.address}" protocol="AJP/1.3"
emptySessionPath="true" enableLookups="false" redirectPort="8443"
maxThreads="200" connectionTimeout="600000" />

then in go to the jboss config for 192.168.1.3

in the file JBOSS_HOME/server/all/deploy/jbossweb.sar/server.xml

<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node2">

and replace or modify this:

<Connector protocol="AJP/1.3" port="8009" address="${jboss.bind.address}"
     redirectPort="8443" />

with this:

<Connector port="8009" address="${jboss.bind.address}" protocol="AJP/1.3"
emptySessionPath="true" enableLookups="false" redirectPort="8443"
maxThreads="200" connectionTimeout="600000" />

Explanation: The change in the connector tag limits the threads in the web container to 200 (i.e. it is the max amount of simultaneous requests is able to manage) the connectionTimeout makes sure that if the client closes the connection (this is "closes the browser") the thread expires after 600 seconds of no use.

You can find sizing for these parameters in this appspot app created by the jboss team: lbconfig.appspot.com

SECURITY CONSIDERATIONS: Secure or disable the jmx-console and/or the web-console by either deleting the jmx-console.war and management directories from the deploy folder or following the instructions in this document

You can find more info about load balancing, mod_jk, mod_cluster in the jboss wiki

Solution 2:

Jboss does not support http LB. Each node is listening on its own port. http session are replicated/distributed. If your boss insist, you can use the HAJNDI Smart client proxy rather then http. Simply initiate a naming context from your client application to the HAJNDI port (1101), lookup you EJB3 application and call any remote method. When the connected node is down the smart proxy will know to switch.