April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

JBoss AS Clustering

Java

Download
wget http://download.oracle.com/otn-pub/java/jdk/6u33-b04/jdk-6u33-linux-i586.bin

Create a bash script to set JAVA_HOME and add Java executables to the path.

vim /etc/profile.d/java.sh

export JAVA_HOME=/opt/jdk1.6.0_26/
export PATH=$JAVA_HOME/bin:$PATH

5. Source you new script so exports take effect

source /etc/profile.d/java.sh

6. Setup Java to be used by the alternatives system (if you want, or if you have an existing install of Java on your box.

alternatives –install /usr/bin/java java /opt/jdk1.6.0_04/bin/java 2

7. Set this new alternatives as the current configuration

alternatives –config java

 

 

 

Download and Install JBoss AS:

Download packaged distribution from http://www.jboss.org/jbossas/downloads
Unpack the compressed archive into a directory of your choice. e.g. /usr/jboss

Clustering in JBoss AS:

A cluster is a set of nodes that communicate with each other and work toward a common goal.
JBoss currently provides full clustering support. Replication of HTTP sessions for web applications is also available.Can also be integrated to an external balancer.

A Cluster provide these functionalities:
  • Scalability (can we handle more users? can we add hardware to our system?)
  • Load Balancing (share the load between servers)
  • High Availability (our application has to be uptime close to 100%)
  • Fault Tolerance (High Availability and Reliability)
  • Clustering support for stateless session beans, stateful session beans, entity beans and JNDI.

 

Partitions

As previously discussed, a cluster is a set of nodes. In JBoss, a node is a JBoss server instance. Thus, to build a cluster, several JBoss instances have to be grouped in what we call a partition.
The partition is the central concept for clustering in JBoss. Partitions are the basic building block of clustering in JBoss.
On a same network, we may have different partitions. In order to differentiate them, each partition must have an individual name.

 

Simple Web Architecture:

 

 

Simple web architecture is not scalable. Additional users can only be handled by improving the performance of the server (e.g.adding additional CPUs, more memory). No fault tolerance. If the JBoss AS server goes down, the entire service becomes unavailable.

External Load Balancer Architecture:
Add one or many web servers to balance the load to multiple JBoss AS nodes typically running on separate physical servers. Additional user load can be handled by adding another server running JBoss AS. If any one of the JBoss AS nodes fail, the service is still available through other JBoss AS servers.

A cluster is defined by:

  • Multicast Address
  • Multicast Post
  • Cluster Name
  • Multicast is the protocol which allow nodes inside to a cluster to communicate without knowing each other. Communication between nodes is provided by JGroups, which is library for multicast communication.

General configuration for the following examples:
Preparing a set of servers to act as a JBoss AS cluster involves a few simple steps:
Copy the all directory and create two directory node1 and node2 as below,

 

General configuration for the following examples:
Preparing a set of servers to act as a JBoss AS cluster involves a few simple steps:
Copy the all directory and create two directory node1 and node2 as below,

$ cd /usr/jboss/server
$ cp -r all jboss1
$ cp -r all
jboss2
$ cp -r all jboss3

Requirements Of Jboss Cluster:
Cluster Name
Multicast Address
Cluster Name
ServerPeerID (its unique id for JBoss Messaging.)
In this scenario we have 3 nodes with different ports on same server. Assume the machine has the 192.168.0.101 address assigned. The 3 JBoss instances(jboss1, jboss2 & jboss3) is created under folder /app/jboss/server as jboss1, jboss2 & jboss3. The ServerPeerID for the jboss1 is 1, for jboss2 is 2 & for jboss3 is 3. We have decided to set cluster name as “TestPartition” and to use 239.255.0.10 as our multicast address.

 

 

Launch a JBoss AS Cluster:

Now just start JBoss AS cluster nodes one by one as below,
For jboss1
$JBOSS_HOME/bin/run.sh -c jboss1 -b 0.0.0.0 -g TestPartition -u 239.255.0.10 -Djboss.messaging.ServerPeerID=1 -Djboss.service.binding.set=ports-default

For jboss2
$JBOSS_HOME/bin/run.sh -c jboss2 -b 0.0.0.0 -g TestPartition -u 239.255.0.10
-Djboss.messaging.ServerPeerID=2 -Djboss.service.binding.set=ports-02

For jboss3
$JBOSS_HOME/bin/run.sh -c jboss3 -b 0.0.0.0 -g TestPartition -u 239.255.0.10
-Djboss.messaging.ServerPeerID=3 -Djboss.service.binding.set=ports-03

In above scripts
The -c switch says to use the config “-c node1”.
The -g switch sets the cluster name “-u TestPartition”.
The -u switch sets the multicast address that will be used for intra-cluster communication
“-u 239.255.0.10”.
The -b switch sets the address on which sockets will be bound “-b 0.0.0.0”.
The -Djboss.messaging.ServerPeerID from which JBoss Messaging gets its unique id “-Djboss.messaging.ServerPeerID=1”.
The -Djboss.service.binding.set switch sets the port set for instance
“-Djboss.service.binding.set=ports-default”.
Ports sets are as below.
Ports-default = 8080
Ports-01 = 8180
ports-02 = 8280
ports-03 = 8380

Thats it, You have complete your JBoss AS clustering part.

Load Balancing Using Apache & mod_jk

Apache is a well-known web server which can be extended by plugging in modules. One of these modules, mod_jk, has been specifically designed to allow the forwarding of requests from Apache to a Servlet container. Furthermore, it is also able to load-balance HTTP calls to a set of Servlet containers while maintaining sticky sessions.

Advantages of Fronting with a Web Server :
Performance: dynamic vs. static content
Scalability & High Availability: load balancing and fail over
Security: web servers are simpler and easier to protect
Stability: proven, more robust
Features: URL rewriting, fine-grained access control, etc.
Fronting with Apache HTTPD:

Steps for Fronting with Apache HTTPD:
Download & compile Apache HTTPD
Download & compile mod_jk with Apache
AJP Connector on JBoss AS already enabled
Access web apps through Apache
Mod_jk (version 1.2.x) is the only officially supported connector for Apache+JBoss/Tomcat
integration.

Steps to install mod_jk
First of all, make sure that you have Apache installed. You can download Apache directly from Apache web site at http://httpd.apache.org. Installation of mod_jk is pretty straightforward and requires no specific configuration. Installation steps are as below,

$tar -zxvf tomcat-connectors-1.2.30-src.tar.gz
$cd tomcat-connectors-1.2.30-src/native
$./configure –with-apxs=$APACHE_HOME/bin/apxs
$make
$sudo make install

Configure Apache to load mod_jk :
Include configuration file of mod_jk in $APACHE_HOME/conf/httpd.conf.
Add below line
Include conf/mod_jk.conf

Configuring mod_jk.conf:
Create <apache-dir>/conf/mod_jk.conf & configure as below.
# Load mod_jk module
LoadModule jk_module $APACHE_HOME/modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile $APACHE_HOME/conf/workers.properties
# Where to find mod_jk.log file
JkLogFile /log/mod_jk.log
#Log level
JkLogLevel info
# Select the log format
JkLogStampFormat “[%a %b %d %H:%M:%S %Y]”
# JkRequestLogFormat
JkRequestLogFormat “%w %V %T”
# Add shared memory. This is needed for for load balancing to work properly
JkShmFile /log/jk.shm
# JkOptions indicates to send SSK KEY SIZE
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# Add jkstatus for managing runtime data
<Location /jkstatus/>
JkMount jkstatus
Order deny,allow
Deny from all
Allow from {HOST_IP}
</Location>
# Mount your applications
JkMountCopy All
JkMount /jmx-console jboss
JkMount /jmx-console/* jboss
JkMount /admin-console jboss
JkMount /admin-console/* jboss
JkMount /jkstatus jkstatus

Define a JBoss AS instance in $APACHE_HOME/conf/workers.properties

worker.list=jboss,jkstatus
#For Node1
worker.jboss1.type=ajp13
worker.jboss1.host=HOST_IP
worker.jboss1.port=8009
worker.jboss1.lbfactor=1
#For Node2
worker.jboss2.type=ajp13
worker.jboss2.host=HOST_IP
worker.jboss2.port=8109
worker.jboss2.lbfactor=1
#For Node3
worker.jboss3.type=ajp13
worker.jboss3.host=HOST_IP
worker.jboss3.port=8209
worker.jboss3.lbfactor=1

worker.jboss.type=lb
worker.jkstatus.type=status
worker.jboss.sticky_session=1
worker.jboss.balance_workers=jboss1,jboss2,jboss3

Configuring JBoss to work with mod_jk
Finally, we must configure the JBoss AS instances on all clustered nodes so that they can
expect requests forwarded from the mod_jk loadbalancer. On each clustered JBoss node, we have to
name the node according to the name specified in workers.properties.

$vim JBOSS_HOME/server/jboss1/deploy/jbossweb.sar/server.xml

Search for line <Engine name=”jboss.web” defaultHost=”localhost”> & add jvmRoute as below.

<Engine name=”jboss.web” defaultHost=”localhost” jvmRoute=”jboss1″>

Save & close the file. Make same changes on jboss2 & jboss3.

You also need to be sure the AJP connector in server.xml is enabled (i.e., uncommented). It is
enabled by default. Here your jboss instance is listening on ajp port (8009), you can disable http port
(8080).

<!– An AJP 1.3 Connector on port 8009 –>
<Connector protocol=”AJP/1.3″ port=”8009″ address=”${jboss.bind.address}”
redirectPort=”8443″ />

Now restart jboss1, jboss2 & jboss3.
Also restart apache server & check logs.
Access the the url for jmx-console as http://HOST_IP/jmx-console & http://HOST_IP/jkstatus

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>