Install and configure DRDB for network filesystem replication on Debian 8 - Page 2

DRBD Configuration as Primary/Primary cluster for High Availability

Now we want to configure our Network Filesystem Cluster to work in a High Availability configuration. For that, we have to make some changes to the configuration.

Edit the configuration file /etc/drbd.d/r0.res and add the red configurations:

resource r0 {
on mysql1.local.vm {
device /dev/drbd1;
disk /dev/sdb;
address 192.168.152.100:7789;
meta-disk internal;
}
on mysql2.local.vm {
device /dev/drbd1;
disk /dev/sdb;
address 192.168.152.110:7789;
meta-disk internal;
}
handlers {
split-brain "/usr/lib/drbd/notify-split-brain.sh root";
}
net {
allow-two-primaries;
after-sb-0pri discard-zero-changes;
after-sb-1pri discard-secondary;
after-sb-2pri disconnect;
}
startup {
become-primary-on both;
}
}

In detail, we have automated the managment of a split brain situation, because we are in a HA environment, and fail over must be automated.

split-brain = this is the action to be taken when splitbrain heappens, in this case, he sends an email to [email protected].

after-sb-0priSplit brain has just been detected, but at this time the resource is not in the Primary role on any host.

discard-zero-changes = If there is any host on which no changes occurred at all, simply apply all modifications made on the other and continue.
after-sb-1pri = Split brain has just been detected, and at this time the resource is in the Primary role on one host.

discard-secondary = Whichever host is currently in the Secondary role, make that host the split brain victim.

after-sb-2pri = Split brain has just been detected, and at this time the resource is in the Primary role on both hosts.

Then on both servers run the following commands, each command on each server simultaneously:

drbdadm disconnect r0
drbdadm connect r0
drbdadm primary r0

Then restart service on both servers with:

/etc/init.d/drbd restart

Now if we look at logs of drbd for both nodes we can see

[email protected]:~# cat /proc/drbd
version: 8.4.3 (api:1/proto:86-101)
srcversion: 1A9F77B1CA5FF92235C2213
1: cs:Connected ro:Primary/Primary ds:UpToDate/UpToDate C r-----
ns:0 nr:12 dw:4 dr:904 al:0 bm:1 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

[email protected]:~# cat /proc/drbd
version: 8.4.3 (api:1/proto:86-101)
srcversion: 1A9F77B1CA5FF92235C2213
1: cs:Connected ro:Primary/Primary ds:UpToDate/UpToDate C r-----
ns:12 nr:0 dw:0 dr:924 al:0 bm:1 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

As you can see, in both cases the configuration is Primary/Primary, so now you can mount the partion on both servers if needed.

[email protected]:~# mount /dev/drbd1 /var/www/
[email protected]:~# df -h
File system Dim. Usati Dispon. Uso% Montato su
/dev/sda1 9,3G 1,4G 7,5G 16% /
udev 10M 0 10M 0% /dev
tmpfs 97M 4,6M 92M 5% /run
tmpfs 241M 0 241M 0% /dev/shm
tmpfs 5,0M 4,0K 5,0M 1% /run/lock
tmpfs 241M 0 241M 0% /sys/fs/cgroup
/dev/drbd1 4,8G 10M 4,6G 1% /var/www

Now check how it works. Try to create one file in mysql1 

[email protected]:~# touch /var/www/mysql1.txt
[email protected]:~#

And now try mount drbd1 on mysql2 and see if mysql1.txt is present.

[email protected]:~# mount /dev/drbd1 /var/www/
[email protected]:~# ls -al /var/www/
totale 24
drwxr-xr-x 3 root root 4096 ott 5 15:30 .
drwxr-xr-x 12 root root 4096 ott 5 12:26 ..
drwx------ 2 root root 16384 ott 5 12:23 lost+found
-rw-r--r-- 1 root root 0 ott 5 15:20 mysql1.txt

As you can see, the file is present!

Share this page:

0 Comment(s)

Add comment

Comments

From: Matteo Temporini at: Oct 11, 2016