Configuring a cluster on the same machine using port offset on standalone mode

What is Cluster?
  • A Cluster is a group of application server instances configured in a single or multiple machines (hosts), and will provide a scalability and availability than a single instance server can provide. And run an Application in continuously in the form of single entry.
  • In general a server instance is called as a node. In this example I am creating two servers in a cluster, Means first server is called as a node1 and second server is called as a node2.
  • In this example I am using JBoss server for creating cluster. You don't have JBoss server in your local machine, follow my previous post and get the server download.( How to download Red Hat JBoss Application Server? )

Using JBoss server you can achieve clustering in two ways

                1) Standalone mode using ha profile.
                2) Domain mode using ha profile.
In this example I am creating cluster using standalone mode. Below is the folder structure given by JBoss.

  • In the above diagram standalone folder is given by the JBoss for one node instance, but here we are going to creating two nodes instances server (Clustering server), because of this reason need a another copy of standalone folder,  for this we need a duplicate copy for standalone folder. But for easy identification purpose I am creating two copies for standalone folder with the names node1 and node2.
  • Here node1 directory for server instance 1 and node2 directory for sever instance 2. For this procedure we are automatically getting a backup of standalone folder for feature reference.  Find the folder structure below after creating node1 and node2 instances.


JBoss Profiles:
JBoss server is available with 4 profiles
  1. Default or Standalone Profile
  2. Ha Profile
  3. Full Profile
  4. Full-Ha Profile
  • If you do not specify any specific profile configuration file, server will start with the default profile, it means by default JBoss server will use standalone.xml file.
  • Starting instance with an alternative profile configuration, we need to specify profile name in server starting time like below
Windows:
Syntax:  
</JBOSS_HOME>/bin/standalone.bat --server-config=<Profile-name>.xml
EX: 
</JBOSS_HOME>/bin/standalone.bat --server-condig=standalone-ha.xml
Linux:
Syntax:  
</JBOSS_HOME>/bin/standalone.sh --server-config=<Profile-name>.xml
EX: 
</JBOSS_HOME>/bin/standalone.sh --server-config=standalone-ha.xml
  • In above example profile or configuration file must be loaded in the </JBOSS_HOME>/standalone/configuration/ directory.
  • You need to specify your own file as a profile or configuration file, and then you must be specify a file with path, in our example you have created a node1 and node2 folder, so If you want to start node1 server, then start sever like below
Syntax:  
</JBOSS_HOME>/bin/standalone.bat --server-config=</JBOSS_HOME>/node1/configuration/<Profile-name>.xml
EX: 
</JBOSS_HOME>/bin/standalone.bat --server-condig=</JBOSS_HOME>/node1/configuration/standalone-ha.xml
Linux:
Syntax:  
</JBOSS_HOME>/bin/standalone.sh --server-config=</JBOSS_HOME>/node1/configuration/<Profile-name>.xml
EX: 
</JBOSS_HOME>/bin/standalone.sh --server-condig=</JBOSS_HOME>/nod1/standalone-ha.xml
In this case node1 server is using default ports for starting server.
  • You know very well, ports are unique, so for starting node2 server in same machine must need changes in port numbers. Basically JBoss server is using multiple ports for starting server, for example JBoss Administration console will use 9990 port, JBoss-CLI mode will user 9999 port, for application access 8080 port, for AJP communication 9008 etc…
  • For changing port numbers in every place is very difficult, for this reason JBoss server providing concept called offset, for achieving this concept we need changes in port-offset attribute in socket-binding-group section on corresponding profile.
  • Search for “socket-binding-group” in standalone-ha.xml file, here you will see port-offset attribute in same line, by default port-offset vale is 0(zero), if you changed value from 0 to 1 then all the ports values will increase 1 (one) number (for example 8080 + 1 = 8081, 9990 + 1 = 9991 etc… ).
  • Otherwise you can pass offset value in server starting time like below
  • </JBOSS_HOME>/bin/standalone.sh --server-condig=</JBOSS_HOME>/nod2/standalone-ha.xml -Djboss.socket.binding.port-offset=1
  • The Best practice for starting server in production or non production servers is creating script for every node. In this example you have two nodes so create node1.sh/node1.bat and node2.sh/node2.bat like below
Note: here my home/base directory is “C:\Users\gurugubelli\jboss-eap-6.4”, In your example you must update a base directory of the server path.
node1.bat
standalone.bat -Djboss.server.base.dir=C:\Users\gurugubelli\jboss-eap-6.4\node1\standalone  -Djboss.socket.binding.port-offset=0
node1.sh
standalone.sh -Djboss.server.base.dir=/gurugubelli/jboss-eap-6.4/node1/standalone  -Djboss.socket.binding.port-offset=0
In node1 script, -Djboss.socket.binding.port-offset is a optional, because by default JBoss will use offset is 0. 
node2.bat
standalone.bat -Djboss.server.base.dir=C:\Users\gurugubelli\jboss-eap-6.4\node2\standalone  -Djboss.socket.binding.port-offset=1
node2.sh
standalone.sh -Djboss.server.base.dir=/gurugubelli/jboss-eap-6.4/node2/standalone  -Djboss.socket.binding.port-offset=1
  • So If you want to start server with two nodes, just need to run a node1.sh/node1.bat and node2.sh/node2.bat file
  • After successful starting of the server you will get messages like below.
For node1 server:

For node2 server:
Configuring a cluster on the same machine using port offset on standalone mode Configuring a cluster on the same machine using port offset on standalone mode Reviewed by Gurugubelli Technologies on September 27, 2017 Rating: 5

1 comment:

  1. Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updatingHadoop Admin Online Training Bangalore

    ReplyDelete

Powered by Blogger.