DRBD + Heartbeat + NFS File Sharing storage Architecture

Source: Internet
Author: User

In high-availability solutions (HA), two common architectures are used to share data in clusters:
1. Storage of shared data using storage cabinets of SAN and other architectures
2. Divide a space in the local disk of the machines in each cluster and synchronize the space to other machines in the cluster by means of networks, to ensure that the data on each machine is consistent.
Of course, in order for the second architecture to be used for databases and other applications, synchronization should be conducted in the form of data blocks rather than file copies, and DRBD is the software that can be used to implement the second architecture.

1. What is DRBD?
DRBD is actually a block device. It consists of two parts: the kernel module and related programs. It synchronizes the entire device through network communication, which is similar to a network RAID function. That is to say, when you write data to a file system on a local DRBD device, the data will be sent to another host on the network at the same time, and recorded in the same format in a file system. Data on local nodes (hosts) and remote nodes (hosts) can be synchronized in real time and Data Consistency can be ensured. Therefore, when the host on the local node fails, the host on the remote node will retain a copy of identical data for continuous use to achieve high availability.
Because DRBD synchronizes data in blocks over the network, it does not depend on upper-layer devices such as file systems, LVM, and Soft RAID, it can be used for database file synchronization (different from rsync file synchronization ).


 

Ii. Runtime Environment
Operating System: CentOS 5.9 Host Name:
TM-Master 192.168.137.132 sdb1 10G
TM-Slave 192.168.137.20.sdb1 10G
Heartbeat virtual IP Address: 192.168.137.13
Gateway: 192.168.137.1

Iii. Initial settings
1. Set the host names of the two servers TM-Master, TM-Slave:
# Hostname TM-Master
# Vi/etc/sysconfig/network
NETWORKING = yes
NETWORKING_IPV6 = no
HOSTNAME = TM-Master
2. Modify the/etc/hosts of the two servers with the same content:
# Vi/etc/hosts
192.168.137.132 TM-Master
192.168.137.20.tm-Slave
3. Confirm the local hard disks of the two servers. Here we use/dev/sdb and create a separate partition/dev/sdb1 for it.
# Fdisk-l/dev/sdb
Disk/dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System
/Dev/sdb1 1 1305 10482381 83 Linux
Note: DRBD is synchronized using data blocks. Therefore, do not create a file system before creating an image disk.
4. Install DRBD on both servers. Use yum to install DRBD:
# Yum-y install drbd kmod-drbd82
5. Check whether the drbd modules of the two servers are loaded properly:
# Modprobe drbd
# Lsmod | grep drbd
Drbd 245928 0

