Install pacemaker on ubuntu

Tested On

OS: Ubuntu 14.04
Pacemaker Version: 1.1.10
Corosync Version: 2.3.3

About

Pacemaker is a cluster system for linux systems. pacemaker help you create highly available services by automatically recover/failover to multiple servers.

In this guide I will explain how I install pacemaker and corosync on ubuntu and configure haproxy cluster on two servers.

Install and configure pacemaker and corosync

  • run the following steps on both servers
  • install packages using apt-get
apt-get install pacemaker corosync fence-agents
  • configure corosync (change ring0_addr to the right address):
vi /etc/corosync/corosync.conf
# Please read the corosync.conf.5 manual page
totem {
 version: 2
 secauth: off
 cluster_name: pacemaker1
 transport: udpu
}

nodelist { 
 node { 
 ring0_addr: haproxy-1
 nodeid: 101 
 } 
 node { 
 ring0_addr: haproxy-2
 nodeid: 102 
 } 
}

quorum { 
 provider: corosync_votequorum 
 two_node: 1 
 wait_for_all: 1 
 last_man_standing: 1 
 auto_tie_breaker: 0 
}

logging {
 fileline: off
 to_logfile: yes
 to_syslog: no
 debug: on
 logfile: /var/log/corosync/corosync.log
 debug: off
 timestamp: on
 logger_subsys {
 subsys: AMF
 debug: off
 }
}
  • configure corosync to start
vi /etc/default/corosync
# start corosync at boot [yes|no]
START=yes
  • start corosync

service corosync start

  • download haproxy ocf resource
cd /usr/lib/ocf/resource.d/heartbeat
 40 curl -O https://raw.githubusercontent.com/thisismitch/cluster-agents/master/haproxy
chmod +x haproxy

ocf resource is a script that pacemaker use to start, stop and monitor a resource (service)

  • install and configure haproxy
apt-get install software-properties-common
add-apt-repository ppa:vbernat/haproxy-1.6
apt-get update
apt-get install haproxy

vi /etc/haproxy/haproxy.cfg
global
 log /dev/log local0
 log /dev/log local1 notice
 user haproxy
 group haproxy
 daemon

defaults
 mode http
 option forwardfor
 option http-server-close

frontend test
 bind 192.168.10.10:80
 default_backend test

backend test
 balance roundrobin
 server server1 192.168.20.11:8080 weight 10 check fall 5
 server server2 192.168.20.12:8080 weight 10 check fall 5
  • configure kernel parameter non local bind so we can start haproxy on both servers even if the server don’t own the vip
vi /etc/sysctl.conf
...
net.ipv4.ip_nonlocal_bind=1
  • reload sysctl.conf file
sysctl -p

Configure pacemaker resources

  • run the following steps on one server
  • configure vip resource
crm configure primitive test-ip ocf:heartbeat:IPaddr2 params ip=192.168.10.10 cidr_netmask=24 op monitor interval=30s

Here we configure a vip that in case of a problem with one server will failover to the other server.

  • configure haproxy resource
crm configure primitive haproxy ocf:heartbeat:haproxy op monitor interval=15s

we configure pacemaker to start and monitor haproxy every 15s, but we want to start haproxy on both servers so we will create a clone resource

  • clone haproxy resource
crm configure clone haproxy-clone haproxy

we create clone resource named haproxy-clone by cloning our haproxy resource. This configuration tell pacemaker to start haproxy on both servers at the same time.
now we need to make sure that the vip resource  is running where haproxy is healthy/running

  • create colocation resource
crm configure colocation test-ip-haproxy inf: test-ip haproxy-clone

This configuration tell pacemaker to run the test-ip resource where the haproxy is running so if we have a problem with haproxy on one server and pacemaker can’t restart haproxy automatically then pacemaker will make sure that test-ip will run on the server with the healthy haproxy by migrating the test-ip resource to the right server.

for more informatrion about pacemaker