Elastix 2.5 + heartbeat + drbd

As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:

Elastix 2.5 stable

Heartbeat for failover

Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:

Stability, Reliability, High-availability

Let`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.

I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

/dev/sda1 - /<br /> /dev/sda2 - swap<br /> /dev/sdb1 - /replica

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.

(By identical i meant compleatly identical start block and finish block must be same on both)

  1. When everything is installed, we need to create FS for /dev/sdb

[root@voipSERVER.drbd /]# fdisk /dev/sdb<br /> p<br /> n<br /> ----<br /> t - 83<br /> w

  1. Format :

[root@voipSERVER.drbd /]# mke2fs -j /dev/sdb1

  1. Just in case, we gonna formated with zeros:

[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync

  1. Installing drbd and heartbeat:

yum install heartbeat drbd83 kmod-drbd83

Note: If by any chance you experience problems with drbd83, use drbd82 version (64 bit

versions).

  1. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

192.168.0.242 voipserver.drbd<br /> 192.168.0.243 voipbackup.drbd

  1. Edit /etc/drbd.conf on the Primary one:

<br /> global { usage-count no; }<br /> resource r0 {<br /> protocol C;<br /> startup { wfc-timeout 10; degr-wfc-timeout 30; }<br /> disk { on-io-error detach; }<br /> net {<br /> after-sb-0pri discard-least-changes;<br /> after-sb-1pri discard-secondary;<br /> after-sb-2pri call-pri-lost-after-sb;<br /> cram-hmac-alg "sha1";<br /> shared-secret "SECRET PASSWD";<br /> }<br /> syncer { rate 5M; }<br /> on voipserver.drbd {<br /> device /dev/drbd0;<br /> disk /dev/sdb1;<br /> address 192.168.0.242:7788;<br /> meta-disk internal;<br /> }<br /> on voipbackup.drbd {<br /> device /dev/drbd0;<br /> disk /dev/sdb1;<br /> address 192.168.0.243:7788;<br /> meta-disk internal;<br /> }<br /> }

Note:

The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).

Reference:

<br /> [root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/

  1. Initialize the meta-data area on disk before starting drbd (! on both server!)

drbdadm create-md r0

  • Start drbd on both nodes (service drbd start)

service drbd start

  • Verify that both server are secondary

cat /proc/drbd

  1. As you can see, both nodes are secondary, which is normal. we need to decide

which node will act as a primary now (voipserver.drbd) : that will initiate the first ‘full

sync’ between the two nodes:

drbdadm -- --overwrite-data-of-peer primary r0

  1. Launch the command and wait until it’s finish synchronizing

watch -n 1 cat /proc/drbd

  1. We can now format /dev/drbd0 and mount it on voipserver.drbd:

<br /> [root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br /> [root@voipSERVER.drbd /]# mkdir /replica</p> <p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica

  1. We can determine the role of a server by executing the following;

drbdadm role r0

The primary server should return;

Primary/Secondary

  1. Now we will copy all of the directories we want synchronized between the two

servers to our new partition, remove the original directories and then create

symbolic links to replace them on voipserver.drbd.

Note: If you use 64bit version of Elastix this line: tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/ should looks like ``As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:

Elastix 2.5 stable

Heartbeat for failover

Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:

Stability, Reliability, High-availability

Let`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.

I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

/dev/sda1 - /<br /> /dev/sda2 - swap<br /> /dev/sdb1 - /replica

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.

(By identical i meant compleatly identical start block and finish block must be same on both)

  1. When everything is installed, we need to create FS for /dev/sdb

[root@voipSERVER.drbd /]# fdisk /dev/sdb<br /> p<br /> n<br /> ----<br /> t - 83<br /> w

  1. Format :

[root@voipSERVER.drbd /]# mke2fs -j /dev/sdb1

  1. Just in case, we gonna formated with zeros:

[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync

  1. Installing drbd and heartbeat:

yum install heartbeat drbd83 kmod-drbd83

Note: If by any chance you experience problems with drbd83, use drbd82 version (64 bit

versions).

  1. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

192.168.0.242 voipserver.drbd<br /> 192.168.0.243 voipbackup.drbd

  1. Edit /etc/drbd.conf on the Primary one:

<br /> global { usage-count no; }<br /> resource r0 {<br /> protocol C;<br /> startup { wfc-timeout 10; degr-wfc-timeout 30; }<br /> disk { on-io-error detach; }<br /> net {<br /> after-sb-0pri discard-least-changes;<br /> after-sb-1pri discard-secondary;<br /> after-sb-2pri call-pri-lost-after-sb;<br /> cram-hmac-alg "sha1";<br /> shared-secret "SECRET PASSWD";<br /> }<br /> syncer { rate 5M; }<br /> on voipserver.drbd {<br /> device /dev/drbd0;<br /> disk /dev/sdb1;<br /> address 192.168.0.242:7788;<br /> meta-disk internal;<br /> }<br /> on voipbackup.drbd {<br /> device /dev/drbd0;<br /> disk /dev/sdb1;<br /> address 192.168.0.243:7788;<br /> meta-disk internal;<br /> }<br /> }

Note:

The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).

Reference:

