This
article shows how to configure a cluster made up of two JBoss AS 7.1.1.Final
instances and how to config Apache Web Server to
implement the so-called load balanced mechanism.
The version
of Apache used to implement this example is Apache 2.2
Firstly, I
would like to show how to create two clustered nodes with JBoss standalone
version.
Finally, I
will outline the steps needed to configure the Apache server to behave just
like a load balancer element.
JBoss Cluster configuration
It is extremely
easy to create a JBoss cluster based on the Standalone modality.
Imagine
that the Jboss server is installed in the following filesystem location.
\JBOSS_HOME\
For dealing
with a simple and non-infrastructure complex example, this
example deploy two clustered nodes in the same machine but listening
different ports.
Thus, we
are going to create two nodes called: node1 and node 2
For
creating each node, the following steps must be followed:
1) Copy the
folder \JBOSS_HOME\standalone to \JBOSS_HOME\ with the name, for instance, “standalone_node1”
2) Copy the
folder \JBOSS_HOME\standalone again to \JBOSS_HOME\ with the name, form instance, “standalone_node2”
3) In the
\JBOSS_HOME\bin create a “bat” file called, for instance, “cluster_node1.bat”
and include the following sentence that run and deploy the instance of the
node1.
./standalone.bat -c standalone-ha.xml -b 127.0.0.1 -u
230.0.0.4 -Djboss.server.base.dir=../standalone_node1
-Djboss.node.name=node1 -Djboss.socket.binding.port-offset=100
4) In the \JBOSS_HOME\bin create a “bat” file
called, for instance, “cluster_node2.bat” and include the following sentence
that run and deploy the instance of the node1.
./standalone.bat -c standalone-ha.xml -b 127.0.0.1 -u
230.0.0.4 -Djboss.server.base.dir=../standalone_node2
-Djboss.node.name=node2 -Djboss.socket.binding.port-offset=200
5) Finally, execute in different cmd
console each of the “bat” files in order to lauch and
make available the JBoss cluster.
APACHE LOAD BALANCER CONFIGURATION
For
activate the load balancer feature of the Apache, I assume in this example to
do so by using the mod_proxy module that is
included in this version of Apache Web Server. It is not the best option to
configure a load balancer node, because the best
protocol called ajp is not used. Instead, all the
communication is based on the common http protocol.
In the file
\APACHE_HOME\conf\httpd.conf several modifications
must be done:
1) Activate
the following modules by adding these sentences
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 proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
Be aware
that all this *.so files are included in the distributable 2.2.* version of
Apache
2) Create a
virtual host as follow:
<VirtualHost
localhost:90>
ServerName
localhost:90
DocumentRoot
"d:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
# Enable forward proxy
ProxyRequests On
ProxyVia On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# Enable reverse proxy
ProxyPass /
balancer://mycluster/ stickysession=JSESSIONID
ProxyPassReverse
/ http://localhost:8180/
ProxyPassReverse
/ http://localhost:8280/
<Proxy balancer://mycluster>
BalancerMember
http://localhost:8180/ route=node1
BalancerMember
http://localhost:8280/ route=node2
# Set counting algorithm to more evenly
distribute work:
ProxySet lbmethod=byrequests
</Proxy>
# Enable load balancer management
<Location /balancer-manager>
SetHandler
balancer-manager
</Location>
<Directory "htdocs">
AllowOverride
AuthConfig
</Directory>
</VirtualHost>
As you can
see, this load balancer configuration points to the two JBoss instances
deployed by way of the http ports (8180 for node 1 and 8280 for node2).
The Jboss node1
listen the request in the port 8180 because when the instance is launched , the port offset is indicated properly in the
command showed previously (8080 + 100 offset=8180). The same
for the node 2 (8080 + 200=8280).
./standalone.bat -c standalone-ha.xml -b 127.0.0.1 -u
230.0.0.4 -Djboss.server.base.dir=../standalone_node1
-Djboss.node.name=node1 -Djboss.socket.binding.port-offset=100
./standalone.bat -c standalone-ha.xml -b 127.0.0.1 -u
230.0.0.4 -Djboss.server.base.dir=../standalone_node2
-Djboss.node.name=node2 -Djboss.socket.binding.port-offset=200
With these steps, you have in your own machine a Jboss cluster comprised of two nodes and in front of them
an Apache Web service balancing the petitions.
This solves the problem in a way that's easier to implement than with mod_cluster modules
ReplyDelete