Skip to content

VitalPBX/vitalpbx4_drbd_ha

Repository files navigation

VitalPBX High Availability with DRBD (Version 4)

High Availability with DRBD (Distributed Replicated Block Device) is a popular solution for achieving data redundancy and fault tolerance in a clustered environment. DRBD is a distributed storage system that synchronously replicates data between two or more nodes in real-time. It ensures that data is consistent across all nodes, providing continuous access to critical data even in the event of a node failure.

Make a high-availability cluster out of any pair of VitalPBX servers. VitalPBX can detect a range of failures on one VitalPBX server and automatically transfer control to the other server, resulting in a telephony environment with minimal down time.

⚠️Important notes:

  • At the time of installation leave the largest amount of space on the hard drive to store the variable data on both servers.

  • If you are going to restore some Backup from another server that is not in HA, restore it first in the Master server before creating the HA. This should be done as the backup does not contain the firewall rules for HA to work.

  • The VitalPBX team does not provide support for systems in an HA environment because it is not possible to determine the environment where it has been installed.

  • We recommend that Server 2 is completely clean if nothing is installed, otherwise the Script could give errors and the process would not be completed.

  • Example:

VitalPBX HA

Prerequisites

In order to install VitalPBX in high availability you need the following:
a.- 3 IP addresses.
b.- Install VitalPBX Version 4.0 in two servers with similar characteristics.
c.- DRBD, Corosync, Pacemaker and PCS.
d.- Root user is required for both servers to communicate.
e.- Both servers will not be able to have a proxy since this affects the communication between them.

Configurations

We will configure in each server the hosname and IP address.

Name Master Standby
Hostname vitalpbx-master.local vitalpbx-salve.local
IP Address 192.168.10.31 192.168.10.32
Netmask 255.255.255.0 255.255.255.0
Gateway 192.168.10.1 192.168.10.1
Primary DNS 8.8.8.8 8.8.8.8
Secondary DNS 8.8.4.4 8.8.4.4

Server 1

Change Hostname

root@vitalpbx:~# hostname vitalpbx-master.local

Change Ip Address, edit the following file with nano, /etc/network/interfaces

root@vitalpbx-master:~# nano /etc/network/interfaces

Change
#The primary network interface
allow-hotplug eth0
iface eth0 inet dchp

With the following
#The primary network interface
allow-hotplug eth0
iface eth0 inet static
address 192.168.10.31
netmask 255.255.255.0
gateway 192.168.10.1

Server 2

Change Hostname

root@vitalpbx:~# hostname vitalpbx-slave.local

Change Ip Address, edit the following file with nano, /etc/network/interfaces

root@vitalpbx-slave:~# nano /etc/network/interfaces

Change
#The primary network interface
allow-hotplug eth0
iface eth0 inet dchp

With the following
#The primary network interface
allow-hotplug eth0
iface eth0 inet static
address 192.168.10.32
netmask 255.255.255.0
gateway 192.168.10.1

Hostname

Configure the hostname of each server in the /etc/hosts file, so that both servers see each other with the hostname.

root@vitalpbx-master-slave:~# nano /etc/hosts
192.168.10.31 vitalpbx-master.local
192.168.10.32 vitalpbx-slave.local

Bind Address

In the Master server go to SETTINGS/PJSIP Settings and configure the Floating IP that we are going to use in "Bind" and "TLS Bind". Also do it in SETTINGS/SIP Settings Tab NETWORK fields "TCP Bind Address" and "TLS Bind Address".

Install Dependencies

Install the necessary dependencies on both servers

root@vitalpbx-master-slave:~# apt -y install drbd-utils corosync pacemaker pcs chrony xfsprogs

Create the partition on both servers

Initialize the partition to allocate the available space on the hard disk. Do these on both servers.

root@vitalpbx-master-slave:~# fdisk /dev/sda
Command (m for help): n
Partition type:
  p   primary (3 primary, 0 extended, 1 free)
  e   extended
Select (default e): p
Selected partition 3 (take note of the assigned partition number as we will need it later)
First sector (35155968-266338303, default 35155968): [Enter]
Last sector, +sectors or +size{K,M,G} (35155968-266338303, default 266338303): [Enter]
Using default value 266338303
Partition 4 of type Linux and of size 110.2 GiB is set
Command (m for help): t
Partition number (1-4, default 4): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w

Then, restart the servers so that the new table is available.

root@vitalpbx-master-slave:~# reboot

Create authorization key for the Access between the two servers without credentials

Create key in Server Master

root@vitalpbx-master:~# ssh-keygen -f /root/.ssh/id_rsa -t rsa -N '' >/dev/null
root@vitalpbx-master:~# ssh-copy-id root@192.168.10.32
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
root@192.168.10.62's password: (remote server root’s password)

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.10.32'"
and check to make sure that only the key(s) you wanted were added. 

