Installation and configuration of DRBD Based on CentOS 6.5

Source: Internet
Author: User
Tags echo b

Installation and configuration of DRBD Based on CentOS 6.5

1. drbd Overview

Distributed Replicated Block Device (DRBD) is a software-based, non-shared, Replicated storage solution for Block devices (hard disks, partitions, logical volumes, etc.) between servers).

DRBD works in the kernel, similar to a driver module. The DRBD job is located between the buffer cache of the file system and the disk scheduler. It is sent to another host through TCP/IP to the peer's TCP/IP and finally to the drbd of the peer, the drbd of the other party is stored on the local disk, which is similar to a network RAID-1 function.

The DRBD function can be used in high availability (HA) instead of a shared disk array. Data on the local (master node) and remote (slave node) can be synchronized in real time. When the local system fails, the same data is retained on the remote host and can be used again.

The architecture of DRBD is as follows:

Underlying Device Support

DRBD needs to be built on the underlying device and then build a block device. A drbd device is like a physical disk. You can create a file system on it. DRBD supports the following underlying devices:

1. a disk, or a partition of the disk;

2. A soft raid device;

3. A logical volume of LVM;

4. An EVMS (Enterprise Volume Management System) Volume;

5. Any other block device.

DRBD replication Mode

Protocol:

Asynchronous replication protocol. Once the write to the local disk is complete and the data packet is in the sending queue, the write is considered complete. When a node fails, data may be lost because the data written to the remote node may still be sent to the queue. Although the data on the Failover node is consistent, it is not updated in time. This is usually used for geographically separate nodes.

Protocol B:

Memory synchronization (semi-sync) replication protocol. Once the data written to the local disk is complete and the copied data packet reaches the peer node, it is considered to have been completed on the master node. Data loss may occur when two nodes at the same time fail, because the data during transmission may not be submitted to the disk.

Protocol C:

Synchronous replication protocol. The write operation is considered complete only when the write operation has been confirmed on the disk of the local node and the remote node. No data is lost, so this is a popular mode for cluster nodes, but I/O throughput depends on network bandwidth.

Generally, protocol C is used, but selecting protocol C affects traffic and network latency. To ensure data reliability, we must carefully select which Protocol to use in the production environment.

Ii. Installation of drbd

1. Preparations

1) This configuration has two Test Nodes: node1.comratings.com and node2.comratings.com. The IP addresses of these nodes are 10.0.0.16 and 10.0.0.17 respectively, and are parsed to the corresponding/etc/hosts;

2) each node of node1 and node2 provides a shard of the same size as the drbd device. Here, the shard size is/dev/sda5 on both nodes, and the size is 512 MB;

3) The system is CentOS 6.5 and x86_64.

2. Introduction to the software package

Drbd consists of a kernel module and a user space management tool. The drbd kernel module code has been integrated into Versions later than Linux kernel 2.6.33. Therefore, if your kernel version is later than this version, you only need to install the management tool. Otherwise, you need to install both the kernel module and the management tool, and the version numbers must be consistent.

Currently, drbd versions applicable to CentOS 5 mainly include 8.0, 8.2, and 8.3. The rpm packages are named drbd, drbd82, and drbd83 respectively, the corresponding kernel modules are named kmod-drbd, kmod-drbd82 and kmod-drbd83 respectively. For CentOS 6, the rpm packages are drbd and drbd-kmdl. However, you must remember two points in actual selection: the versions of drbd and drbd-kmdl must correspond to each other, and the version of drbd-kmdl must correspond to the content version of the current system. The features and configurations of each version are slightly different. The platform used in our experiment is x86_64 and the system is CentOS 6.4. Therefore, we need to install the kernel module and management tool at the same time. Here we choose the latest 8.4 version (drbd-8.4.3-33.el6.x86_64.rpm and drbd-kmdl-2.6.32-431.el6-8.4.3-33.el6.x86_64.rpm), for ftp://rpmfind.net/linux/atrpms/, Please download as usual.

In actual use, you need to download the required software package version based on your system platform.

3. install the software package

After the download is complete, install it directly:

# Rpm-ivh drbd-8.4.3-33.el6.x86_64.rpm drbd-kmdl-2.6.32-431.el6-8.4.3-33.el6.x86_64.rpm

3. Configure drbd

1. configuration file Introduction

The main configuration file of drbd is/etc/drbd. conf; For ease of management, some configuration files are usually divided into multiple parts and saved to/etc/drbd. in the d directory, the main configuration file only uses the "include" command to integrate these configuration file fragments. Generally, the configuration file in the/etc/drbd. d directory is global_common.conf and all files ending with. res. Global_common.conf mainly defines the global and common segments, and each. res file is used to define a resource.

