Sunday, October 14, 2012

Testing cluster with three computers in JBOSS


First we have to create a cluster with three nodes. One node means one machine. That all three computers should be jboss installed. Then we need to start jboss with all configuration and bind with computer IP address. Therefore open the command prompt and go to the jboss bin directory. Then run following command.
Run.bat –c all –b 192.168.1.140 –Djboss.messaging.ServerPeerID=1
This serverPeerId should be unique within a cluster. Since we have three computers in our cluster, we need to start jboss with different peerIDs and corresponding IP’s by running above code.
Now we have created a cluster. Then we need to create a load balancer. So we need to install apache http server on one of above three machine or separate machine. We need not to install apache on every computers.
Go to the following link to download apache http server. Then download and install win32 MSI installer.  It is better not to install inside program files. Because the is a space between “Program file” directory. So in could be a problem. So create a new folder called apache inside C drive and install into that folder.


We are going to use mod_jk.so connecter for load balancing. We have to download mod_jk.so file from following link.


you need to download tomcat-connectors-1.2.37-windows-i386-httpd-2.2.x.zip. Because we used apache 2.2.22. 
Then unzip the downloaded file and copy that mod_jk.so file into modules folder inside apache installed directory.
Then go to the apache conf folder. Now create a file called mod_jk.conf and add following code to that file.

LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkShmFile logs/mod_jk.shm
JkLogFile logs/mod_jk.log
JkLogLevel info
JkMount /FarmTest-war/* loadbalancer

Most important part of above code is jkMount part. /FarmTest-war/* is the URL pattern of the clustered resource. So you need to specify your clustered resource here.
Then create another file called workers.properties inside the conf folder. This is the file that we specify cluster details. Add following code to that file.

# Define list of workers that will be used
     # for mapping requests
       worker.list=loadbalancer,status
     # Define Node1
     # modify the host as your host IP or DNS name.
       worker.node1.port=8009
    worker.node1.host=192.168.1.140
      worker.node1.type=ajp13
      worker.node1.lbfactor=1
       worker.node1.cachesize=10
     # Define Node2
     # modify the host as your host IP or DNS name.
       worker.node2.port=8009
       worker.node2.host= 192.168.1.141
       worker.node2.type=ajp13
       worker.node2.lbfactor=1
       worker.node2.cachesize=10
 #define node3
worker.node3.port=8009
       worker.node3.host=192.168.1.142
       worker.node3.type=ajp13
       worker.node3.lbfactor=1
      #worker.node1.local_worker=1 (1)
       worker.node3.cachesize=10
           
     # Load-balancing behavior
       worker.loadbalancer.type=lb
       worker.loadbalancer.balance_workers=node1,node2,node3
       worker.loadbalancer.sticky_session=1

Then open the httpd.conf file which located inside the conf folder. Then add following line of code to the bottom of that file.

Include conf/mod_jk.conf

Now restart the apache server.
Then start all jboss nodes.
We have created a load balancer and cluster with three nodes. Now we need to deploy an application to the cluster.  Create a small enterprise application and deploy it with one machine. Then go to the deploy folder inside the “all” folder. Now copy the application “war” file and paste it to the farm folder inside the “all” folder.
Now we deployed an application to the cluster. Now open a web browser and go to following link.
This IP address is the IP address of apache installed computer. 



No comments:

Post a Comment