Configure Asterisk High Availability Cluster with DRBD
Today, In this article I will explains how to set up and maintain an Active/Passive Cluster of asterisk with DRBD Replication, using Pacemaker. We have two nodes, one is active and another in passive mode. If the active node goes down, the passive one will automatically take its position and all running services.
My Setup:
Configure the Asterisk HA Setup:
1) Installation and configuration of basic HA Cluster.
Previously We have already covered the Installation and configuration of basic HA Cluster. refer below link;
Configure the Basic HA Cluster Using pcs..
2) Configure and installation of the DRBD Setup.
We have covered the configuration of DRBD setup, refer the below link.
3) Configure MariaDB HA Pacemaker Cluster with DRBD.
We have already explained two node Active/Passive MariaDB HA Cluster using Pacemaker. refer below link for more information.
Configure MariaDB HA Pacemaker Cluster with DRBD
4) Install the Drbdlinks Package and download the drbdlink script from git.
To install drbdlinks, First create the new “drbdlink.repo” file in “/etc/yum.repos.d/” directory and that containing;
#vim /etc/yum.repos.d/drbdlink.repo
[drbdlink] name=Drbdlinks baseurl=http://dl.fedoraproject.org/pub/epel/7/x86_64/ enable=1 gpgcheck=0 ~ ~ :wq
Now Install “drbdlinks” packages from above repository, refer below command;
[master ~]# yum repolist all; yum install drbdlinks -y
Similarly, For the Node2
[client ~]# yum repolist all; yum install drbdlinks -y
Now Download and install the drbdlinks resource agents. Drbdlinks package provides Manages symbol-links into a shared DRBD partition(i.e /Drbdshared).
Note: We are installing the “drbdlinks” on Node1 server same steps are used on Node2 server.
[master ~]# git clone https://github.com/linsomniac/drbdlinks.git Cloning into 'drbdlinks'... remote: Counting objects: 159, done. remote: Total 159 (delta 0), reused 0 (delta 0), pack-reused 159 Receiving objects: 100% (159/159), 44.29 KiB | 0 bytes/s, done. Resolving deltas: 100% (93/93), done. [master ~]# ls anaconda-ks.cfg drbdlinks [master ~]# cd drbdlinks/ [master drbdlinks]# cp -vr drbdlinks /usr/lib/ocf/resource.d/heartbeat/ ‘drbdlinks’ -> ‘/usr/lib/ocf/resource.d/heartbeat/drbdlinks’ [root@client drbdlinks]# pcs resource agents ocf:heartbeat | grep drbdlinks drbdlinks [master drbdlinks]# chmod +x /usr/lib/ocf/resource.d/heartbeat/drbdlinks
We are mounting the DRBD device on “/Drbdshared” directory. On that Device we are creating directories on shared DRBD mount point to take the backup of Configuration files.
[master ~]# mkdir -p /Drbdshared/usr/lib/asterisk [master ~]# mkdir -p /Drbdshared/etc/asterisk
Now edit the “drbdlinks.conf” file on both the servers(or nodes) and add configuration path for asterisk .
#vim /etc/drbdlinks.conf
# it is equivalent to calling "link('/etc/httpd', '/shared/etc/httpd')".
#link('/etc/httpd')
#link('/var/lib/pgsql/')
mountpoint('/Drbdshared')
link('/usr/lib64/asterisk')
link('/etc/asterisk')
~
~
:wq
Copy all the configuration files on “/Drbdshared” directory.
[master ~]# cp -r /usr/lib64/asterisk/* /Drbdshared/usr/lib64/asterisk/ [master ~]# cp -r /etc/asterisk/* /Drbdshared/etc/asterisk/
Before configuring the asterisk resource first install the Asterisk resource agent. Below steps will be perform on both the nodes of cluster.
[master ~]# wget https://raw.githubusercontent.com/ClusterLabs/resource-agents/master/heartbeat/asterisk -O /usr/lib/ocf/resource.d/heartbeat/asterisk [master ~]# chmod +x /usr/lib/ocf/resource.d/heartbeat/asterisk
Node 2 Output:
[client ~]# wget https://raw.githubusercontent.com/ClusterLabs/resource-agents/master/heartbeat/asterisk -O /usr/lib/ocf/resource.d/heartbeat/asterisk [client ~]# chmod +x /usr/lib/ocf/resource.d/heartbeat/asterisk
5) Configure the cluster resource for Asterisk.
When you are using the pcs command, you can use the “-f” option to save a configuration change to a file without affecting the active CIB. If you have previously configured a cluster and there is already an active CIB, you use the following command to save the raw xml a file.
[master ~]# pcs cluster cib clustasterisk_cfg
We need to add ip address on which Asterisk service will run. We create a resource named as “virtualast_ip” for IP Address.
[master ~]# pcs -f clustasterisk_cfg resource create virtualast_ip ocf:heartbeat:IPaddr2 \ ip=172.16.1.21 cidr_netmask=24 \ op monitor interval=30s
Now We have to create a cluster resource for the Drbdlinks named as “drbdlinks”.
[master ~]# pcs -f clustasterisk_cfg resource create drbdlinks ocf:heartbeat:drbdlinks \ op monitor interval=20s
Then tell the cluster the resource i.e “drbdlinks” and “virtualast_ip” must be run on the same node as the file-system resource.
[master ~]# pcs -f clustasterisk_cfg constraint colocation add fsDRBD_mysql with drbdlinks score=INFINITY [master ~]#pcs -f clustasterisk_cfg constraint colocation add fsDRBD_mysql with virtualast_ip score=INFINITY
The “fsDRBD_mysql” resource must be started before the “drbdlinks” and “virtualast_ip” resource must started after the “drbdlinks” resource.
[master ~]# pcs -f clustasterisk_cfg constraint order fsDRBD_mysql then drbdlinks Adding fsDRBD_mysql drbdlinks (kind: Mandatory) (Options: first-action=start then-action=start) [master ~]# pcs -f clustasterisk_cfg constraint order drbdlinks then virtualast_ip Adding drbdlinks virtualast_ip (kind: Mandatory) (Options: first-action=start then-action=start) [master ~]#
Create the cluster resource for the asterisk named as “asterisk”.
[master ~]# pcs -f clustasterisk_cfg resource create asterisk ocf:heartbeat:asterisk \ params user="root" group="root" \ op monitor timeout="30"
The “virtualast_ip” resource must be started before the asterisk resource.
[master ~]# pcs -f clustasterisk_cfg constraint order virtualast_ip then asterisk Adding virtualast_ip asterisk (kind: Mandatory) (Options: first-action=start then-action=start) [master ~]#
Then Tell the cluster that the MariaDB service must be run on the same node as the “asterisk” resource.
[master ~]# pcs -f clustasterisk_cfg constraint colocation add fsDRBD_mysql with asterisk INFINITY
At Last, The MariaDB resource must be started before the “virtualast_ip” resource.
[master ~]# pcs -f clustasterisk_cfg constraint order MariaDB_New then virtualast_ip Adding MariaDB_New virtualast_ip (kind: Mandatory) (Options: first-action=start then-action=start) [master ~]#
We can commit changes now and check cluster status;
[master ~]# pcs cluster cib-push clustasterisk_cfg
[master ~]# pcs status
Cluster name: AsteriskCluster
Stack: corosync
Current DC: NODE2 (version 1.1.15-11.el7_3.4-e174ec8) - partition with quorum
Last updated: Thu Jul 6 08:39:45 2017 Last change: Thu Jul 6 07:40:53 2017 by root via crm_resource on NODE1
2 nodes and 8 resources configured
Online: [ NODE1 NODE2 ]
Full list of resources:
Master/Slave Set: databasebothnode [Database_mysql]
Masters: [ NODE1 ]
Slaves: [ NODE2 ]
fsDRBD_mysql (ocf::heartbeat:Filesystem): Started NODE1
MariaDB_New (systemd:mariadb): Started NODE1
MariaDB_VIP (ocf::heartbeat:IPaddr2): Started NODE1
virtualast_ip (ocf::heartbeat:IPaddr2): Started NODE1
drbdlinks (ocf::heartbeat:drbdlinks): Started NODE1
asterisk (ocf::heartbeat:asterisk): Started NODE1
Daemon Status:
corosync: active/disabled
pacemaker: active/disabled
pcsd: active/enabled
[master ~]#
Now try to login on asterisk console using below command;
[master ~]# asterisk -rvvv Asterisk 14.5.0, Copyright (C) 1999 - 2016, Digium, Inc. and others. Created by Mark Spencer <markster@digium.com> Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details. This is free software, with components licensed under the GNU General Public License version 2 and other licenses; you are welcome to redistribute it under certain conditions. Type 'core show license' for details. ========================================================================= Connected to Asterisk 14.5.0 currently running on master (pid = 7824) master*CLI>
Successfully We login on asterisk console. Make a note selinux should be disabled.
To test the data syncing between the nodes we need to perform below steps.
Now we are try to move the currently active resource on the node to another node, using below command will puts all nodes into standby mode.
[master ~]# pcs cluster standby NODE1 [master ~]# pcs status Cluster name: AsteriskCluster Stack: corosync Current DC: NODE2 (version 1.1.15-11.el7_3.4-e174ec8) - partition with quorum Last updated: Thu Jul 6 09:15:29 2017 Last change: Thu Jul 6 09:12:42 2017 by root via crm_attribute on NODE1 2 nodes and 8 resources configured Node NODE1: standby Online: [ NODE2 ] Full list of resources: Master/Slave Set: databasebothnode [Database_mysql] Masters: [ NODE2 ] Stopped: [ NODE1 ] fsDRBD_mysql (ocf::heartbeat:Filesystem): Started NODE2 MariaDB_New (systemd:mariadb): Started NODE2 MariaDB_VIP (ocf::heartbeat:IPaddr2): Started NODE2 virtualast_ip (ocf::heartbeat:IPaddr2): Started NODE2 drbdlinks (ocf::heartbeat:drbdlinks): Started NODE2 asterisk (ocf::heartbeat:asterisk): Started NODE2 Daemon Status: corosync: active/disabled pacemaker: active/disabled pcsd: active/enabled [master ~]#
Now go to Node2 and try to login on asterisk console using below command;
[client ~]# asterisk -rvv Asterisk 14.5.0, Copyright (C) 1999 - 2016, Digium, Inc. and others. Created by Mark Spencer <markster@digium.com> Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details. This is free software, with components licensed under the GNU General Public License version 2 and other licenses; you are welcome to redistribute it under certain conditions. Type 'core show license' for details. ========================================================================= Connected to Asterisk 14.5.0 currently running on client (pid = 25052) client*CLI>
Hope this post will help Linux/Unix beginners. Please share you feedback and Comments. Stay tune for more updates with ittroubleshooter.in …!!!
Leave a Reply