How to installing and configuring DRBD

Introduction

Learn how to install and configure DRBD (Distributed Replicated Block Device) on two Linux nodes for high availability. This step-by-step guide ensures your data is secure and replicated across servers.

In today's digital age, ensuring the availability and redundancy of data is crucial for maintaining a robust IT infrastructure. One powerful tool that system administrators rely on for this purpose is DRBD (Distributed Replicated Block Device). DRBD allows you to mirror the content of block devices, such as hard drives, between servers over a network. This ensures that if one server fails, the other can take over without any data loss.

This guide will walk you through the process of installing and configuring DRBD on two Linux nodes. By the end of this tutorial, you will have a fully functional DRBD setup that can be used to enhance the reliability and availability of your data.

Installation Environment

  • Node 1:

    • FQDN: node1.huuphan.local
    • HDD1: 10GB (/dev/sda1)
    • HDD2: 1GB (/dev/sdb1)
  • Node 2:

    • FQDN: node2.huuphan.local
    • HDD1: 10GB (/dev/sda1)
    • HDD2: 1GB (/dev/sdb1)

Note: The device /dev/sdb on both nodes is unpartitioned.

Step 1: Disable SELinux

To disable SELinux, run the following command on both nodes:

sed -i 's/SELINUX=enforcing/SELINUX=disable/' /etc/sysconfig/selinux

Step 2: Install NTP

Synchronize time between the two nodes by installing NTP:

yum install ntp ntpdate -y

Step 3: Configure Firewall

Open port 7788 on both nodes to allow DRBD communication:

iptables -I eth1 -m state --state NEW -m tcp -p tcp --dport 7788 -j ACCEPT service iptables save

Step 4: Configure /etc/hosts File

Add the following lines to the /etc/hosts file to map IP addresses to domain names:

vim /etc/hosts
172.16.235.145 node1.huuphan.local node1 172.16.235.146 node2.huuphan.local node2

Step 5: Create Partition for /dev/sdb1

Follow these steps on both nodes to create the /dev/sdb1 partition:

fdisk /dev/sdb

Execute the following commands in fdisk:

Command (m for help): n Command action p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-783, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-783, default 783): Using default value 783 Command (m for help): w

Step 6: Install and Configure DRBD

Install DRBD on both nodes:

rpm -ivh http://elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm yum -y install drbd84-utils.x86_64 kmod-drbd84.x86_64

Load the DRBD module:

modprobe drbd

Verify that the DRBD module is loaded:

lsmod | grep drbd

Step 7: Configure drbd.conf File

On Node 1, back up and configure the drbd.conf file:

cp /etc/drbd.conf /etc/drbd.conf_orig cat /dev/null > /etc/drbd.conf vim /etc/drbd.conf

Add the following content to drbd.conf:

global { usage-count no; } common { syncer { rate 100M; } } resource r0 { protocol C; startup { wfc-timeout 15; degr-wfc-timeout 60; } net { cram-hmac-alg sha1; shared-secret "secret"; } on node1.huuphan.local { device /dev/drbd0; disk /dev/sdb1; address 172.16.235.145:7788; meta-disk internal; } on node2.huuphan.local { device /dev/drbd0; disk /dev/sdb1; address 172.16.235.146:7788; meta-disk internal; } }

Copy the configuration file to Node 2:

scp /etc/drbd.conf node2:/etc/

Step 8: Initialize and Sync Data

Initialize the metadata for DRBD:

drbdadm create-md r0 /etc/init.d/drbd start

Set Node 1 as the primary and start data synchronization:

drbdadm -- --overwrite-data-of-peer primary all

On Node 2, monitor the synchronization status:

watch cat /proc/drbd

Step 9: Mount and Verify Data

On Node 1, format the DRBD device and mount it:

mkfs.ext4 /dev/drbd0 mkdir /data mount /dev/drbd0 /data touch /data/test1.txt umount /data

Set Node 1 to secondary:

drbdadm secondary r0

On Node 2, switch to primary and verify the data:

drbdadm primary r0 mkdir /data mount /dev/drbd0 /data ls -l /data/

Common Errors

If you encounter an error when mounting:

mount -t ext4 /dev/drbd0 /data mount: block device /dev/drbd0 is write-protected, mounting read-only mount: Wrong medium type

This indicates that the Primary/Secondary mode is functioning correctly. To enable Dual-Primary mode, further configuration is required.

Conclusion

Through these steps, we have successfully set up DRBD between two nodes, laying a solid foundation for building high-availability systems. Thank you for reading the huuphan.com page!

Comments

Popular posts from this blog

zimbra some services are not running [Solve problem]

Bash script list all IP addresses connected to Server with Country Information

Zimbra Client host rejected Access denied fixed