This is a two node Apache tomcat cluster with virtual IP 10.20.9.225
node1.example.com
node2.example.com
Add the following to the /etc/hosts file in both nodes so that they are able to reach each other
10.20.9.220 node1.example.com node1
10.20.9.221 node2.example.com node2
Now install the pre-requisites on both nodes
#yum install -y java-1.7.0-openjdk.x86_64 pcs pacemaker corosync cman wget
Download and extract Apache Tomcat
#cd /usr/local/
#wget http://apache.arvixe.com/tomcat/tomcat-6/v6.0.43/bin/apache-tomcat-6.0.43.tar.gz
#tar xvzf apache-tomcat-6.0.43.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 node1 node2
Now create the cluster
#pcs cluster setup --name MYCLUSTER node1 node2
#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.225 cidr_netmask=24 op monitor interval=30s
#pcs resource create tomcat ocf:heartbeat:tomcat params java_home="/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64/jre" catalina_home="/usr/local/apache-tomcat-6.0.43" 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
#################################################################################
Amazing, worked for me. Just located tomcat in shared NFS directory (/var/www/html) and it works with HA :). Thanks.... Hope I will be able manage NodeJS with Pacemaker too....
ReplyDeleteAlso maybe you know how to manage crond with pcs, thanks.
Its simple. Just add cron service as a resource. Detailed explanation here
Deletehttp://muru-techsolution.blogspot.in/2015/10/cron-with-pacemaker.html
i am doing this now. i am able to launch tomcat, but the cluster is not able to stop the instance. any clue why? i'm still looking
ReplyDelete