Asterisk Cluster on CentOS
From KlavoWiki
I have completed the following using CentOS 7.1 and Asterisk 13.4.0
Firewall
Disable firewall or allow the required ports manually. See Firewall_for_Linux
The Cluster
The following needs to be done on both servers.
Install Cluster Apps
yum -y install corosync pcs pacemaker
systemctl enable pcsd systemctl enable corosync systemctl enable pacemaker
systemctl start pcsd
Create Cluster User
Use a 30 plus character random password.
passwd hacluster
Install Asterisk resource agent
wget https://raw.githubusercontent.com/ClusterLabs/resource-agents/master/heartbeat/asterisk -O /usr/lib/ocf/resource.d/heartbeat/asterisk chmod +x /usr/lib/ocf/resource.d/heartbeat/asterisk
Configure Cluster
The following is only required on a single server as it will be replicated across your cluster.
Bind Servers
The first command will use the username and password of the user account hacluster as created above.
pcs cluster auth srv1.myserver.com srv2.myserver.com pcs cluster setup --name pbx-cluster srv1.myserver.com srv2.myserver.com pcs cluster start --all
pcs property set stonith-enabled=false pcs property set no-quorum-policy=ignore
This is creating a clustered IP address of 192.168.25.30
pcs resource create virtual_ip ocf:heartbeat:IPaddr2 ip=192.168.25.30 cidr_netmask=32 op monitor interval=30s
Install Asterisk
Refer to Asterisk_Install if you are not sure how.
Create Asterisk Cluster
pcs resource create asterisk ocf:heartbeat:asterisk params user="root" group="root" op monitor timeout="30" pcs constraint colocation add asterisk with virtual_ip score=INFINITY pcs constraint order virtual_ip then asterisk
If a specific sever is required to be used over another
pcs constraint location asterisk prefers srv1.myserver.com
or if multiple servers
pcs constraint location asterisk prefers srv1.myserver.com=5 pcs constraint location asterisk prefers srv2.myserver.com=10 pcs constraint location asterisk prefers srv3.myserver.com=15
Tools
Status
pcs status pcs status cluster pcs status nodes
pcs constraint
Move
pcs resource move asterisk
Other Details
corosync-cmapctl | grep members pcs status corosync pcs property
Stop/Start a Single Node
pcs cluster stop srv2.myserver.com pcs cluster start srv2.myserver.com
Adding/Removing Nodes
pcs cluster add srv3.myserver.com
pcs cluster stop srv2.myserver.com pcs cluster remove srv2.myserver.com