Iv. Configuration
1. Configure/etc/drbd. conf, refer to location:/usr/share/doc/drbd82-8.2.6/drbd. conf. Here we edit it directly on the TM-Master node:
[Root @ TM-Master ~] Vi/etc/drbd. conf
Resource r0
{
Protocol C;
Startup {
Wfc-timeout 0;
Degr-wfc-timeout 120;
}
Disk {
On-io-error detach;
}
Syncer {
Rate 10 M;
}
On TM-Master {
Device/dev/drbd1;
Disk/dev/sdb1;
Address 192.168.137.132: 7789;
Meta-disk internal;
}
On TM-Master S {
Device/dev/drbd1;
Disk/dev/sdb1;
Address 192.168.137.small: 7789;
Meta-disk internal;
}
}
Configuration instructions:
Resource r0; resource Group name r0
Degr-wfc-timeout 120; connection timeout
On-io-error detach; if a disk error occurs, it is not connected.
Rate 10 M; set the maximum network rate for master-slave node synchronization
On TM-Master; Host Name of the node
Device/dev/drbd1; The created drbd device.
2. Copy the configuration file of TM-Master to TM-Slave:
[Root @ TM-Slave ~] # Scp root @ TM-Slave:/etc/drbd. conf/etc/drbd. conf
3. initialize the partitions on the two servers and start the service:
# Drbdadm create-md r0
Writing meta data...
Initialising activity log
NOT initialized bir0ap
New drbd meta data block sucessfully created.
Note:
1) "r0" is the Resource Name Defined in drbd. conf.
2) When the command "drbdadm create-md r0" is executed, the following error message is displayed.
Device size wocould be truncated, which
Wocould upload upt data and result in
'Access beyond end of device' errors.
You need to either
* Use external meta data (recommended)
* Shrink that filesystem first
* Zero out of the device (destroy the filesystem)
Operation refused.
Command 'drbdmeta 0 v08/dev/xvdb internal create-md' terminated with exit code 40
Drbdadm create-md r0: exited with code 40
Solution: Initialize the disk file format. dd if =/dev/zero of =/dev/sdxx bs = 1 M count = 100
# Dd if =/dev/zero of =/dev/sdb1 bs = 1 M count = 100
100 + 0 records in
100 + 0 records out
104857600 bytes (105 MB) copied, 1.92004 seconds, 54.6 MB/s
Start:
#/Etc/init. d/drbd start
Starting DRBD resources: [d (r0) s (r0) n (r0)].
..........
Here I use r0, and you can also use your resource group name, such as the db in this example.
View the status of the two machines, with cat/proc/drbd or/etc/init. d/drbd status:
[Root @ TM-Master ~] #/Etc/init. d/drbd status
Drbd driver loaded OK; device status:
Version: 8.2.6 (api: 88/proto: 86-88)
GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn @ c5-x8664-build, 2008-10-03 11:30:17
M: res cs st ds p mounted fstype
0: r0 Connected Secondary/Secondary Inconsistent/Inconsistent C
[Root @ TM-Slave ~] #/Etc/init. d/drbd status
Drbd driver loaded OK; device status:
Version: 8.2.6 (api: 88/proto: 86-88)
GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn @ c5-x8664-build, 2008-10-03 11:30:17
M: res cs st ds p mounted fstype
0: r0 Connected Secondary/Secondary Inconsistent/Inconsistent C
Now both machines are in the Secondary status. (Marked in red). If it is Unknow, check whether the two servers are configured the same.
5. Set the primary Host:
[Root @ TM-Master ~] Drbdadm primary r0
The setting may fail for the first time. You can use:
[Root @ TM-Master ~] # Drbdsetup/dev/drbd0 primary-o
The TM-Master is used as the host, and the data in the TM-Master is synchronized to the TM-Slave in blocks. R0 indicates the resource name. You can view the status again:
[Root @ TM-Master ~] #/Etc/init. d/drbd status
Drbd driver loaded OK; device status:
Version: 8.2.6 (api: 88/proto: 86-88)
GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn @ c5-x8664-build, 2008-10-03 11:30:17
M: res cs st ds p mounted fstype
... Sync' ed: 8.8% (9350/10236) M
0: r0 SyncSource Primary/Secondary UpToDate/Inconsistent C
[Root @ TM-Slave ~] #/Etc/init. d/drbd status
Drbd driver loaded OK; device status:
Version: 8.2.6 (api: 88/proto: 86-88)
GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn @ c5-x8664-build, 2008-10-03 11:30:17
M: res cs st ds p mounted fstype
... Sync' ed: 13.7% (8847/10236) M
0: r0 SyncTarget Secondary/Primary Inconsistent/UpToDate C
You can view the disk copy status through/proc/drbd:
[Root @ TM-Master ~] # Cat/proc/drbd
Version: 8.2.6 (api: 88/proto: 86-88)
GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn @ c5-x8664-build, 2008-10-03 11:30:17
0: cs: SyncSource st: Primary/Secondary ds: UpToDate/Inconsistent C r-
Ns: 2151328 nr: 0 dw: 0 dr: 2151328 al: 0 bm: 131 lo: 0 pe: 0 ua: 0 ap: 0 oos: 8330696
[=>...] Sync 'ed: 20.6% (8135/10236) M
Finish: 0:12:48 speed: 10,804 (10,244) K/sec
[Root @ TM-Slave ~] # Cat/proc/drbd
Version: 8.2.6 (api: 88/proto: 86-88)
GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn @ c5-x8664-build, 2008-10-03 11:30:17
0: cs: SyncTarget st: Secondary/Primary ds: Inconsistent/UpToDate C r-
Ns: 0 nr: 1791904 dw: 1791904 dr: 0 al: 0 bm: 109 lo: 0 pe: 0 ua: 0 ap: 0 oos: 8690120
[=>...] Sync 'ed: 17.2% (8486/10236) M
Finish: 0:11:18 speed: 12,792 (10,236) K/sec
At this point, the image partition has been created, and we set it to boot on the two servers:
# Chkconfig drbd on
Mount and use
Format and mount the file system on the Primary Master node, that is, TM-Master.
[Root @ TM-Master ~] # Mkfs. ext3/dev/drbd0
[Root @ TM-Master ~] # Tune2fs-c 0-I 0/dev/drbd0
[Root @ TM-Master ~] # Mkdir/home/drbd
[Root @ TM-Master ~] # Mount/dev/drbd0/home/drbd
[Root @ TM-Master ~] # Mount
/Dev/drbd0 on/home/drbd type ext3 (rw)
Note: The drbd device can only be used on the Primary end. To avoid misoperation, it is in the Secondary status by default after the machine is restarted. To use the drbd device, you must manually set it to Primary.

DRBD details: click here
DRBD: click here

DRBD for Linux high availability (HA) CLUSTERS

DRBD Chinese application guide PDF

Installation and configuration notes for DRBD in CentOS 6.3

High-availability MySQL based on DRBD + Corosync

Install and configure DRBD in CentOS 6.4

  • 1
  • 2
  • 3
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.