{"id":55,"date":"2015-06-29T09:54:34","date_gmt":"2015-06-29T13:54:34","guid":{"rendered":"http:\/\/blog.voipxswitch.com\/?p=55"},"modified":"2015-12-11T10:35:09","modified_gmt":"2015-12-11T15:35:09","slug":"kamailio-high-availabilityfailover-with-corosync-and-pacemaker-on-debian-7","status":"publish","type":"post","link":"https:\/\/blog.voipxswitch.com\/?p=55","title":{"rendered":"Kamailio: High-Availability\/Failover with Corosync and Pacemaker on Debian 7"},"content":{"rendered":"<p>In this setup, we will have 2 Kamailio servers, referred to as &#8216;nodes&#8217;. One will be active and one will standby. There is a 3rd &#8216;floating&#8217; IP that is moved to which ever node is active. Kamailio should be configured to use the floating IP. In this example, the nodes are:<\/p>\n<p style=\"padding-left: 30px;\"><strong>kam01: 10.10.10.18<\/strong><br \/>\n<strong>kam02: 10.10.10.19<\/strong><\/p>\n<p style=\"padding-left: 30px;\"><strong>Floating IP: 10.10.10.200<\/strong><\/p>\n<p>First, add both nodes to \/etc\/hosts<\/p>\n<pre>10.10.10.18\u00a0\u00a0 \u00a0kam01\r\n10.10.10.19\u00a0\u00a0 \u00a0kam02<\/pre>\n<p>Install corosync and pacemaker:<\/p>\n<pre>apt-get install ntp corosync pacemaker -y<\/pre>\n<p>Generate \/etc\/corosync\/authkey:<\/p>\n<pre>corosync-keygen<\/pre>\n<p>Copy corosync-key\u00a0 to kam02:<\/p>\n<pre>scp -P 22 \/etc\/corosync\/authkey root@kam02:\/etc\/corosync<\/pre>\n<p>Enable corosync on kam01 &amp; kam02:<\/p>\n<pre>sed -i \"s\/START=no\/START=yes\/g\" \/etc\/default\/corosync<\/pre>\n<p>Enable pacemaker service in corosync:<\/p>\n<pre>cat &gt; \/etc\/corosync\/service.d\/pcmk &lt;&lt; EOF\r\nservice {\r\n\u00a0 name: pacemaker\r\n\u00a0 ver: 1\r\n}\r\nEOF<\/pre>\n<p>Add corosync config:<\/p>\n<pre>cat &gt;\/etc\/corosync\/corosync.conf&lt;&lt;EOF\r\n#\r\ntotem {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 version: 2\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 transport: udpu\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 interface {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 member {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 memberaddr: 10.10.10.18\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 member {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 memberaddr: 10.10.10.19\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ringnumber: 0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 bindnetaddr: 10.10.10.0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 mcastport: 5405\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n}\r\n\r\nlogging {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 to_logfile: yes\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 logfile: \/var\/log\/corosync\/corosync.log\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 debug: off\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 timestamp: on\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 logger_subsys {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 subsys: AMF\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 debug: off\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n}\r\nEOF<\/pre>\n<p>Start corosync and pacemaker:<\/p>\n<pre>service corosync start\r\nservice pacemaker start<\/pre>\n<p>Configure corosync, changes will propagate to other node. Make sure to disable stonith:<\/p>\n<pre class=\"codebox\">crm configure property stonith-enabled=false\r\ncrm configure primitive FAILOVER-IP ocf:heartbeat:IPaddr2 params ip=\"10.10.10.200\" nic=\"eth0\" cidr_netmask=\"255.255.255.0\" op monitor interval=\"10s\"\r\ncrm configure primitive KAM-HA lsb:kamailio op monitor interval=\"30s\"\r\ncrm configure group KAM-HA-GROUP FAILOVER-IP KAM-HA\r\ncrm configure colocation KAM-HA-GROUP-COLO inf: FAILOVER-IP KAM-HA\r\ncrm configure order KAM-HA-ORDER inf: FAILOVER-IP KAM-HA\r\ncrm configure property no-quorum-policy=ignore<\/pre>\n<p>You need no-quorum-policy=ignore for a 2 node cluster. If you messed up during the crm configure part, you can start over using these commands:<\/p>\n<pre># TO CLEAR CONFIG AND START OVER\r\ncrm configure property stop-all-resources=true\r\ncrm configure erase<\/pre>\n<p>It&#8217;s sometimes useful to see what resource agents are available, you can check with these commands:<\/p>\n<pre># TO LIST RESOURCE AGENTS\r\ncrm ra list lsb\r\ncrm ra list systemd # (if using systemd init system)\r\ncrm ra list ocf heartbeat\r\ncrm ra list ocf pacemaker<\/pre>\n<p>If you need to migrate services and floating IP to other node you can run:<\/p>\n<pre>crm resource migrate KAM-HA-GROUP kam02<\/pre>\n<p>If you need edit specific parameters in the config, you can export it to xml, make the changes and re-import them:<\/p>\n<pre># ADVANCED EDITING\r\ncibadmin --query &gt; tmp.xml\r\nvi tmp.xml\r\ncibadmin --replace --xml-file tmp.xml<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this setup, we will have 2 Kamailio servers, referred to as &#8216;nodes&#8217;. One will be active and one will standby. There is a 3rd &#8216;floating&#8217; IP that is moved to which ever node is active. Kamailio should be configured to use the floating IP. In this example, the nodes are: kam01: 10.10.10.18 kam02: 10.10.10.19 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,19,6,21,12,25,15],"tags":[],"class_list":["post-55","post","type-post","status-publish","format-standard","hentry","category-corosync","category-failover","category-high-availability","category-kamailio","category-pacemaker","category-sip","category-voip"],"_links":{"self":[{"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=\/wp\/v2\/posts\/55","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=55"}],"version-history":[{"count":3,"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=\/wp\/v2\/posts\/55\/revisions"}],"predecessor-version":[{"id":99,"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=\/wp\/v2\/posts\/55\/revisions\/99"}],"wp:attachment":[{"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=55"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=55"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.voipxswitch.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=55"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}