362.1 DRBD (weight: 6)

Tech Tutorial: 362.1 DRBD (Distributed Replicated Block Device) #

Introduction #

DRBD, or Distributed Replicated Block Device, is a software-based, shared-nothing, replicated storage solution for mirroring the content of block devices (such as hard disks, partitions, logical volumes, etc.) between servers. It is commonly used in high-availability (HA) clusters to ensure data redundancy and consistency across networked computers.

In this tutorial, we will cover the essential aspects of setting up and managing a DRBD environment as part of the preparation for the Linux Professional Institute Certification (LPIC) exam objective 362.1. We will go through installation, configuration, management, and troubleshooting of DRBD.

Key Knowledge Areas: #

  • Installation and configuration of DRBD
  • Understanding of DRBD resources, states, and configuration files
  • Management and monitoring of DRBD devices
  • Basic troubleshooting of DRBD setups

Utilities: #

  • drbdadm
  • drbdsetup
  • drbdmeta

Prerequisites #

This guide assumes that you have two Linux servers with connectivity between them and that you have superuser privileges on both. The examples use CentOS 7, but similar steps can be applied to other Linux distributions.

Step-by-Step Guide #

Step 1: Installation #

First, you need to install DRBD on both nodes. On RHEL/CentOS-based systems, you can use the EPEL repository:

sudo yum install epel-release
sudo yum install drbd83-utils kmod-drbd83

For Debian/Ubuntu systems:

sudo apt-get update
sudo apt-get install drbd-utils

Step 2: Configuring DRBD #

Create a DRBD configuration file. Here’s an example configuration for a resource named r0:

sudo nano /etc/drbd.d/r0.res

Insert the following configuration:

resource r0 {
  protocol C;

  on primary {
    device /dev/drbd0;
    disk /dev/sda7;
    address 192.168.1.1:7788;
    meta-disk internal;
  }

  on secondary {
    device /dev/drbd0;
    disk /dev/sda7;
    address 192.168.1.2:7788;
    meta-disk internal;
  }
}

Step 3: Initialize DRBD Metadata #

On both nodes, you need to create DRBD metadata on the configured devices:

sudo drbdadm create-md r0

Output will confirm that metadata was successfully created.

Step 4: Starting DRBD #

Start DRBD on both nodes:

sudo drbdadm up r0

Step 5: Initial Device Synchronization #

Choose one node to be the primary node. Only on the primary node, run:

sudo drbdadm primary --force r0

This sets the device to primary mode and starts synchronization. Check the synchronization status:

sudo cat /proc/drbd

Step 6: Using the DRBD Device #

Once synchronized, you can create a filesystem on the DRBD device on the primary node:

sudo mkfs.ext4 /dev/drbd0

Mount the filesystem:

sudo mount /dev/drbd0 /mnt

Step 7: Managing DRBD #

To adjust the DRBD device or to switch roles, use drbdadm. For example, to demote the primary to secondary:

sudo drbdadm secondary r0

To promote a secondary to primary:

sudo drbdadm primary r0

Monitoring and Troubleshooting #

Check the status of DRBD:

sudo drbdadm status

In case of issues, consult the DRBD logs typically located in /var/log/messages or use dmesg:

dmesg | grep drbd

Conclusion #

In this tutorial, you have learned how to set up and manage a basic DRBD environment. DRBD is a powerful tool for data replication and is crucial in creating high-availability clusters. With understanding and practice, you can implement DRBD in production environments to ensure data safety and service availability.