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
Using DRBD on CentOS
Installation Steps
Configuring DRBD
Setting Primary and Secondary Nodes
Using DRBD
Manage DRBD with LCMC
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:
-
Storage Clustering: DRBD replicates the data on a block device from the primary node to the secondary node.
-
Failover Mechanism: If the primary node fails, the secondary node can seamlessly take over by becoming the new primary.
-
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
-
Add the EPEL Repository
Install the ELRepo package since DRBD is not included in the default CentOS repositories:
bashrpm -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
-
Install DRBD
Use
yum
to install the DRBD package and kernel modules:bashyum -y install drbd84-utils kmod-drbd84
-
Verify Kernel Module
Check if the DRBD kernel module is loaded:
bashlsmod | grep -i drbd
If not loaded, reboot the system and load it manually:
bashmodprobe drbd echo drbd > /etc/modules-load.d/drbd.conf
Configuring DRBD
-
Create a Resource File
Resource files define the DRBD configuration. On both nodes, create a resource file, e.g.,
linuxhandbook.res
:bashvi /etc/drbd.d/linuxhandbook.res
Add the following configuration:
plaintextresource 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; } }
-
Initialize Metadata
Prepare the block devices for DRBD:
bashdrbdadm create-md linuxhandbook
If errors occur, initialize the disk manually:
bashdd if=/dev/zero of=/dev/sdb1 bs=1024k count=1024
-
Attach Devices
Attach the devices to the resource file:
bashdrbdadm attach linuxhandbook
-
Start DRBD Service
Enable and start the DRBD service:
bashsystemctl start drbd systemctl enable drbd
Setting Primary and Secondary Nodes
Designate one node as the primary for read/write operations:
drbdadm primary linuxhandbook --force
Verify the DRBD status:
cat /proc/drbd
Using DRBD
-
Format the DRBD Device
On the primary node, format the DRBD device:
bashmkfs -t ext3 /dev/drbd0
-
Mount the Device
Mount the device to make it accessible:
bashmount /dev/drbd0 /mnt
-
Test Synchronization
Create a test file on the primary node:
bashtouch /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.
iDatam Recommended Tutorials
Linux
Solving the 5 Most Common Linux Server Problems
Master the art of Linux server problem solving with this comprehensive guide. Learn how to diagnose and fix common server issues including network problems, disk space management, security vulnerabilities, and performance bottlenecks.
Mysql
How To Create a New User and Grant Permissions in MySQL
Learn how to create a new MySQL user and grant permissions with this comprehensive guide. Understand the essential commands, best practices, and troubleshooting tips for effective user and permission management in MySQL.
Control Panel, Security
Plesk Server Security Tutorial: A Step-by-Step Guide to Secure Your Web Infrastructure
Secure your Plesk server with our in-depth tutorial! Learn step-by-step techniques, from updates and advanced configurations to code-level protections and emergency strategies, to fortify your web infrastructure against potential threats.
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.