root@vitalpbx-master:~#

Create key in Server Slave

root@vitalpbx-slave:~# ssh-keygen -f /root/.ssh/id_rsa -t rsa -N '' >/dev/null
root@vitalpbx-slave:~# ssh-copy-id root@192.168.10.31
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
root@192.168.10.61's password: (remote server root’s password)

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.10.31'"
and check to make sure that only the key(s) you wanted were added. 

root@vitalpbx-slave:~#

Script

Now copy and run the following script

root@vitalpbx-master:~# mkdir /usr/share/vitalpbx/ha
root@vitalpbx-master:~# cd /usr/share/vitalpbx/ha
root@vitalpbx-master:~# wget https://github.com/VitalPBX/vitalpbx4_drbd_ha/main/vpbxha.sh
root@vitalpbx-master:~# chmod +x vpbxha.sh
root@vitalpbx-master:~# ./vpbxha.sh
************************************************************
*  Welcome to the VitalPBX high availability installation  *
*                All options are mandatory                 *
************************************************************
IP Server1............... > 192.168.10.31
IP Server2............... > 192.168.10.32
Floating IP.............. > 192.168.10.30
Floating IP Mask (SIDR).. > 24
Disk (sdax).............. > sda3
hacluster password....... > MyPassword
************************************************************
*                   Check Information                      *
*        Make sure you have internet on both servers       *
************************************************************
Are you sure to continue with this settings? (yes,no) > yes

Change Servers Role

To execute the process of changing the role, we recommend using the following command:

root@vitalpbx-master:~# bascul
************************************************************
*     Change the roles of servers in high availability     *
* WARNING-WARNING-WARNING-WARNING-WARNING-WARNING-WARNING  *
*All calls in progress will be lost and the system will be *
*     be in an unavailable state for a few seconds.        *
************************************************************
Are you sure to switch from vitalpbx-master.local to vitalpbx-slave.local? (yes,no) >

This action convert the vitalpbxmaster.local to Standby and vitalpbxslave.local to Master. If you want to return to default do the same again.

Next we will show a short video how high availability works in VitalPBX

High Availability demo video on VitalPBX

Recommendations

If you have to turn off both servers at the same time, we recommend that you start by turning off the one in Standby and then the Master
If the two servers stopped abruptly, always start first that you think you have the most up-to-date information and a few minutes later the other server
If you want to update the version of VitalPBX we recommend you do it first on Server Master, then do a bascul and do it again on Server Slave

Update VitalPBX version

To update VitalPBX to the latest version just follow the following steps:
1.- From your browser, go to ip 192.168.10.30
2.- Update VitalPBX from the interface
3.- Execute the following command in Master console

root@vitalpbx-master:~# bascul

4.- From your browser, go to ip 192.168.10.30 again
5.- Update VitalPBX from the interface
6.- Execute the following command in Master console

root@vitalpbx-master:~# bascul

Some useful commands

bascul, is used to change roles between high availability servers. If all is well, a confirmation question should appear if we wish to execute the action.
role, shows the status of the current server. If all is well you should return Masters or Slaves.
drbdsplit, solves DRBD split brain recovery.
pcs resource refresh --full, to poll all resources even if the status is unknown, enter the following command.
pcs cluster unstandby host, in some cases the bascul command does not finish tilting, which causes one of the servers to be in standby (stop), with this command the state is restored to normal.
pcs resource delete, removes the resource so it can be created.
pcs resource create, create the resource.
corosync-cfgtool -s, to check whether cluster communication is happy. • ps axf, confirmed that Corosync is functional, we can check the rest of the stack. Pacemaker has already been started, so verify the necessary processes are running. • pcs status, check the pcs status output. • crm_verify -L -V, check the validity of the configuration. • drbdadm status, shows the integrity status of the disks that are being shared between both servers in high availability. If for some reason the status of Connecting or Standalone returns to us, wait a while and if the state remains it is because there are synchronization problems between both servers, and you should execute the drbdsplit command.
cat /proc/drbd, the state of your device is kept in /proc/drbd.
drbdadm role drbd0, another way to check the role of the block device.
drbdadm primary drbd0, switch the DRBD block device to Primary using drbdadm.
drbdadm secondary drbd0, switch the DRBD block device to Secondary using drbdadm.

More Information

If you want more information that will help you solve problems about High Availability in VitalPBX we invite you to see the following manual
High Availability Manual, step by step

CONGRATULATIONS, you have installed and tested the high availability in VitalPBX 4
👍

About

High Availability on VitalPBX 4 with DRBD

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages