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


Install and Configure Linux High-Availability Cluster tool "Pacemaker"

This example is based on the environment like follows. Configure basic cluster environment on here.

DB1:10.20.9.60(db1)

DB2:10.20.9.61(db2)

Install Pacemaker like follows on all Nodes.

[root@db1 ~]# yum -y install pacemaker pcs

[root@db1 ~]# systemctl start pcsd 

 

[root@db1 ~]# systemctl enable pcsd

# set password for cluster admin user

 

[root@db1 ~]# passwd hacluster 

Changing password for user hacluster.

New password:

Retype new password:

passwd: all authentication tokens updated successfully.

 

[2] Configure like follows on a Node.

 

# establish authorization

 

[root@db1 ~]# pcs cluster auth db1 db2 

Username: hacluster 

Password:

db1: Authorized

db2: Authorized

# configure cluster

 

[root@db1 ~]# pcs cluster setup --name ha_cluster db1 db2 

Shutting down pacemaker/corosync services...

Redirecting to /bin/systemctl stop pacemaker.service

Redirecting to /bin/systemctl stop corosync.service

Killing any remaining services...

Removing all cluster configuration files...

db1: Succeeded

db2: Succeeded

# start srvices for cluster

 

[root@db1 ~]# pcs cluster start --all 

db2: Starting Cluster...

db1: Starting Cluster...

# enable cluster

 

[root@db1 ~]# pcs cluster enable --all 

db1: Cluster Enabled

db2: Cluster Enabled

# show status

 

[root@db1 ~]# pcs status cluster

Cluster Status:

 Last updated: Wed Aug 31 11:28:19 2016         Last change: Wed Aug 31 06:17:00 2016 by root via cibadmin on db1

 Stack: corosync

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

 2 nodes and 1 resource configured

 Online: [ db1 db2 ]

PCSD Status:

  db1: Online

  db2: Online

 

 

[root@db1 ~]# pcs status corosync

Membership information

----------------------

    Nodeid      Votes Name

         1          1 db1 (local)

         2          1 db2