| JBoss Clustering a Web Application |
|
|
|
| Written by Mark S. | |||||||||||||||||||||||||||||||||||
| Tuesday, 26 August 2008 13:03 | |||||||||||||||||||||||||||||||||||
|
Clustering allows us to run an applications on several parallel servers (a.k.a cluster nodes). The load is distributed across different servers, and even if any of the servers fails, the application is still accessible via other cluster nodes. Clustering is crucial for scalable enterprise applications, as you can improve performance by simply adding more nodes to the cluster.
The JBoss Application Server (AS) comes with clustering support out of the box.
For Web applications, a hardware- or software-based HTTP load-balancer usually sits in front of the application servers within a cluster. These load-balancers can be used to decrypt HTTPS requests quickly, distribute the load between nodes in the cluster, and detect server failures. The usual setup is to have a user session live entirely on one server that is picked by the load-balancer. This is called a "sticky" session. Configuring JBoss to run in a cluster So let's see how to configure 2 instances of JBoss in a cluster. We'll define two nodes nodeA and nodeB
fine the line:
<Engine name="jboss.web" defaultHost="localhost"> and for the machine 192.168.0.1 modify: <Engine name="jboss.web" defaultHost="localhost" jvmRoute="nodeA"> and for the machine 192.168.0.2 <Engine name="jboss.web" defaultHost="localhost" jvmRoute="nodeB">
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
String dummy = (String)request.getSession().getAttribute("dummy");
PrintWriter out = response.getWriter();
out.println("");
out.println("");
System.out.print("Hello from Node "+ InetAddress.getLocalHost().toString());
if (dummy == null) {
out.println("
<?xml version="1.0" encoding="UTF-8"?> <distributable/>
The easiest way to deploy an application into the cluster is to use the farming service. That is to hot-deploy the application archive file (e.g., the EAR, WAR or SAR file) in the all/farm/ directory of any of the cluster member and the application is automatically duplicated across all nodes in the same cluster
for a detailed explanation of all steps necessary to configure Apache-JBoss via modJK we suggest you reading the Wiki http://wiki.jboss.org/wiki/UsingMod_jk1.2WithJBoss. Now we'll focus in particular on the part of the configuration relative to the cluster. The first thing we need to have is redirecting calls to the mod_JK load balancer: this is done in file mod_jk.properties: # Where to find workers.properties # Where to put jk logs JkMount /HelloWorld/* loadbalancer
worker.nodeA.port=8009 worker.nodeB.port=8009 worker.loadbalancer.type=lb # Status worker for managing load balancer As you can see we have the two nodes (nodeA and nodeB) with relative port and IP address. Now launch the two instances of JBoss using the command run -c all. The first instance started will display this information when the second instance kicks in: 16:09:20,562 INFO [AjpProtocol] Starting Coyote AJP/1.3 on ajp-192.168.0.1-8009 Ok. In order to invoke our Servlet simply point to our Apache Web Server domain address http://apache.web.server/HelloWorld/helloWorld You'll see that the balancer load balances calls and, once it has created the session, it will replicate the session to the secondary server. You can do experiments to test your cluster, switching off one instance of the cluster and verifying that the session stays alive on the other server. ConclusionJBoss clustering is designed to be simple to configure and simple to extend. It is one of the final pieces of the puzzle that makes JBoss a viable open source competitor to other enterprise J2EE offerings. In the next article we'll see how to cluster EJB using simple annotations.
JBoss.org Search
Custom Search
Only registered users can write comments!
Powered by !JoomlaComment 3.26
3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved." |
|||||||||||||||||||||||||||||||||||
| Last Updated ( Tuesday, 28 October 2008 09:57 ) | |||||||||||||||||||||||||||||||||||




You can only put archive files, not exploded directories, in the farm directory. This way, the application on a remote node is only deployed when the entire archive file is copied over. Otherwise, the application might be deployed (and failed) when the directory is only partially copied.