Wednesday, 31 August 2016

Apache Tomcat Clustering using Pacemaker on CentOS 7


Pacemaker is a High Availability cluster Software for Linux like Operating System.Pacemaker is known as ‘Cluster Resource Manager‘, It provides maximum availability of the cluster resources by doing fail over of resources between the cluster nodes.

Pacemaker use corosync for heartbeat and internal communication among cluster components , Corosync also take care of Quorum in cluster.

In this article we will demonstrate the installation and configuration of two Node Apache Tomcat Clustering using Pacemaker on CentOS 7.

Add the following to the /etc/hosts file in both nodes so that they are able to reach each other


Add the following lines in /etc/hosts file in both the nodes.
10.20.9.60       tomcat1

10.20.9.61       tomcat2

Now install the pre-requisites on both nodes

install the java on both node

#yum install -y java

# java -version

openjdk version "1.8.0_101"

OpenJDK Runtime Environment (build 1.8.0_101-b13)

OpenJDK 64-Bit Server VM (build 25.101-b13, mixed mode)

Install Pacemaker like follows on both Nodes.


#yum install -y pcs pacemaker corosync cman wget

Download and extract Apache Tomcat

#cd /opt/
#wget http://ftp.itu.edu.tr/Mirror/Apache/tomcat/tomcat-8/v8.5.4/bin/apache-tomcat-8.5.4.tar.gz

#tar -xvf apache-tomcat-8.5.4.tar.gz

Now set password for the hacluster user on both nodes

#passwd hacluster

Now start pcsd service on both nodes and add it to startup

#service pcsd start
#chkconfig pcsd on

Now authorize the cluster nodes. Will ask for username and password. Use "hacluster"

#mkdir /etc/cluster
#pcs cluster auth tomcat1 tomcat2

Now create the cluster

#pcs cluster setup --name ha_cluster tomcat1 tomcat2 

#pcs cluster start --all


Now disable STONITH and quorum as it is not required for a two node setup

#pcs property set stonith-enabled=false

#pcs property set no-quorum-policy=ignore

Now add the resources. We need a virtual IP and tomcat resource

#pcs resource create VirtualIP ocf:heartbeat:IPaddr2 ip=10.20.9.62 cidr_netmask=24  op monitor interval=30s

 #pcs resource create tomcat ocf:heartbeat:tomcat params java_home="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.101-3.b13.el7_2.x86_64/jre" catalina_home="/opt/apache-tomcat-8.5.4" tomcat_user="root" op monitor interval="15s"

Now to make both resources run in the same node we must have a constraint as follows

# pcs constraint colocation set VirtualIP tomcat

All done. Now stop the cluster and start it.

#pcs cluster stop --all

#pcs cluster start --all

# pcs status

Cluster name: ha_cluster

Last updated: Wed Aug 31 12:14:51 2016          Last change: Mon Aug 29 17:35:34 2016 by root via cibadmin on tomcat1

Stack: corosync

Current DC: tomcat2 (version 1.1.13-10.el7_2.4-44eb2dd) - partition with quorum

2 nodes and 2 resources configured

Online: [ tomcat1 tomcat2 ]

Full list of resources:

 VirtualIP      (ocf::heartbeat:IPaddr2):       Started tomcat2

 tomcat (ocf::heartbeat:tomcat):        Started tomcat2

PCSD Status:

  tomcat1: Online

  tomcat2: Online

Daemon Status:

  corosync: active/enabled

  pacemaker: active/enabled

  pcsd: active/enabled


5 comments:

  1. Dear Raju, I have followed the same steps but in my case when I try to create the tomcat resource it is showing "unable to get cib"
    Pls help !

    ReplyDelete
  2. Hi Raju,

    I can't make it work with Tomcat. I always get the following:
    Failed Actions:
    * tomcat_start_0 on tomcat16 'unknown error' (1): call=10, status=Timed Out, exitreason='none',
    last-rc-change='Mon Jan 8 06:43:29 2018', queued=0ms, exec=60002ms

    Please help.

    ReplyDelete
    Replies
    1. I got the same problem, any solution?

      Delete
    2. I think that happens because Tomcat service in nodes really is not running

      Delete
  3. When I change default port 8080 than cluster tomcat services disable . Have any solution for this problem

    ReplyDelete