DRBD Pacemaker HA Cluster
In this blog we step you through the very basics in setting up a DRBD Pacemaker HA Cluster on Ubuntu 16.04 LTS. This can make up the foundation of many clusters as, at the DRBD level, we can make the filesystem highly available, We are using two Ubuntu 16.04 servers for the demonstration. This is the latest LTS version from Ubuntu and both DRBD and Pacemaker are in the standard repos.
DRBD
This component manages replication of your data at the block device level. Distributed Replicated Block Device. You can find more detail at DRBD.org. The link is to the version 8.4 docs which is the version included with Ubuntu 16.04. For commercial support and training then this is offered by Linbit. To nice thing with DRBD is that it creates a shared-nothing cluster. There is no central shared SAN or iSCSI disk to go wrong. The data is replicated between nodes so nothing is shared other than the data.
There is a kernel module and user-space tools to implement this and these can be installed with:
sudo apt-get update sudo apt-get install -y drbd8-utils
With this installed you want to make sure that you can resolve you hostname to the IP Address you want you use in the cluster. For this edit the /etc/hosts and make sure you replace the 127.0.1.1 entry with you actual hostname. In the example we use two hosts bob and alice and in each /etc/hosts file we have the same entries:
127.0.0.1 localhost 192.168.56.101 bob 192.168.56.102 alice
We should also make sure that NTP, Network Time Protocol is installed for accurate time:
sudo apt-get install -y ntp
The ntp package and drbd8-utils should be installed on both hosts to ensure we can proceed with the DRBD Pacemaker HA Cluster.
Additionally on both hosts we should have and additional unused disk. On this disk we create a partition of the same size on each host so that we can replicate data. On each host we will create a 1 GB partition (1 GB is the size of the disk I am using. We do not format the disk but ensure that it is clean with the command dd:
sudo dd if=/dev/zero of=/dev/sdb1
Next, on each host edit the /etc/drbd.conf
global { usage-count no; } common { protocol C; } resource r0 { on bob { device /dev/drbd0; disk /dev/sdb1; address 192.168.56.101:7788; meta-disk internal; } on alice { device /dev/drbd0; disk /dev/sdb1; address 192.168.56.102:7788; meta-disk internal; } }
sudo modprobe drbd
sudo drbdadm create-md r0
sudo drbdadm up r0
sudo drbd-overview sudo cat /proc/drbd
sudo drbdadm -- --overwrite-data-of-peer primary r0/0
sudo watch cat /proc/drbd
sudo mkfs.ext4 /dev/drbd0 sudo mkdir -p /var/www/html sudo mount /dev/drbd0 /var/www/html
Pacemaker
sudo systemctl disable drbd
sudo umount /var/www/htmlsudo drbdadm down r0
sudo apt-get install -y pacemaker
totem { version: 2 cluster_name: debian secauth: off transport:udpu interface { ringnumber: 0 bindnetaddr: 192.168.56.0 broadcast: yes mcastport: 5405 } } nodelist { node { ring0_addr: 192.168.56.101 name: bob nodeid: 1 } node { ring0_addr: 192.168.56.102 name: alice nodeid: 2 } } quorum { provider: corosync_votequorum two_node: 1 wait_for_all: 1 last_man_standing: 1 auto_tie_breaker: 0 }
sudo systemctl restart corosync sudo systemctl start pacemaker
sudo crm status
sudo crm configure > property stonith-enabled=false > property no-quorum-policy=ignore > primitive drbd_res ocf:linbit:drbd params drbd_resource=r0 op monitor interval=29s role=Master op monitor interval=31s role=Slave > ms drbd_master_slave drbd_res meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true > primitive fs_res ocf:heartbeat:Filesystem params device=/dev/drbd0 directory=/var/www/html fstype=ext4 > colocation fs_drbd_colo INFINITY: fs_res drbd_master_slave:Master > order fs_after_drbd mandatory: drbd_master_slave:promote fs_res:start > commit > show > quit