How To Install DRBD On CentOS Linux?

Learn how to install and configure DRBD on CentOS Linux with this step-by-step guide. Enable high availability and disaster recovery for your storage systems.

tutorial_img_name_alt

DRBD (Distributed Replicated Block Device) is a powerful software tool designed for Linux systems. It enables the replication of storage devices over a network, providing solutions for disaster recovery and failover management. Essentially, DRBD creates a network-based alternative to shared storage, ensuring high availability and reliability for your hardware resources.

What You'll Learn

How DRBD Works

DRBD allows the creation of a virtual block device (/dev/drbd0) that mirrors physical block devices (e.g., /dev/sdb1) between two systems. These systems are designated as the primary and secondary nodes, with the primary node handling read/write operations.

Here’s how it operates:

  1. Storage Clustering: DRBD replicates the data on a block device from the primary node to the secondary node.

  2. Failover Mechanism: If the primary node fails, the secondary node can seamlessly take over by becoming the new primary.

  3. Data Integrity: The synchronization process ensures that the data remains consistent across nodes.

Using DRBD on CentOS

This guide focuses on configuring DRBD on CentOS 7 but is applicable to other CentOS versions.

Requirements

  • Two CentOS systems.

  • A free block device on each system, e.g., /dev/sdb1.

  • SELinux set to permissive or disabled.

  • Port 7788 open on the firewall.

  • Both nodes must be on the same network.

Installation Steps

  1. Add the EPEL Repository

    Install the ELRepo package since DRBD is not included in the default CentOS repositories:

    bash
    
    rpm -ivh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
    rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
                                        
  2. Install DRBD

    Use yum to install the DRBD package and kernel modules:

    bash
    
    yum -y install drbd84-utils kmod-drbd84
                                        
  3. Verify Kernel Module

    Check if the DRBD kernel module is loaded:

    bash
    
    lsmod | grep -i drbd
                                        

    If not loaded, reboot the system and load it manually:

    bash
    
    modprobe drbd
    echo drbd > /etc/modules-load.d/drbd.conf
                                        

Configuring DRBD

  1. Create a Resource File

    Resource files define the DRBD configuration. On both nodes, create a resource file, e.g., linuxhandbook.res:

    bash
    
    vi /etc/drbd.d/linuxhandbook.res
                                        

    Add the following configuration:

    plaintext
    
    resource linuxhandbook {
        protocol C;
        on node1 {
            device /dev/drbd0;
            disk /dev/sdb1;
            address 10.20.222.14:7788;
            meta-disk internal;
        }
        on node2 {
            device /dev/drbd0;
            disk /dev/sdb1;
            address 10.20.222.15:7788;
            meta-disk internal;
        }
    }
                                        
  2. Initialize Metadata

    Prepare the block devices for DRBD:

    bash
    
    drbdadm create-md linuxhandbook
                                        

    If errors occur, initialize the disk manually:

    bash
    
    dd if=/dev/zero of=/dev/sdb1 bs=1024k count=1024
                                        
  3. Attach Devices

    Attach the devices to the resource file:

    bash
    
    drbdadm attach linuxhandbook
                                        
  4. Start DRBD Service

    Enable and start the DRBD service:

    bash
    
    systemctl start drbd
    systemctl enable drbd
                                        

Setting Primary and Secondary Nodes

Designate one node as the primary for read/write operations:

bash

drbdadm primary linuxhandbook --force
                            

Verify the DRBD status:

bash

cat /proc/drbd
                            

Using DRBD

  1. Format the DRBD Device

    On the primary node, format the DRBD device:

    bash
    
    mkfs -t ext3 /dev/drbd0
                                        
  2. Mount the Device

    Mount the device to make it accessible:

    bash
    
    mount /dev/drbd0 /mnt
                                        
  3. Test Synchronization

    Create a test file on the primary node:

    bash
    
    touch /mnt/drbdtest.txt
    ls /mnt/
                                        

    Promote the secondary node to primary and verify the synchronization.

Manage DRBD with LCMC

For easier management, use the Linux Cluster Management Console (LCMC) to visualize and administer DRBD clusters.

By following this guide, you can effectively set up DRBD on your CentOS systems, ensuring high availability and disaster recovery for your critical data.

Conclusion

DRBD is a robust tool for achieving high availability and disaster recovery in Linux-based systems. By mirroring block devices between two nodes, it ensures data consistency and reliability, even in cases of hardware failure. Following this guide, you can successfully set up DRBD on CentOS, making your infrastructure more resilient and reliable. Whether for failover solutions or disaster recovery planning, DRBD provides a network-based alternative to shared storage that is both efficient and secure.

Discover iDatam Dedicated Server Locations

iDatam servers are available around the world, providing diverse options for hosting websites. Each region offers unique advantages, making it easier to choose a location that best suits your specific hosting needs.

Up