DRBD for MySQL High Availability

Source: Internet
Author: User
Keywords mysql mysql database mysql tutorial
Most MySQL high-availability solutions are based on various replication technologies that MySQL comes with. Essentially, the data update or transaction on one instance is replayed on other instances to complete data replication. When the production instance fails to provide services, the application connection is switched to other instances to achieve continuous availability of database services. From this perspective, the way to use DRBD to achieve high availability of MySQL is completely different. It has nothing to do with MySQL replication, and it can be said to be a different way.


Introduction to DRBD

The full name of DRBD is Distributed Replicated Block Device, that is, distributed replicated block device. It is a software-implemented, shared-free, storage replication solution for the content of mirrored block devices between servers. DRBD is a mirrored block device, which is mirrored into the same data block according to data bits. Simply put, DRBD is a software that automatically replicates the storage data of the active node to the corresponding storage location of the standby node after the data is changed. It is a physical copy of the data block level.

1. Working principle
DRBD needs to run on each node, and it runs in the kernel of the node host, so DRBD is a kernel module, which has been integrated into the kernel since Linux version 2.6.33.

Suppose the left node is the active node (primary) and the right node is the standby node (secondary). The left node receives the data sent to the data path of the kernel. DRBD registers the hook in the data path to check the data. When it finds that the received data is sent to the storage location managed by itself, it copies another copy and stores one copy to the local machine. The other copy of the DRBD storage device is sent to the TCP/IP protocol stack, and transmitted to the network TCP/IP protocol stack of another node host through the network card network. The DRBD module running on another node also checks the data on the data path, and when it finds the transmitted data, it stores it in the corresponding location of the DRBD storage device.
If the left node goes down, the right node can become the active node in the high-availability cluster, and the received data is stored locally. When the left node comes back online, the changed data of the right node after the downtime is mirrored to the left node. After the mirroring process is completed, a success/failure response message needs to be returned. This response message can be returned at different locations in the transmission process and can be divided into three replication modes:
A: Async, asynchronous: return immediately after the local write succeeds. The data is stored in the sending buffer, which may be lost, but the transmission performance is good.

B: Semi sync: after the other party receives the data, but has not returned before placing the disk.

C: Sync, synchronization: the local and the other party write successfully and return after confirmation. The data reliability is high, and the production system generally adopts this method.

2. The underlying devices supported by DRBD
DRBD needs to build a block device on the underlying device. For users, a DRBD device is like a physical disk, and a file system can be created in the DRBD device. The underlying device categories supported by DRBD include: a disk or a partition of a disk; soft raid device; LVM logical volume; EVMS (Enterprise Volume Management System, Enterprise Volume Management System) volume; or any other block device.
3. DRBD resources
DRBD resource defines the storage space and related information managed by DRBD, and mainly configures the following four options:
Resource name: It can be any ACSII code character except blank characters.

DRBD device: On both nodes, the device file of this DRBD device is generally /dev/drbdN, and its major device number is 147.

Disk: The storage device provided by each node on both nodes.

Network configuration: the network attributes used when the two parties are synchronizing data.

4. DRBD Configuration Tool
DRBD mainly has the following three configuration tools:
drbdadm: Advanced management tool, manage /etc/drbd.conf, send commands to drbdsetup and drbdmeta.

drbdsetup: Configure the DRBD module loaded into the kernel, which is rarely used directly.

drbdmeta: To manage the META data structure, it is rarely used directly.

5. The difference between DRBD and RAID1
RAID1 also implements data mirroring and backup between different storage devices. The difference is that each storage device of RAID1 is connected to a RAID controller and connected to a host, while DRBD implements data mirroring and backup of host storage devices at different nodes through the network.
6. DRBD and shared storage
If all nodes access the same data file in the same storage space, that is to say, only one copy of the data is shared, then the storage space is shared storage. The definition of DRBD points out "no sharing"—the storage device space of different nodes is mirrored. DRBD can be directly applied in the cluster of the active and standby model, or it can be applied in the dual-active model cluster through high-availability software such as corosycn. This requires distributed cluster file systems such as DML/OCFS2/GFS2 to allocate locks for dual-master read and write. There is also DRBD that provides highly available mirror backup for NFS shared storage.

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.