<br /> [root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/

  1. Initialize the meta-data area on disk before starting drbd (! on both server!)

drbdadm create-md r0

  • Start drbd on both nodes (service drbd start)

service drbd start

  • Verify that both server are secondary

cat /proc/drbd

  1. As you can see, both nodes are secondary, which is normal. we need to decide

which node will act as a primary now (voipserver.drbd) : that will initiate the first ‘full

sync’ between the two nodes:

drbdadm -- --overwrite-data-of-peer primary r0

  1. Launch the command and wait until it’s finish synchronizing

watch -n 1 cat /proc/drbd

  1. We can now format /dev/drbd0 and mount it on voipserver.drbd:

<br /> [root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br /> [root@voipSERVER.drbd /]# mkdir /replica</p> <p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica

  1. We can determine the role of a server by executing the following;

drbdadm role r0

The primary server should return;

Primary/Secondary

  1. Now we will copy all of the directories we want synchronized between the two

servers to our new partition, remove the original directories and then create

symbolic links to replace them on voipserver.drbd.

Note: If you use 64bit version of Elastix this line: tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/ should looks like``

cd /replica</p> <p>amportal chown</p> <p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br /> tar -zxvf etc-asterisk.tgz<br /> tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br /> tar -zxvf var-lib-asterisk.tgz<br /> tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br /> tar -zxvf usr-lib-asterisk.tgz<br /> tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br /> tar -zxvf var-spool-asterisk.tgz<br /> tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br /> tar -zxvf var-lib-mysql.tgz<br /> tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br /> tar -zxvf var-log-asterisk.tgz<br /> tar -zcvf var-www.tgz /var/www/<br /> tar -zxvf var-www.tgz<br /> rm -rf /etc/asterisk<br /> rm -rf /var/lib/asterisk<br /> rm -rf /usr/lib/asterisk/<br /> rm -rf /var/spool/asterisk<br /> rm -rf /var/www</p> <p>rm -rf /var/lib/mysql/<br /> rm -rf /var/log/asterisk/<br /> ln -s /replica/etc/asterisk/ /etc/asterisk<br /> ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br /> ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br /> ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br /> ln -s /replica/var/lib/mysql/ /var/lib/mysql<br /> ln -s /replica/var/log/asterisk/ /var/log/asterisk<br /> ln -s /replica/var/www /var/www<br /> cd /

Stop mysqld, asterisk and httpd services on voipserver.drbd

service mysqld restart<br /> service mysqld stop<br /> service asterisk stop<br /> service httpd stop<br /> service elastix-updaterd stop<br /> service elastix-portknock stop

  1. Verify services are down and proceed to switch manually to the second server:

[root@voipSERVER.drbd /]# umount /replica ; drbdadm secondary r0

  1. Now switch to the VOIPBACKUP server

[root@voipBACKUP.drbd /]# mkdir /replica ; drbdadm primary r0 ; mount /dev/drbd0 /replica<br /> [root@voipBACKUP.drbd /]# ls /replica/

Note: This is used to check if you are replicating information on both servers. You should

see all data replicated in the secondary server just like data in the primary.

  • DO NOT perform this action with the physical terminal logged in. Use SSH. Otherwise, it will fail to

unmount the /replica folder for some reason! Also make sure you are not IN the replica folder. Type “cd /” .

  1. Verify voipserver.drbd status (Primary/Secondary)

drbdadm role r0

Note: Executing this same command in voipbackup.drbd while in secondary mode should

not display the /dev/drbd0 partition unless it’s assuming primary mode.

  1. Now we will remove and link on voipbackup.drbd

cd /replica</p> <p>amportal chown</p> <p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br /> tar -zxvf etc-asterisk.tgz<br /> tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br /> tar -zxvf var-lib-asterisk.tgz<br /> tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br /> tar -zxvf usr-lib-asterisk.tgz<br /> tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br /> tar -zxvf var-spool-asterisk.tgz<br /> tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br /> tar -zxvf var-lib-mysql.tgz<br /> tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br /> tar -zxvf var-log-asterisk.tgz<br /> tar -zcvf var-www.tgz /var/www/<br /> tar -zxvf var-www.tgz<br /> rm -rf /etc/asterisk<br /> rm -rf /var/lib/asterisk<br /> rm -rf /usr/lib/asterisk/<br /> rm -rf /var/spool/asterisk<br /> rm -rf /var/www</p> <p>rm -rf /var/lib/mysql/<br /> rm -rf /var/log/asterisk/<br /> ln -s /replica/etc/asterisk/ /etc/asterisk<br /> ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br /> ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br /> ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br /> ln -s /replica/var/lib/mysql/ /var/lib/mysql<br /> ln -s /replica/var/log/asterisk/ /var/log/asterisk<br /> ln -s /replica/var/www /var/www<br /> cd /

  1. Stop mysqld, asterisk and httpd services on voipserver.drbd

<br /> service mysqld restart<br /> service mysqld stop<br /> service asterisk stop<br /> service httpd stop<br /> service elastix-updaterd stop<br /> service elastix-portknock stop

  1. Now switch back to the first server:

[root@voipBACKUP.drbd /]# umount /replica/ ; drbdadm secondary r0

  1. Now switch to the VOIPSERVER server

[root@voipSERVER.drbd /]# drbdadm primary r0 ; mount /dev/drbd0 /replica

Drbd is working … let’s be sure that it will always be started:

chkconfig drbd on

  1. Remember to stop any boot up services on both servers that should be controlled by heartbeat. These services will be controlled by heartbeat on the server that is in control.

```As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:

Elastix 2.5 stable

Heartbeat for failover

Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:

Stability, Reliability, High-availability

Let`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.

I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

/dev/sda1 - /<br /> /dev/sda2 - swap<br /> /dev/sdb1 - /replica

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.

(By identical i meant compleatly identical start block and finish block must be same on both)

  1. When everything is installed, we need to create FS for /dev/sdb

[root@voipSERVER.drbd /]# fdisk /dev/sdb<br /> p<br /> n<br /> ----<br /> t - 83<br /> w

  1. Format :

[root@voipSERVER.drbd /]# mke2fs -j /dev/sdb1

  1. Just in case, we gonna formated with zeros:

[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync

  1. Installing drbd and heartbeat:

yum install heartbeat drbd83 kmod-drbd83

Note: If by any chance you experience problems with drbd83, use drbd82 version (64 bit

versions).

  1. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

192.168.0.242 voipserver.drbd<br /> 192.168.0.243 voipbackup.drbd

  1. Edit /etc/drbd.conf on the Primary one:

<br /> global { usage-count no; }<br /> resource r0 {<br /> protocol C;<br /> startup { wfc-timeout 10; degr-wfc-timeout 30; }<br /> disk { on-io-error detach; }<br /> net {<br /> after-sb-0pri discard-least-changes;<br /> after-sb-1pri discard-secondary;<br /> after-sb-2pri call-pri-lost-after-sb;<br /> cram-hmac-alg "sha1";<br /> shared-secret "SECRET PASSWD";<br /> }<br /> syncer { rate 5M; }<br /> on voipserver.drbd {<br /> device /dev/drbd0;<br /> disk /dev/sdb1;<br /> address 192.168.0.242:7788;<br /> meta-disk internal;<br /> }<br /> on voipbackup.drbd {<br /> device /dev/drbd0;<br /> disk /dev/sdb1;<br /> address 192.168.0.243:7788;<br /> meta-disk internal;<br /> }<br /> }

Note:

The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).

Reference:

<br /> [root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/

  1. Initialize the meta-data area on disk before starting drbd (! on both server!)

drbdadm create-md r0

  • Start drbd on both nodes (service drbd start)

service drbd start

  • Verify that both server are secondary

cat /proc/drbd

  1. As you can see, both nodes are secondary, which is normal. we need to decide

which node will act as a primary now (voipserver.drbd) : that will initiate the first ‘full

sync’ between the two nodes:

drbdadm -- --overwrite-data-of-peer primary r0

  1. Launch the command and wait until it’s finish synchronizing

watch -n 1 cat /proc/drbd

  1. We can now format /dev/drbd0 and mount it on voipserver.drbd:

<br /> [root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br /> [root@voipSERVER.drbd /]# mkdir /replica</p> <p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica

  1. We can determine the role of a server by executing the following;

drbdadm role r0

The primary server should return;

Primary/Secondary

  1. Now we will copy all of the directories we want synchronized between the two

servers to our new partition, remove the original directories and then create

symbolic links to replace them on voipserver.drbd.

Note: If you use 64bit version of Elastix this line: tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/ should looks like ``As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:

Elastix 2.5 stable

Heartbeat for failover

Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:

Stability, Reliability, High-availability

Let`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.

I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

/dev/sda1 - /<br /> /dev/sda2 - swap<br /> /dev/sdb1 - /replica

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.

(By identical i meant compleatly identical start block and finish block must be same on both)

  1. When everything is installed, we need to create FS for /dev/sdb

[root@voipSERVER.drbd /]# fdisk /dev/sdb<br /> p<br /> n<br /> ----<br /> t - 83<br /> w

  1. Format :

[root@voipSERVER.drbd /]# mke2fs -j /dev/sdb1

  1. Just in case, we gonna formated with zeros:

[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync

  1. Installing drbd and heartbeat:

yum install heartbeat drbd83 kmod-drbd83

Note: If by any chance you experience problems with drbd83, use drbd82 version (64 bit

versions).

  1. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

192.168.0.242 voipserver.drbd<br /> 192.168.0.243 voipbackup.drbd

  1. Edit /etc/drbd.conf on the Primary one:

<br /> global { usage-count no; }<br /> resource r0 {<br /> protocol C;<br /> startup { wfc-timeout 10; degr-wfc-timeout 30; }<br /> disk { on-io-error detach; }<br /> net {<br /> after-sb-0pri discard-least-changes;<br /> after-sb-1pri discard-secondary;<br /> after-sb-2pri call-pri-lost-after-sb;<br /> cram-hmac-alg "sha1";<br /> shared-secret "SECRET PASSWD";<br /> }<br /> syncer { rate 5M; }<br /> on voipserver.drbd {<br /> device /dev/drbd0;<br /> disk /dev/sdb1;<br /> address 192.168.0.242:7788;<br /> meta-disk internal;<br /> }<br /> on voipbackup.drbd {<br /> device /dev/drbd0;<br /> disk /dev/sdb1;<br /> address 192.168.0.243:7788;<br /> meta-disk internal;<br /> }<br /> }

Note:

The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).

Reference:

<br /> [root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/

  1. Initialize the meta-data area on disk before starting drbd (! on both server!)

drbdadm create-md r0

  • Start drbd on both nodes (service drbd start)

service drbd start

  • Verify that both server are secondary

cat /proc/drbd

  1. As you can see, both nodes are secondary, which is normal. we need to decide

which node will act as a primary now (voipserver.drbd) : that will initiate the first ‘full

sync’ between the two nodes:

drbdadm -- --overwrite-data-of-peer primary r0

  1. Launch the command and wait until it’s finish synchronizing

watch -n 1 cat /proc/drbd

  1. We can now format /dev/drbd0 and mount it on voipserver.drbd:

<br /> [root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br /> [root@voipSERVER.drbd /]# mkdir /replica</p> <p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica

  1. We can determine the role of a server by executing the following;

drbdadm role r0

The primary server should return;

Primary/Secondary

  1. Now we will copy all of the directories we want synchronized between the two

servers to our new partition, remove the original directories and then create

symbolic links to replace them on voipserver.drbd.

Note: If you use 64bit version of Elastix this line: tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/ should looks like``

cd /replica</p> <p>amportal chown</p> <p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br /> tar -zxvf etc-asterisk.tgz<br /> tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br /> tar -zxvf var-lib-asterisk.tgz<br /> tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br /> tar -zxvf usr-lib-asterisk.tgz<br /> tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br /> tar -zxvf var-spool-asterisk.tgz<br /> tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br /> tar -zxvf var-lib-mysql.tgz<br /> tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br /> tar -zxvf var-log-asterisk.tgz<br /> tar -zcvf var-www.tgz /var/www/<br /> tar -zxvf var-www.tgz<br /> rm -rf /etc/asterisk<br /> rm -rf /var/lib/asterisk<br /> rm -rf /usr/lib/asterisk/<br /> rm -rf /var/spool/asterisk<br /> rm -rf /var/www</p> <p>rm -rf /var/lib/mysql/<br /> rm -rf /var/log/asterisk/<br /> ln -s /replica/etc/asterisk/ /etc/asterisk<br /> ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br /> ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br /> ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br /> ln -s /replica/var/lib/mysql/ /var/lib/mysql<br /> ln -s /replica/var/log/asterisk/ /var/log/asterisk<br /> ln -s /replica/var/www /var/www<br /> cd /

Stop mysqld, asterisk and httpd services on voipserver.drbd

service mysqld restart<br /> service mysqld stop<br /> service asterisk stop<br /> service httpd stop<br /> service elastix-updaterd stop<br /> service elastix-portknock stop

  1. Verify services are down and proceed to switch manually to the second server:

[root@voipSERVER.drbd /]# umount /replica ; drbdadm secondary r0

  1. Now switch to the VOIPBACKUP server

[root@voipBACKUP.drbd /]# mkdir /replica ; drbdadm primary r0 ; mount /dev/drbd0 /replica<br /> [root@voipBACKUP.drbd /]# ls /replica/

Note: This is used to check if you are replicating information on both servers. You should

see all data replicated in the secondary server just like data in the primary.

  • DO NOT perform this action with the physical terminal logged in. Use SSH. Otherwise, it will fail to

unmount the /replica folder for some reason! Also make sure you are not IN the replica folder. Type “cd /” .

  1. Verify voipserver.drbd status (Primary/Secondary)

drbdadm role r0

Note: Executing this same command in voipbackup.drbd while in secondary mode should

not display the /dev/drbd0 partition unless it’s assuming primary mode.

  1. Now we will remove and link on voipbackup.drbd

cd /replica</p> <p>amportal chown</p> <p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br /> tar -zxvf etc-asterisk.tgz<br /> tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br /> tar -zxvf var-lib-asterisk.tgz<br /> tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br /> tar -zxvf usr-lib-asterisk.tgz<br /> tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br /> tar -zxvf var-spool-asterisk.tgz<br /> tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br /> tar -zxvf var-lib-mysql.tgz<br /> tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br /> tar -zxvf var-log-asterisk.tgz<br /> tar -zcvf var-www.tgz /var/www/<br /> tar -zxvf var-www.tgz<br /> rm -rf /etc/asterisk<br /> rm -rf /var/lib/asterisk<br /> rm -rf /usr/lib/asterisk/<br /> rm -rf /var/spool/asterisk<br /> rm -rf /var/www</p> <p>rm -rf /var/lib/mysql/<br /> rm -rf /var/log/asterisk/<br /> ln -s /replica/etc/asterisk/ /etc/asterisk<br /> ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br /> ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br /> ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br /> ln -s /replica/var/lib/mysql/ /var/lib/mysql<br /> ln -s /replica/var/log/asterisk/ /var/log/asterisk<br /> ln -s /replica/var/www /var/www<br /> cd /

  1. Stop mysqld, asterisk and httpd services on voipserver.drbd

<br /> service mysqld restart<br /> service mysqld stop<br /> service asterisk stop<br /> service httpd stop<br /> service elastix-updaterd stop<br /> service elastix-portknock stop

  1. Now switch back to the first server:

[root@voipBACKUP.drbd /]# umount /replica/ ; drbdadm secondary r0

  1. Now switch to the VOIPSERVER server

[root@voipSERVER.drbd /]# drbdadm primary r0 ; mount /dev/drbd0 /replica

Drbd is working … let’s be sure that it will always be started:

chkconfig drbd on

  1. Remember to stop any boot up services on both servers that should be controlled by heartbeat. These services will be controlled by heartbeat on the server that is in control.
22. Let’s configure a simple /etc/ha.d/ha.cf file on voipserver.drbd :

````As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like ``As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like`` 

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

Stop mysqld, asterisk and httpd services on voipserver.drbd

`service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

14. Verify services are down and proceed to switch manually to the second server:

[root@voipSERVER.drbd /]# umount /replica ; drbdadm secondary r0

15. Now switch to the VOIPBACKUP server

`[root@voipBACKUP.drbd /]# mkdir /replica ; drbdadm primary r0 ; mount /dev/drbd0 /replica<br />
[root@voipBACKUP.drbd /]# ls /replica/`

Note: This is used to check if you are replicating information on both servers. You should
  
see all data replicated in the secondary server just like data in the primary.
  
* DO NOT perform this action with the physical terminal logged in. Use SSH. Otherwise, it will fail to
  
unmount the /replica folder for some reason! Also make sure you are not IN the replica folder. Type β€œcd /” .

16. Verify voipserver.drbd status (Primary/Secondary)

drbdadm role r0

**Note:** Executing this same command in voipbackup.drbd while in secondary mode should
  
not display the /dev/drbd0 partition unless it’s assuming primary mode.

17. Now we will remove and link on voipbackup.drbd

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

18. Stop mysqld, asterisk and httpd services on voipserver.drbd
  
`<br />
service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

19. Now switch back to the first server:
  
`[root@voipBACKUP.drbd /]# umount /replica/ ; drbdadm secondary r0`

20. Now switch to the VOIPSERVER server

[root@voipSERVER.drbd /]# drbdadm primary r0 ; mount /dev/drbd0 /replica

Drbd is working … let’s be sure that it will always be started:
  
`chkconfig drbd on`

21. Remember to stop any boot up services on both servers that should be controlled by heartbeat. These services will be controlled by heartbeat on the server that is in control.

```As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like ``As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like`` 

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

Stop mysqld, asterisk and httpd services on voipserver.drbd

`service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

14. Verify services are down and proceed to switch manually to the second server:

[root@voipSERVER.drbd /]# umount /replica ; drbdadm secondary r0

15. Now switch to the VOIPBACKUP server

`[root@voipBACKUP.drbd /]# mkdir /replica ; drbdadm primary r0 ; mount /dev/drbd0 /replica<br />
[root@voipBACKUP.drbd /]# ls /replica/`

Note: This is used to check if you are replicating information on both servers. You should
  
see all data replicated in the secondary server just like data in the primary.
  
* DO NOT perform this action with the physical terminal logged in. Use SSH. Otherwise, it will fail to
  
unmount the /replica folder for some reason! Also make sure you are not IN the replica folder. Type β€œcd /” .

16. Verify voipserver.drbd status (Primary/Secondary)

drbdadm role r0

**Note:** Executing this same command in voipbackup.drbd while in secondary mode should
  
not display the /dev/drbd0 partition unless it’s assuming primary mode.

17. Now we will remove and link on voipbackup.drbd

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

18. Stop mysqld, asterisk and httpd services on voipserver.drbd
  
`<br />
service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

19. Now switch back to the first server:
  
`[root@voipBACKUP.drbd /]# umount /replica/ ; drbdadm secondary r0`

20. Now switch to the VOIPSERVER server

[root@voipSERVER.drbd /]# drbdadm primary r0 ; mount /dev/drbd0 /replica

Drbd is working … let’s be sure that it will always be started:
  
`chkconfig drbd on`

21. Remember to stop any boot up services on both servers that should be controlled by heartbeat. These services will be controlled by heartbeat on the server that is in control.
  1. Let’s configure a simple /etc/ha.d/ha.cf file on voipserver.drbd :
23. Create also the /etc/ha.d/authkeys on voipserver.drbd:

`````As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like ``As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like`` 

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

Stop mysqld, asterisk and httpd services on voipserver.drbd

`service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

14. Verify services are down and proceed to switch manually to the second server:

[root@voipSERVER.drbd /]# umount /replica ; drbdadm secondary r0

15. Now switch to the VOIPBACKUP server

`[root@voipBACKUP.drbd /]# mkdir /replica ; drbdadm primary r0 ; mount /dev/drbd0 /replica<br />
[root@voipBACKUP.drbd /]# ls /replica/`

Note: This is used to check if you are replicating information on both servers. You should
  
see all data replicated in the secondary server just like data in the primary.
  
* DO NOT perform this action with the physical terminal logged in. Use SSH. Otherwise, it will fail to
  
unmount the /replica folder for some reason! Also make sure you are not IN the replica folder. Type β€œcd /” .

16. Verify voipserver.drbd status (Primary/Secondary)

drbdadm role r0

**Note:** Executing this same command in voipbackup.drbd while in secondary mode should
  
not display the /dev/drbd0 partition unless it’s assuming primary mode.

17. Now we will remove and link on voipbackup.drbd

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

18. Stop mysqld, asterisk and httpd services on voipserver.drbd
  
`<br />
service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

19. Now switch back to the first server:
  
`[root@voipBACKUP.drbd /]# umount /replica/ ; drbdadm secondary r0`

20. Now switch to the VOIPSERVER server

[root@voipSERVER.drbd /]# drbdadm primary r0 ; mount /dev/drbd0 /replica

Drbd is working … let’s be sure that it will always be started:
  
`chkconfig drbd on`

21. Remember to stop any boot up services on both servers that should be controlled by heartbeat. These services will be controlled by heartbeat on the server that is in control.

```As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like ``As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like`` 

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

Stop mysqld, asterisk and httpd services on voipserver.drbd

`service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

14. Verify services are down and proceed to switch manually to the second server:

[root@voipSERVER.drbd /]# umount /replica ; drbdadm secondary r0

15. Now switch to the VOIPBACKUP server

`[root@voipBACKUP.drbd /]# mkdir /replica ; drbdadm primary r0 ; mount /dev/drbd0 /replica<br />
[root@voipBACKUP.drbd /]# ls /replica/`

Note: This is used to check if you are replicating information on both servers. You should
  
see all data replicated in the secondary server just like data in the primary.
  
* DO NOT perform this action with the physical terminal logged in. Use SSH. Otherwise, it will fail to
  
unmount the /replica folder for some reason! Also make sure you are not IN the replica folder. Type β€œcd /” .

16. Verify voipserver.drbd status (Primary/Secondary)

drbdadm role r0

**Note:** Executing this same command in voipbackup.drbd while in secondary mode should
  
not display the /dev/drbd0 partition unless it’s assuming primary mode.

17. Now we will remove and link on voipbackup.drbd

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

18. Stop mysqld, asterisk and httpd services on voipserver.drbd
  
`<br />
service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

19. Now switch back to the first server:
  
`[root@voipBACKUP.drbd /]# umount /replica/ ; drbdadm secondary r0`

20. Now switch to the VOIPSERVER server

[root@voipSERVER.drbd /]# drbdadm primary r0 ; mount /dev/drbd0 /replica

Drbd is working … let’s be sure that it will always be started:
  
`chkconfig drbd on`

21. Remember to stop any boot up services on both servers that should be controlled by heartbeat. These services will be controlled by heartbeat on the server that is in control.

``` 

22. Let’s configure a simple /etc/ha.d/ha.cf file on voipserver.drbd :

````As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like ``As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like`` 

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

Stop mysqld, asterisk and httpd services on voipserver.drbd

`service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

14. Verify services are down and proceed to switch manually to the second server:

[root@voipSERVER.drbd /]# umount /replica ; drbdadm secondary r0

15. Now switch to the VOIPBACKUP server

`[root@voipBACKUP.drbd /]# mkdir /replica ; drbdadm primary r0 ; mount /dev/drbd0 /replica<br />
[root@voipBACKUP.drbd /]# ls /replica/`

Note: This is used to check if you are replicating information on both servers. You should
  
see all data replicated in the secondary server just like data in the primary.
  
* DO NOT perform this action with the physical terminal logged in. Use SSH. Otherwise, it will fail to
  
unmount the /replica folder for some reason! Also make sure you are not IN the replica folder. Type β€œcd /” .

16. Verify voipserver.drbd status (Primary/Secondary)

drbdadm role r0

**Note:** Executing this same command in voipbackup.drbd while in secondary mode should
  
not display the /dev/drbd0 partition unless it’s assuming primary mode.

17. Now we will remove and link on voipbackup.drbd

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

18. Stop mysqld, asterisk and httpd services on voipserver.drbd
  
`<br />
service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

19. Now switch back to the first server:
  
`[root@voipBACKUP.drbd /]# umount /replica/ ; drbdadm secondary r0`

20. Now switch to the VOIPSERVER server

[root@voipSERVER.drbd /]# drbdadm primary r0 ; mount /dev/drbd0 /replica

Drbd is working … let’s be sure that it will always be started:
  
`chkconfig drbd on`

21. Remember to stop any boot up services on both servers that should be controlled by heartbeat. These services will be controlled by heartbeat on the server that is in control.

```As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like ``As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like`` 

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

Stop mysqld, asterisk and httpd services on voipserver.drbd

`service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

14. Verify services are down and proceed to switch manually to the second server:

[root@voipSERVER.drbd /]# umount /replica ; drbdadm secondary r0

15. Now switch to the VOIPBACKUP server

`[root@voipBACKUP.drbd /]# mkdir /replica ; drbdadm primary r0 ; mount /dev/drbd0 /replica<br />
[root@voipBACKUP.drbd /]# ls /replica/`

Note: This is used to check if you are replicating information on both servers. You should
  
see all data replicated in the secondary server just like data in the primary.
  
* DO NOT perform this action with the physical terminal logged in. Use SSH. Otherwise, it will fail to
  
unmount the /replica folder for some reason! Also make sure you are not IN the replica folder. Type β€œcd /” .

16. Verify voipserver.drbd status (Primary/Secondary)

drbdadm role r0

**Note:** Executing this same command in voipbackup.drbd while in secondary mode should
  
not display the /dev/drbd0 partition unless it’s assuming primary mode.

17. Now we will remove and link on voipbackup.drbd

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

18. Stop mysqld, asterisk and httpd services on voipserver.drbd
  
`<br />
service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

19. Now switch back to the first server:
  
`[root@voipBACKUP.drbd /]# umount /replica/ ; drbdadm secondary r0`

20. Now switch to the VOIPSERVER server

[root@voipSERVER.drbd /]# drbdadm primary r0 ; mount /dev/drbd0 /replica

Drbd is working … let’s be sure that it will always be started:
  
`chkconfig drbd on`

21. Remember to stop any boot up services on both servers that should be controlled by heartbeat. These services will be controlled by heartbeat on the server that is in control.

``` 

22. Let’s configure a simple /etc/ha.d/ha.cf file on voipserver.drbd :
  1. Create also the /etc/ha.d/authkeys on voipserver.drbd:
24. Change permissions on the /etc/ha.d/authkeys file on voipserver.drbd:
  
`chmod 600 /etc/ha.d/authkeys`

25. Edit /etc/ha.d/haresources on voipserver.drbd: (It is two lines!!!!!!! Formating is
  
important). Replace the email addresses with your own, on the second line.

`voipserver.drbd drbddisk::r0 Filesystem::/dev/drbd0::/replica::ext3 IPaddr::192.168.0.244/24/eth0/192.168.0.255 mysqld asterisk httpd elastix-updaterd elastix-portknock fop_start<br />
voipserver.drbd MailTo::hristo@computerassistance.uk.com::DRBD/HA-ALERT<br />
voipserver.drbd IPaddr::192.168.0.245/24/eth1/192.168.0.255`

Note: If you have second NIC, and you want to failover it, just add it here, like I did, the last line. Now this IP which you’ve set up will be floating between both servers. 

26. Start the heartbeat service on voipserver.drbd :
  
`service heartbeat start`

27. Replicate now the ha.cf, authkeys and haresources to voipbackup.drbd and start heartbeat

`[root@voipserver.drbd ha.d]# scp /etc/ha.d/ha.cf /etc/ha.d/authkeys /etc/ha.d/haresources<br />
root@voipbackup.drbd:/etc/ha.d/<br />
[root@svoipbackup.drbd ha.d]# service heartbeat start`

28. Configure heartbeat to initialize at boot on both server

``````As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like ``As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like`` 

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

Stop mysqld, asterisk and httpd services on voipserver.drbd

`service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

14. Verify services are down and proceed to switch manually to the second server:

[root@voipSERVER.drbd /]# umount /replica ; drbdadm secondary r0

15. Now switch to the VOIPBACKUP server

`[root@voipBACKUP.drbd /]# mkdir /replica ; drbdadm primary r0 ; mount /dev/drbd0 /replica<br />
[root@voipBACKUP.drbd /]# ls /replica/`

Note: This is used to check if you are replicating information on both servers. You should
  
see all data replicated in the secondary server just like data in the primary.
  
* DO NOT perform this action with the physical terminal logged in. Use SSH. Otherwise, it will fail to
  
unmount the /replica folder for some reason! Also make sure you are not IN the replica folder. Type β€œcd /” .

16. Verify voipserver.drbd status (Primary/Secondary)

drbdadm role r0

**Note:** Executing this same command in voipbackup.drbd while in secondary mode should
  
not display the /dev/drbd0 partition unless it’s assuming primary mode.

17. Now we will remove and link on voipbackup.drbd

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

18. Stop mysqld, asterisk and httpd services on voipserver.drbd
  
`<br />
service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

19. Now switch back to the first server:
  
`[root@voipBACKUP.drbd /]# umount /replica/ ; drbdadm secondary r0`

20. Now switch to the VOIPSERVER server

[root@voipSERVER.drbd /]# drbdadm primary r0 ; mount /dev/drbd0 /replica

Drbd is working … let’s be sure that it will always be started:
  
`chkconfig drbd on`

21. Remember to stop any boot up services on both servers that should be controlled by heartbeat. These services will be controlled by heartbeat on the server that is in control.

```As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like ``As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like`` 

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

Stop mysqld, asterisk and httpd services on voipserver.drbd

`service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

14. Verify services are down and proceed to switch manually to the second server:

[root@voipSERVER.drbd /]# umount /replica ; drbdadm secondary r0

15. Now switch to the VOIPBACKUP server

`[root@voipBACKUP.drbd /]# mkdir /replica ; drbdadm primary r0 ; mount /dev/drbd0 /replica<br />
[root@voipBACKUP.drbd /]# ls /replica/`

Note: This is used to check if you are replicating information on both servers. You should
  
see all data replicated in the secondary server just like data in the primary.
  
* DO NOT perform this action with the physical terminal logged in. Use SSH. Otherwise, it will fail to
  
unmount the /replica folder for some reason! Also make sure you are not IN the replica folder. Type β€œcd /” .

16. Verify voipserver.drbd status (Primary/Secondary)

drbdadm role r0

**Note:** Executing this same command in voipbackup.drbd while in secondary mode should
  
not display the /dev/drbd0 partition unless it’s assuming primary mode.

17. Now we will remove and link on voipbackup.drbd

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

18. Stop mysqld, asterisk and httpd services on voipserver.drbd
  
`<br />
service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

19. Now switch back to the first server:
  
`[root@voipBACKUP.drbd /]# umount /replica/ ; drbdadm secondary r0`

20. Now switch to the VOIPSERVER server

[root@voipSERVER.drbd /]# drbdadm primary r0 ; mount /dev/drbd0 /replica

Drbd is working … let’s be sure that it will always be started:
  
`chkconfig drbd on`

21. Remember to stop any boot up services on both servers that should be controlled by heartbeat. These services will be controlled by heartbeat on the server that is in control.

``` 

22. Let’s configure a simple /etc/ha.d/ha.cf file on voipserver.drbd :

````As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like ``As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like`` 

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

Stop mysqld, asterisk and httpd services on voipserver.drbd

`service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

14. Verify services are down and proceed to switch manually to the second server:

[root@voipSERVER.drbd /]# umount /replica ; drbdadm secondary r0

15. Now switch to the VOIPBACKUP server

`[root@voipBACKUP.drbd /]# mkdir /replica ; drbdadm primary r0 ; mount /dev/drbd0 /replica<br />
[root@voipBACKUP.drbd /]# ls /replica/`

Note: This is used to check if you are replicating information on both servers. You should
  
see all data replicated in the secondary server just like data in the primary.
  
* DO NOT perform this action with the physical terminal logged in. Use SSH. Otherwise, it will fail to
  
unmount the /replica folder for some reason! Also make sure you are not IN the replica folder. Type β€œcd /” .

16. Verify voipserver.drbd status (Primary/Secondary)

drbdadm role r0

**Note:** Executing this same command in voipbackup.drbd while in secondary mode should
  
not display the /dev/drbd0 partition unless it’s assuming primary mode.

17. Now we will remove and link on voipbackup.drbd

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

18. Stop mysqld, asterisk and httpd services on voipserver.drbd
  
`<br />
service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

19. Now switch back to the first server:
  
`[root@voipBACKUP.drbd /]# umount /replica/ ; drbdadm secondary r0`

20. Now switch to the VOIPSERVER server

[root@voipSERVER.drbd /]# drbdadm primary r0 ; mount /dev/drbd0 /replica

Drbd is working … let’s be sure that it will always be started:
  
`chkconfig drbd on`

21. Remember to stop any boot up services on both servers that should be controlled by heartbeat. These services will be controlled by heartbeat on the server that is in control.

```As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like ``As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like`` 

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

Stop mysqld, asterisk and httpd services on voipserver.drbd

`service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

14. Verify services are down and proceed to switch manually to the second server:

[root@voipSERVER.drbd /]# umount /replica ; drbdadm secondary r0

15. Now switch to the VOIPBACKUP server

`[root@voipBACKUP.drbd /]# mkdir /replica ; drbdadm primary r0 ; mount /dev/drbd0 /replica<br />
[root@voipBACKUP.drbd /]# ls /replica/`

Note: This is used to check if you are replicating information on both servers. You should
  
see all data replicated in the secondary server just like data in the primary.
  
* DO NOT perform this action with the physical terminal logged in. Use SSH. Otherwise, it will fail to
  
unmount the /replica folder for some reason! Also make sure you are not IN the replica folder. Type β€œcd /” .

16. Verify voipserver.drbd status (Primary/Secondary)

drbdadm role r0

**Note:** Executing this same command in voipbackup.drbd while in secondary mode should
  
not display the /dev/drbd0 partition unless it’s assuming primary mode.

17. Now we will remove and link on voipbackup.drbd

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

18. Stop mysqld, asterisk and httpd services on voipserver.drbd
  
`<br />
service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

19. Now switch back to the first server:
  
`[root@voipBACKUP.drbd /]# umount /replica/ ; drbdadm secondary r0`

20. Now switch to the VOIPSERVER server

[root@voipSERVER.drbd /]# drbdadm primary r0 ; mount /dev/drbd0 /replica

Drbd is working … let’s be sure that it will always be started:
  
`chkconfig drbd on`

21. Remember to stop any boot up services on both servers that should be controlled by heartbeat. These services will be controlled by heartbeat on the server that is in control.

``` 

22. Let’s configure a simple /etc/ha.d/ha.cf file on voipserver.drbd :

```` 

23. Create also the /etc/ha.d/authkeys on voipserver.drbd:

`````As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like ``As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like`` 

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

Stop mysqld, asterisk and httpd services on voipserver.drbd

`service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

14. Verify services are down and proceed to switch manually to the second server:

[root@voipSERVER.drbd /]# umount /replica ; drbdadm secondary r0

15. Now switch to the VOIPBACKUP server

`[root@voipBACKUP.drbd /]# mkdir /replica ; drbdadm primary r0 ; mount /dev/drbd0 /replica<br />
[root@voipBACKUP.drbd /]# ls /replica/`

Note: This is used to check if you are replicating information on both servers. You should
  
see all data replicated in the secondary server just like data in the primary.
  
* DO NOT perform this action with the physical terminal logged in. Use SSH. Otherwise, it will fail to
  
unmount the /replica folder for some reason! Also make sure you are not IN the replica folder. Type β€œcd /” .

16. Verify voipserver.drbd status (Primary/Secondary)

drbdadm role r0

**Note:** Executing this same command in voipbackup.drbd while in secondary mode should
  
not display the /dev/drbd0 partition unless it’s assuming primary mode.

17. Now we will remove and link on voipbackup.drbd

`cd /replica</p>
<p>amportal chown</p>
<p>tar -zcvf etc-asterisk.tgz /etc/asterisk<br />
tar -zxvf etc-asterisk.tgz<br />
tar -zcvf var-lib-asterisk.tgz /var/lib/asterisk<br />
tar -zxvf var-lib-asterisk.tgz<br />
tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/<br />
tar -zxvf usr-lib-asterisk.tgz<br />
tar -zcvf var-spool-asterisk.tgz /var/spool/asterisk/<br />
tar -zxvf var-spool-asterisk.tgz<br />
tar -zcvf var-lib-mysql.tgz /var/lib/mysql/<br />
tar -zxvf var-lib-mysql.tgz<br />
tar -zcvf var-log-asterisk.tgz /var/log/asterisk/<br />
tar -zxvf var-log-asterisk.tgz<br />
tar -zcvf var-www.tgz /var/www/<br />
tar -zxvf var-www.tgz<br />
rm -rf /etc/asterisk<br />
rm -rf /var/lib/asterisk<br />
rm -rf /usr/lib/asterisk/<br />
rm -rf /var/spool/asterisk<br />
rm -rf /var/www</p>
<p>rm -rf /var/lib/mysql/<br />
rm -rf /var/log/asterisk/<br />
ln -s /replica/etc/asterisk/ /etc/asterisk<br />
ln -s /replica/var/lib/asterisk/ /var/lib/asterisk<br />
ln -s /replica/usr/lib/asterisk/ /usr/lib/asterisk<br />
ln -s /replica/var/spool/asterisk/ /var/spool/asterisk<br />
ln -s /replica/var/lib/mysql/ /var/lib/mysql<br />
ln -s /replica/var/log/asterisk/ /var/log/asterisk<br />
ln -s /replica/var/www /var/www<br />
cd /`

18. Stop mysqld, asterisk and httpd services on voipserver.drbd
  
`<br />
service mysqld restart<br />
service mysqld stop<br />
service asterisk stop<br />
service httpd stop<br />
service elastix-updaterd stop<br />
service elastix-portknock stop`

19. Now switch back to the first server:
  
`[root@voipBACKUP.drbd /]# umount /replica/ ; drbdadm secondary r0`

20. Now switch to the VOIPSERVER server

[root@voipSERVER.drbd /]# drbdadm primary r0 ; mount /dev/drbd0 /replica

Drbd is working … let’s be sure that it will always be started:
  
`chkconfig drbd on`

21. Remember to stop any boot up services on both servers that should be controlled by heartbeat. These services will be controlled by heartbeat on the server that is in control.

```As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are in primary mode and need to know how to resolve who should assume primary/secondary role (discarding or accepting changes made in primaries).
  
Reference: 

  * http://www.drbd.org/users-guide/s-configure-split-brain-behavior.html
7. Replicate this config file to the second server
  
`<br />
[root@voipSERVER.drbd /]# scp /etc/drbd.conf root@voipbackup.drbd:/etc/`

8. Initialize the meta-data area on disk before starting drbd (! on both server!)

`drbdadm create-md r0`

* Start drbd on both nodes (service drbd start)

`service drbd start`

* Verify that both server are secondary 

`cat /proc/drbd`

9. As you can see, both nodes are secondary, which is normal. we need to decide
  
which node will act as a primary now (voipserver.drbd) : that will initiate the first β€˜full
  
sync’ between the two nodes:

`drbdadm -- --overwrite-data-of-peer primary r0`

10. Launch the command and wait until it’s finish synchronizing

`watch -n 1 cat /proc/drbd`

11. We can now format /dev/drbd0 and mount it on voipserver.drbd:
  
`<br />
[root@voipSERVER.drbd /]# mkfs.ext3 /dev/drbd0<br />
[root@voipSERVER.drbd /]# mkdir /replica</p>
<p>[root@voipSERVER.drbd /]# mount /dev/drbd0 /replica`

12. We can determine the role of a server by executing the following;
  
drbdadm role r0
  
The primary server should return;

`Primary/Secondary` 

13. Now we will copy all of the directories we want synchronized between the two
  
servers to our new partition, remove the original directories and then create
  
symbolic links to replace them on voipserver.drbd.
  
**Note:** If you use 64bit version of Elastix this line: `tar -zcvf usr-lib-asterisk.tgz /usr/lib/asterisk/` should looks like ``As some of you knows I’ve got so much luck that even in my ne job they want new Telefon system πŸ™‚ But massive one with failover and -20 sec downtime.

So what we’ve got:
  
Elastix 2.5 stable
  
Heartbeat for failover
  
Drbd – Network mirror raid, on which are all Elastix and asterig confs etc.

Our goals:
  
Stability, Reliability, High-availability 

Let\`s fucking do this shit!

I test it with 2 virtual elastix servers with attached 8 gig hdd on both, whitch I used for networ mirroring.
  
I followed THE TUTORIAL, the one tutorial for elastix HA+drbd.

`/dev/sda1 - /<br />
/dev/sda2 - swap<br />
/dev/sdb1  - /replica`

!!!Remember, these partition MUST be identical on both PCs, especially /dev/sdb1, where our Elasterix live.
  
(By identical i meant compleatly identical start block and finish block must be same on both)

1. When everything is installed, we need to create FS for /dev/sdb

`[root@voipSERVER.drbd /]# fdisk /dev/sdb<br />
p<br />
n<br />
----<br />
t - 83<br />
w`

2. Format : 

`[root@voipSERVER.drbd /]#  mke2fs -j /dev/sdb1` 

3. Just in case, we gonna formated with zeros:

`[root@voipSERVER.drbd /]# dd if=/dev/zero bs=1M count=500 of=/dev/sdb1; sync`

4. Installing drbd and heartbeat:

`yum install heartbeat drbd83 kmod-drbd83`

**Note:** If by any chance you experience problems with drbd83, use drbd82 version (64 bit
  
versions). 

5. Now we need to edit /etc/hosts to be sure that the IP name resolution will be ok

`192.168.0.242 voipserver.drbd<br />
192.168.0.243 voipbackup.drbd`

6. Edit /etc/drbd.conf on the Primary one:
  
`<br />
global { usage-count no; }<br />
resource r0 {<br />
protocol C;<br />
startup { wfc-timeout 10; degr-wfc-timeout 30; }<br />
disk { on-io-error detach; }<br />
net {<br />
after-sb-0pri discard-least-changes;<br />
after-sb-1pri discard-secondary;<br />
after-sb-2pri call-pri-lost-after-sb;<br />
cram-hmac-alg "sha1";<br />
shared-secret "SECRET PASSWD";<br />
}<br />
syncer { rate 5M; }<br />
on voipserver.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.242:7788;<br />
meta-disk internal;<br />
}<br />
on voipbackup.drbd {<br />
device /dev/drbd0;<br />
disk /dev/sdb1;<br />
address 192.168.0.243:7788;<br />
meta-disk internal;<br />
}<br />
}`

 **Note:**
  
The following lines are used to help the servers resolve split brain recovery. Split brain is when two servers are