DRBD + Pacemaker & Corosync NFS Cluster Centos7
On Both Nodes
Host file
xxxxxxxxxxvim /etc/hosts10.1.2.114 nfs1 nfs1.localdomain.com
10.1.2.115 nfs2 nfs2.localdomain.com
Corosync will not work if you add something like this: 127.0.0.1 nfs1 nfs2.localdomain.com - however you do not need to delete 127.0.0.1 localhost
Firewall
Option 1 Firewalld
xxxxxxxxxxsystemctl start firewalldsystemctl enable firewalldfirewall-cmd --permanent --add-service=nfsfirewall-cmd --permanent --add-service=rpc-bindfirewall-cmd --permanent --add-service=mountdfirewall-cmd --permanent --add-service=high-availabilityOn NFS1
xxxxxxxxxxfirewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.1.2.115" port port="7789" protocol="tcp" accept'firewall-cmd --reloadfirewall-cmd --reloadOn NFS2
xxxxxxxxxxfirewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.1.2.114" port port="7789" protocol="tcp" accept'firewall-cmd --reloadfirewall-cmd --reloadDisable SELINUX
xxxxxxxxxxvim /etc/sysconfig/selinuxSELINUX=disabled
Pacemaker Install
Install PaceMaker and Corosync
xxxxxxxxxxyum install -y pacemaker pcsAuthenticate as the hacluster user
xxxxxxxxxxecho "H@xorP@assWD" | passwd hacluster --stdinStart and enable the service
xxxxxxxxxxsystemctl start pcsdsystemctl enable pcsdON NFS1
Test and generate the Corosync configuration
xxxxxxxxxxpcs cluster auth nfs1 nfs2 -u hacluster -p H@xorP@assWDxxxxxxxxxxpcs cluster setup --start --name mycluster nfs1 nfs2ON BOTH NODES
Start the cluster
xxxxxxxxxxsystemctl start corosyncsystemctl enable corosyncpcs cluster start --allpcs cluster enable --allVerify Corosync installation
Master should have ID 1 and slave ID 2
xxxxxxxxxxcorosync-cfgtool -sON NFS1
Create a new cluster configuration file
pcs cluster cib myclusterDisable the Quorum & STONITH policies in your cluster configuration file
pcs -f /root/mycluster property set no-quorum-policy=ignorepcs -f /root/mycluster property set stonith-enabled=falsePrevent the resource from failing back after recovery as it might increases downtime
pcs -f /root/mycluster resource defaults resource-stickiness=300LVM partition setup
Both Nodes
Create a empty partition
fdisk /dev/sdbWelcome to fdisk (util-linux 2.23.2).
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):(ENTER)
Partition number (1-4, default 1): (ENTER)
First sector (2048-16777215, default 2048): (ENTER)
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-16777215, default 16777215): (ENTER)
Using default value 16777215
Partition 1 of type Linux and of size 8 GiB is setCommand (m for help): w
The partition table has been altered!
Create LVM partition
pvcreate /dev/sdb1vgcreate vg00 /dev/sdb1lvcreate -l 95%FREE -n drbd-r0 vg00View LVM partition after creation
pvdisplayLook in "/dev/mapper/" find the name of your LVM disk
ls /dev/mapper/OUTPUT:
control vg00-drbd--r0**You will use "vg00-drbd--r0" in the "drbd.conf" file in the below steps
DRBD Installation
Install the DRBD package
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.orgrpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpmyum install -y kmod-drbd84 drbd84-utilsmodprobe drbdecho drbd > /etc/modules-load.d/drbd.confEdit the DRBD config and add the to hosts it will be connecting to (NFS1 and NFS2)
vim /etc/drbd.confDelete all and replace for the following
include "drbd.d/global_common.conf";
include "drbd.d/*.res";global {
usage-count no;
}
resource r0 {
protocol C;
startup {
degr-wfc-timeout 60;
outdated-wfc-timeout 30;
wfc-timeout 20;
}
disk {
on-io-error detach;
}
net {
cram-hmac-alg sha1;
shared-secret "Daveisc00l123313";
}
on nfs1.localdomain.com {
device /dev/drbd0;
disk /dev/mapper/vg00-drbd--r0;
address 10.1.2.114:7789;
meta-disk internal;
}
on nfs2.localdomain.com {
device /dev/drbd0;
disk /dev/mapper/vg00-drbd--r0;
address 10.1.2.115:7789;
meta-disk internal;
}
}
vim /etc/drbd.d/global_common.confDelete all and replace for the following
common {
handlers {
}
startup {
}
options {
}
disk {
}
net {
after-sb-0pri discard-zero-changes;
after-sb-1pri discard-secondary;
after-sb-2pri disconnect;
}
}
On NFS1
Create the DRBD partition and assign it primary on NFS1
drbdadm create-md r0drbdadm up r0drbdadm primary r0 --forcedrbdadm -- --overwrite-data-of-peer primary alldrbdadm outdate r0mkfs.ext4 /dev/drbd0On NFS2
Configure r0 and start DRBD on NFS2
drbdadm create-md r0drbdadm up r0drbdadm secondary allPacemaker cluster resources
On NFS1
Add resource r0 to the cluster resource
pcs -f /root/mycluster resource create r0 ocf:linbit:drbd drbd_resource=r0 op monitor interval=10sCreate an additional clone resource r0-clone to allow the resource to run on both nodes at the same time
pcs -f /root/mycluster resource master r0-clone r0 master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=trueAdd DRBD filesystem resource
pcs -f /root/mycluster resource create drbd-fs Filesystem device="/dev/drbd0" directory="/data" fstype="ext4"Filesystem resource will need to run on the same node as the r0-clone resource, since the pacemaker cluster services that runs on the same node depend on each other we need to assign an infinity score to the constraint:
pcs -f /root/mycluster constraint colocation add drbd-fs with r0-clone INFINITY with-rsc-role=MasterAdd the Virtual IP resource
pcs -f /root/mycluster resource create vip1 ocf:heartbeat:IPaddr2 ip=10.1.2.116 cidr_netmask=24 op monitor interval=10sThe VIP needs an active filesystem to be running, so we need to make sure the DRBD resource starts before the VIP
pcs -f /root/mycluster constraint colocation add vip1 with drbd-fs INFINITYpcs -f /root/mycluster constraint order drbd-fs then vip1Verify that the created resources are all there
pcs -f /root/mycluster resource showpcs -f /root/mycluster constraintAnd finally commit the changes
pcs cluster cib-push myclusterOn Both Nodes
Installing NFS
Install nfs-utils
yum install nfs-utils -yStop all services
systemctl stop nfs-lock && systemctl disable nfs-lockSetup service
pcs -f /root/mycluster resource create nfsd nfsserver nfs_shared_infodir=/data/nfsinfopcs -f /root/mycluster resource create nfsroot exportfs clientspec="10.1.2.0/24" options=rw,sync,no_root_squash directory=/data fsid=0pcs -f /root/mycluster constraint colocation add nfsd with vip1 INFINITYpcs -f /root/mycluster constraint colocation add vip1 with nfsroot INFINITYpcs -f /root/mycluster constraint order vip1 then nfsdpcs -f /root/mycluster constraint order nfsd then nfsrootpcs -f /root/mycluster constraint order promote r0-clone then start drbd-fspcs resource cleanuppcs cluster cib-push myclusterReboot both servers
Test failover
pcs resource move drbd-fs nfs2Other notes on DRBD
To update a resource after a commit
cibadmin --query > tmp.xmlEdit with vi tmp.xml or do a pcs -f tmp.xml %do your thing%
cibadmin --replace --xml-file tmp.xmlDelete a resource
pcs -f /root/mycluster resource delete dbDelete cluster
pcs cluster destroy
Recover a split brain
Secondary node
drbdadm secondary all
drbdadm disconnect all
drbdadm -- --discard-my-data connect all
Primary node
drbdadm primary all
drbdadm disconnect all
drbdadm connect all
On both
drbdadm status
cat /proc/drbd