Installing DRBD + Heartbeat + NFS on CentOS 5.6 x86_64

       

       This article is actually a supplement to the section “Production-Ready High-Availability NFS File Server” in Chapter 5 of “Building High-Availability Linux Servers (2nd Edition)”. In fact, software like DRBD and Heartbeat can all be installed automatically via yum. For example, the command to install DRBD is as follows:

1
yum -y install drbd83 kmod-drbd83

The DRBD configuration file /etc/drbd.conf is shown below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
global {
# minor-count dialog-refresh disable-ip-verification
usage-count no;         # Track DRBD usage
}
common {
syncer  { rate 30M; }  # Sync rate, depends on bandwidth
}
resource r0 {           # Create a resource named "r0"
protocol C;             # Use DRBD Protocol C (data sync protocol: C acknowledges after receiving and writing data)
handlers {              # Default DRBD library files
pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f";
# fence-peer "/usr/lib/drbd/crm-fence-peer.sh";
# split-brain "/usr/lib/drbd/notify-split-brain.sh root";
# out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh root";
# before-resync-target "/usr/lib/drbd/snapshot-resync-target-lvm.sh -p 15 -- -c 16k";
# after-resync-target /usr/lib/drbd/unsnapshot-resync-target-lvm.sh;
}
startup {
# wfc-timeout degr-wfc-timeout outdated-wfc-timeout wait-after-sb
wfc-timeout 120;
degr-wfc-timeout 120;    
}
disk {
# on-io-error fencing use-bmbv no-disk-barrier no-disk-flushes
# no-disk-drain no-md-flushes max-bio-bvecs
on-io-error detach;
}
net {
# sndbuf-size rcvbuf-size timeout connect-int ping-int ping-timeout max-buffers
# max-epoch-size ko-count allow-two-primaries cram-hmac-alg shared-secret
# after-sb-0pri after-sb-1pri after-sb-2pri data-integrity-alg no-tcp-cork
max-buffers 2048;
cram-hmac-alg "sha1";
shared-secret "123456";
#allow-two-primaries;
}
syncer {
rate 30M;
# rate after al-extents use-rle cpu-mask verify-alg csums-alg
}
on centos1.cn7788.com { # Define a node, named by its hostname
device  /dev/drbd0; # Map resource device /dev/drbd0 to the actual physical partition /dev/sdb1
disk    /dev/sdb;
address 192.168.11.32:7788;      # Set the listening address and port
meta-disk       internal;
}
on centos2.cn7788.com {         # Define a node, named by its hostname
device  /dev/drbd0; # Map resource device /dev/drbd0 to the actual physical partition /dev/sdb1
disk    /dev/sdb;
address 192.168.11.33:7788;       # Set the listening address and port
meta-disk       internal;
}
}

The Heartbeat configuration file is as follows:

1
2
3
4
5
6
7
8
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 15
ucast eth0 192.168.11.32
ucast eth1 10.0.0.2
auto_failback off
node centos1.cn7788.com centos2.cn7788.com

A few supplementary points:

1. Many people prefer deploying DRBD using a dedicated partition, which is also feasible. You only need to reserve free space during system installation and then use fdisk during DRBD deployment. This does not need to be written into /etc/fstab, i.e., it does not need to be mounted during system installation. In my testing, I found this method of deploying DRBD to be rather tedious, increasing the overall complexity of the experiment, and it also requires using dd. I personally recommend using a dedicated disk as the DRBD block device instead.

2. The hard drive or partition used for DRBD on the Secondary host can be a different size than the Primary host, but please do not make it smaller than the Primary host.

3. I recommend Gigabit series server NICs and switches. During testing, the sync rate was found to be between 100M-200M. Following the official recommendation, set the rate to 30% of the minimum bandwidth.

4. DRBD has high requirements for the network environment. It is recommended to use a dedicated twisted-pair cable as the heartbeat line between the two hosts. If conditions permit, consider using two or more heartbeat lines. If this part is done well, split-brain issues are basically non-existent. In fact, the entire experiment can be implemented on the same network initially, and heartbeat lines can be added later, which is also feasible.

5. When installing Heartbeat, you need to install it twice, i.e., run “yum -y install heartbeat” twice.

6. The DRBD+Heartbeat+NFS setup proved to be very robust in testing. I often abruptly powered off the primary machine during write tests, and the data writing was completely unaffected — users could not notice at all that a machine had gone down.

7. It is recommended not to use the root partition as the MySQL datadir, otherwise when you run “show database” you will find a database named #mysql50#lost+found.

8. Even if a split-brain issue occurs, DRBD will not lose data — simply resolve it manually. It is precisely because DRBD is reliable that MySQL also recommends it as one of the high-availability solutions for MySQL. For specific operations, see http://database.51cto.com/art/201209/355332.htm

This article is from the blog of 抚琴煮酒. Please be sure to retain this source: http://andrewyu.blog.51cto.com/1604432/976135

Leave a Comment

Your email address will not be published.