How To Configure High Availability FreePBX or Asterisk HA Cluster with Pacemaker on Ubuntu 18.04

In this High Availability FreePBX HA Cluster with Pacemaker tutorial on Ubuntu 18.04, I am assuming you have a set of two identical FreePBX or just Asterisk sharing a single MySQL database. I am also assuming both of your FreePBX are configured with all the modules you need.

Important: Once the cluster is configured the adding module could break the FreePBX’s functionality.

In this tutorial, the first FreePBX/Asterisk hostname is “asterisk-master” with IP and the second FreePBX Asterisk’s hostname is “asterisk-slave” with IP address Our Floating/Virtual IP is

If you do not have two identical FreePBX or just Asterisk sharing a single MySQL database follow this blog to configure them.


Setting Up Hostname Entries

On asterisk-master & asterisk-slave Node Run The Following

echo " asterisk-master" >> /etc/hosts
echo " asterisk-slave" >> /etc/hosts

Install The Required Ubuntu Packages

On asterisk-master & asterisk-slave Node Run The Following

apt install -y corosync pcs pacemaker

Enable pcsd, corosync and pacemaker Auto Start on Both Nodes

On asterisk-master & asterisk-slave Node Run The Following

systemctl enable pcsd; systemctl enable corosync; systemctl enable pacemaker

Stop and Disable “asterisk” to Auto Start on Both Nodes

On asterisk-master & asterisk-slave Node Store and Disable asterisk service

systemctl stop asterisk
systemctl disable asterisk

Edit the Buggy”asterisk” resource script on Both Nodes

On asterisk-master & asterisk-slave Edit asterisk recourse File

vi /usr/lib/ocf/resource.d/heartbeat/asterisk

Comment Out the following 2 lines

#: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
#. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs

Add the following line after “# Initialization:”

. /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs

The Lines Should Look

# Initialization:
. /usr/lib/ocf/lib/heartbeat/ocf-shellfuncs
#: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
#. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs

We Need to Apply FreePBX Config Changes After Asterisk Starts

Look for the Following Line

ocf_log info "Asterisk PBX started"

Add the Following Two Lines Above That Line and Save

sleep 5
/usr/sbin/fwconsole reload

Start pcsd Service on Both Nodes

On asterisk-master & asterisk-slave Node

systemctl start pcsd

Set the Same Password on Both Nodes

On asterisk-master & asterisk-slave Node

passwd hacluster

Authorize Nodes to Each Other

On asterisk-master Node

pcs cluster auth asterisk-master asterisk-slave

Begin Setting Up  HA Cluster

Run the Following on asterisk-master Node

pcs cluster setup --name asterisk_cluster asterisk-master asterisk-slave --force
systemctl start pacemaker; systemctl start corosync
pcs cluster start --all
pcs property set stonith-enabled=false
pcs property set no-quorum-policy=ignore
pcs resource create virtual_ip ocf:heartbeat:IPaddr2 ip= cidr_netmask=32 op monitor interval=30s on-fail=restart
pcs resource create p_asterisk ocf:heartbeat:asterisk op monitor timeout="30s" interval="20s"
pcs constraint colocation add p_asterisk with virtual_ip score=INFINITY
pcs constraint order virtual_ip then p_asterisk

Run this on asterisk-master to be the Primary Node

On asterisk-master

pcs constraint location p_asterisk prefers asterisk-master

Verify Cluster

On asterisk-master & asterisk-slave

pcs status

Successful Cluster Will Output As Follow

Cluster name: asterisk_cluster
Stack: corosync
Current DC: node2 (version 1.1.18-2b07d5c5a9) - partition with quorum
Last updated: Sun Dec 16 17:08:20 2018
Last change: Sun Dec 16 15:51:53 2018 by root via cibadmin on node1

2 nodes configured
2 resources configured

Online: [ node1 node2 ]

Full list of resources:

virtual_ip (ocf::heartbeat:IPaddr2): Started node1
p_asterisk (ocf::heartbeat:asterisk): Started node1

Daemon Status:
corosync: active/enabled
pacemaker: active/enabled
pcsd: active/enabled


Write us here if you require assistance configuring FreePBX HA Cluster.  We will respond within an hour.

Leave a Reply

Your email address will not be published. Required fields are marked *