11/10/08

  1. Introduction
  2. Configuration of JBoss to run in a cluster
  3. Load Balancing (Using Apache Web Server 2.2.9)
  4. Configuration of HTTP session state replication
  5. Start JBoss 4.2.2 GA Instance
  6. References
  1. Introduction: Clustering allows us to run an application on several parallel servers. The load is distributed across different servers, and even if any of the servers fail, the application is still accessible via other cluster nodes. A node can be a computer or, more simply, a server instance. These nodes generally have a common goal. Nodes in a cluster have two common goals: achieving Fault Tolerance and Load Balancing through replication. These concepts are often mixed.

    1. Fault Tolerance: Fault tolerant service always guarantees strictly correct behavior despite a certain number and type of faults.
    2. Load balancing: Load balancing is a means to obtain better performance by dispatching incoming requests to different servers.

  2. Configuration of JBoss to run in a cluster: We’ll configure two instances (nodeA and nodeB) of JBoss in a cluster.

    Node Name IP Address
    nodeA 192.168.0.161
    nodeB 192.168.0.162

    Now for every installation of JBoss go under the folder "JBOSS_HOME\server\all\deploy\jboss-web.deployer" and open the file server.xml. Find the line:
    Now before packing the application add at the very beginning of the web.xml file

    The tag "distributable" has no parameter, it is just some kind of placeholder that tells the Servlet container that the session should be replicated.

    Now we can deploy the web application in JBoss. There are two ways to deploy the application in JBoss. First we can copy an application into each of the cluster nodes “all/deploy” folder and the second way to deploy in JBoss is a more efficient way to deploy application updates rather than manually copying them to each cluster node every time the application changes. If we copy an application into the JBoss “all/farm” folder (Hot deploy), the application archive (e. g the EAR, WAR or SAR file) will deploy locally and then duplicate to all other running cluster nodes. When other nodes join the cluster, they will pull the application to their farm deployment folder and deploy it.

    So now JBoss is ready to accept cluster web applications. Now we need something at first sitting in front of our JBoss Cluster to handle incoming requests and distribute load across cluster nodes.

  3. Load Balancing (Using Apache Web Server 2.2.9): Load balancing is a different story. It is not handled by JBoss itself and requires additional Software or Hardware (switches or routers, for example Cisco LoadDirector). We’ll use this for Load Balancing Apache Web Server via mod_jk module.
    1. Download Apache2
    2. Download modjk 1.2.x
    3. Change the main Apache config to include modjk config
    4. Create the modjk config
    5. Configure the modjk workers (which JBoss nodes Apache uses)
    6. Configure the Apache URIs served by modjk (the applications served by JBoss)
    7. Restart Apache
    8. Configure Tomcat (Give each JBoss a jvmRoute for session slickness)
    9. Restart JBoss
    10. Test it
    3.1 Download and Install: Download Apache Web Server from http://httpd.apache.org/ .The more stable version is 2.0.9 and download mod_jk 1.2.x binary from

    Install Apache Web Server and set APACHE_HOME environment variable to Apache Web Server installation home directory and copy mod_jk.so file under directory APACHE_HOME/modules/.


    STEP 1: Setup Apache to use modjk
    Add the following line at the very bottom in APACHE_HOME/conf/httpd.conf




    STEP 2: Create the modjk config
    Under APACHE_HOME/conf/httpd.conf, create file name mod-jk.conf and populate it as follows.





    mod_jk is ready to forward requests to JBoss instances. We now need to setup the workers.

    STEP 3: Configuration of workers

    Under APACHE_HOME/conf, create workers.properties and populate it as follows:



    STEP 4: Now we have to create the uriworkermap.properties file under APACHE_HOME/conf directory. This file will contain the URL mappings you want Apache to forward to the JBoss Application server. The format of the file is /url=worker_name.




    STEP 5: Now Apache web server is configured with mod_jk to work as a Load Balancer and forward request to JBoss Application server. Now Restart Apache web server.

    STEP 6: Now we have to configure JBoss Application server
    [
    NOTE: We need to name each node accordingly to the names specified in workers.properties.]

    Open and edit JBOSS_HOME/server/all/deploy/jboss-web.deployer/server.xml and locate the element and add an attribute jvmRoute.


    The jvmRoute attribute must match the name specified in workers.properties.
    In the server.xml file, make sure that the AJP 1.3 Connector is uncommented, ex.



    [
    NOTE: If we are only accepting requests via mod_jk then we can comment out the regular HTTP Connector. Tomcat then won't listen on port 8080]

    STEP 7: Now we have to activate the UseJK Valve in JBoss. Finally we have to tell JBoss to add the jvmRoutevalue to its session cookies so that mod_jk can route incoming requests. Open and edit JBOSS_HOME/server/all/deploy/jboss-web.deployer/META-INF/jboss-service.xml

    STEP 8: Now all configurations have been done and we have to restart JBoss Application Server to access the shoping cart Application.
    To keep in cluster we have to pass some arguments during starting of JBoss instance.
    Syntax: - run.bat -c
    -b
    Ex: - run.bat –c nodeA –b 192.168.0.164

    [You can see detail in Start JBoss Instance]

    STEP 9: Access the shoping cart application through Apache by browsing to http://localhost/shopingcart or http://192.168.0.164/shopingcart and you can see the JBoss web console page


  4. Configuration of HTTP session state replication: HTTP session replication is used to copy the Web client state from one node to the other nodes in a cluster environment. When one node fails, another node in the cluster is able to continue processing the client requests without interruption.
    To enable clustering in our
    shoping cart web application, we must add the tag in the web.xml descriptor. Here's an example.


    This tag "distributable" has no parameter, it is just some kind of placeholder that tells the Servlet container that session should be replicated.
    We can further configure session replication using the replication-config element in the WebApplication\WEB-INF\jboss-web.xml file.


  5. Start JBoss 4.2.2 GA Instance: The simplest way to start a JBoss server cluster is to start several JBoss instances on the same local network, using the “run -c all” command for each instance. These server instances, started in the “all” configuration, detect each other and automatically form a cluster.



    [
    NOTE: If you want to access JBoss 4.2.2 GA using IP address instead of local host then use “-b” parameter with IP address.
    The following command will start a JBoss server named “nodeA” on IP 192.168.0.173.
    Ex:
    run.bat -c nodeA -b 192.168.0.173
    If you now try to start the application from other machines by using this IP it works]


  6. References:

    1. http://www.jboss.org/jbossmessaging/docs/userguide-1.4.0.GA/html/installation.html
    2. http://roneiv.wordpress.com/2008/01/03/jboss-tutorial-how-to-enable-ssl-https-on-jboss-as-well-as-other-nice-to-know-configurations/
    3. http://hasin.wordpress.com/2007/06/28/damn-why-the-hell-skype-is-blocking-port-80/
    4. http://www.jboss.org/community/docs/DOC-9384
    5. http://www.comptechdoc.org/os/linux/usersguide/linux_ugbasicnet.html
    6. http://www.windowsreference.com/windows-xp/how-to-addassign-multiple-ip-address-in-vistaxp20002003/
    7. http://www.jboss.org/community/docs/DOC-12525
    8. http://www.programmersheaven.com/mb/jsp/360057/360057/urgent-help---virtual-host-creation-using-apache-tomcat-for-windows/?S=B20000
    9. http://docs.huihoo.com/jonas/jonas-3.3.6/doc/howto/Clustering.html
    10. http://docs.jboss.org/jbossas/jboss4guide/r2/html/ch9.chapt.html