In the configuration file, the global segment can only appear once. If all the configuration information is saved to the same configuration file and not separated into multiple files, the global segment must be at the beginning of the configuration file. Currently, only the minor-count, dialog-refresh, disable-ip-verification, and usage-count parameters can be defined in the global segment.

The common section is used to define parameters inherited by each resource by default. parameters that can be used in the resource definition can be defined in the common section. In practice, the common section is not required, but we recommend that you define parameters for multiple resource sharing as parameters in the common section to reduce the complexity of the configuration file.

The resource segment is used to define drbd resources. Each resource is usually defined in a separate file ending with. res in the/etc/drbd. d directory. When defining a resource, you must name it. The name can contain non-blank ASCII characters. Each resource segment must contain at least two host sub-segments to define the nodes associated with the resource, other parameters can be inherited from the common section or the default drbd without being defined.

The following is my configuration example:

# Cat/etc/drbd. d/global-common.conf

Global {
Usage-count no;
# Minor-count dialog-refresh disable-ip-verification
}
Common {
Protocol C;
Handlers {
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 16 k ";
# After-resync-target/usr/lib/drbd/unsnapshot-resync-target-lvm.sh;
}
Startup {
# Wfc-timeout 120;
# Degr-wfc-timeout 120;
}
Disk {
On-io-error detach;
# Fencing resource-only;
}
Net {
Cram-hmac-alg "sha1 ";
Shared-secret "mydrbd ";
}
Syncer {
Rate 1000 M;
}
}

2. Define a resource/etc/drbd. d/web. res. The content is as follows:

Resource web {
On node1.comratings.com {
Device/dev/drbd0;
Disk/dev/sda5;
Address 10.0.0.16: 7789;
Meta-disk internal;
}
On node2.comratings.com {
Device/dev/drbd0;
Disk/dev/sda5;
Address 10.0.0.17: 7789;
Meta-disk internal;
}
}

Note: The preceding configurations must be the same on both nodes.

4. Start and view drbd

1. initialize Resources

Run the following commands on Node1 and Node2:

# Drbdadm create-md web

2. Start the service

Run the following commands on Node1 and Node2:

# Service drbd start

3. view the startup status

# Cat/proc/drbd

Version: 8.3.8 (api: 88/proto: 86-94)

GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16

0: cs: Connected ro: Secondary/Secondary ds: Inconsistent/Inconsistent C r ----

Ns: 0 nr: 0 dw: 0 dr: 0 al: 0 bm: 0 lo: 0 pe: 0 ua: 0 ap: 0 ep: 1 wo: B oos: 505964

You can also run the drbd-overview command to view the details:

# Drbd-overview

0: web Connected Secondary/Secondary Inconsistent/Inconsistent C r ----

From the above information, we can see that both nodes are in the Secondary state. Therefore, we need to set one of the nodes as Primary. Run the following command on the node to be set as Primary:

# Drbdadm primary -- force resource

Note: You can also use the following command to set the master node on the node to be set as Primary:

# Drbdadm -- overwrite-data-of-peer primary web

Check the status again and you will find that the data synchronization process has started:

# Drbd-overview

0: web SyncSource Primary/Secondary UpToDate/Inconsistent C r ----

[============>...] Sync 'ed: 66.2% (172140/505964) K delay_probe: 35

After the data synchronization is complete, check the status again. You can find that the node has the real-time status card and the node has the primary and secondary nodes:

# Drbd-overview

0: web Connected Primary/Secondary UpToDate/UpToDate C r ----

4. Create a File System

The file system can only be mounted on the Primary node. Therefore, the drbd device can be formatted only after the master node is set:

# Mke2fs-j-l drbd/dev/drbd0

# Mkdir/mnt/drbd

# Mount/dev/drbd0/mnt/drbd

5. Switch between Primary and Secondary nodes.

For the drbd service of the Primary/Secondary model, only one node can be set to Primary at a time point. Therefore, you must switch the roles of the two nodes, only after the original Primary node is set to Secondary can the original Secondary node be set to Primary:

Node1:

# Cp-r/etc/drbd. */mnt/drbd

# Umount/mnt/drbd

# Drbdadm secondary web

View status:

# Drbd-overview

0: web Connected Secondary/Secondary UpToDate/UpToDate C r ----

Node2:

# Drbdadm primary web

# Drbd-overview

0: web Connected Primary/Secondary UpToDate/UpToDate C r ----

# Mkdir/mnt/drbd

# Mount/dev/drbd0/mnt/drbd

Run the following command to check whether the file copied to this device exists on the master node:

# Ls/mnt/drbd

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

DRBD details: click here
DRBD: click here

This article permanently updates the link address:

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.