DRBD Cheat Sheet

DRBD Replication

DRBD is a distributed replicated storage system for the Linux platform. It is implemented as a kernel driver, several userspace management applications, and some shell scripts. This article describes about DRBD all administration commands.


Topic

  • How to use DRBD?
  • DRBD setup example
  • All DRBD reference commands


Solution


Create DRBD volume

  • Install DRBD package on cluster nodes.
# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# rpm -ivh http://elrepo.org/elrepo-release-7.0-4.el7.elrepo.noarch.rpm

# yum info *drbd* | grep Name
Name        : drbd84-utils
Name        : drbd84-utils-sysvinit
Name        : drbd90-utils
Name        : drbd90-utils-sysvinit
Name        : kmod-drbd84
Name        : kmod-drbd90

# yum install drbd90-utils kmod-drbd90

  • Load DRBD kernel module and auto load the module at boot time.
# modprobe drbd
# lsmod | grep -i drbd
drbd                  568697  0
libcrc32c              12644  2 xfs,drbd

# echo "modprobe drbd" >> /etc/rc.local 
# chmod 755 /etc/rc.local

Create DRBD volume resource

  • Edit common global configuration file on cluster nodes and make the following changes.
# cat /etc/drbd.d/global_common.conf
global {
 usage-count no;
}
common {
 net {
  protocol C;
 }
}

  • Create a volume resource configuration file on cluster nodes and make the following changes.
# cat /etc/drbd.d/mysql.res 
resource <Resource Name> {
startup {
}
disk { on-io-error detach; }
device      /dev/drbd0;
disk        /dev/sda;

on node1.example.local {
address     192.168.5.20:7788;
meta-disk   internal;
node-id     0;
}

on node2.example.local {
address     192.168.5.21:7788;
meta-disk   internal;
node-id     1;
}
}

  • Execute the following command on cluster nodes to add firewall rules for DRBD resource.
# firewall-cmd --add-port=7788/tcp --permanent
success
# firewall-cmd --reload
success

  • Enable DRBD resource and start DRBD service on cluster nodes.
# drbdadm up <Resource Name>
# systemctl start drbd
# systemctl enable drbd

  • Execute below command on cluster nodes to initialize the DRBD resource.
# drbdadm create-md <Resource Name>

  • Execute following command on one of the cluster node to make primary resource.
# drbdadm primary <Resource Name> --force

Verify DRBD Status

# drbdadm status
<Resource Name> role:Primary
  disk:UpToDate
  node1.example.local role:Secondary
    peer-disk:UpToDate

# drbdadm status
# drbdsetup status -vs
# cat /proc/drbd


Resize DRBD volume

  • Resize DRBD volume with resync.
# drbdadm resize <Resource Name>

Resize DRBD volume without resync

# drbdadm -- --assume-clean resize <Resource Name>

Resize DRBD filesystem

# resize2fs <DRBD volume path>


DRBD split brain Recovery

  • Execute the following command on one of the node.
# drbdadm disconnect <Resource Name>
# drbdadm secondary <Resource Name>
# drbdadm connect --discard-my-data <Resource Name>

  • Execute the following command on another node.
# drbdadm disconnect <Resource Name>
# drbdadm connect <Resource Name>


Switch DRBD resource mode

  • Change primary node mode to secondary.
# drbdadm secondary <Resource Name>

  • Change secondary node mode to primary.
# drbdadm primary <Resource Name>

Attach a DRBD resource

# drbdadm attach <Resource Name>

Detach a DRBD resource

# drbdadm detach <Resource Name>

Connect DRBD resource

# drbdadm connect <Resource Name>

Disconnect DRBD resource

# drbdadm disconnect <Resource Name>


DRBD Configuration

  • Set the syncer rate for a specific DRBD resource.
# drbdsetup <DRBD volume> syncer -r <rate>

  • View the current live configuration of a resource.
# drbdsetup <DRBD Volume> show

  • Adjust the configuration of a resource after made any changes in the configuration file.
# drbdadm adjust <Resource Name>


Interrupting the synchronization process on DRBD

  • Pause a currently running resynchronisation process:
# drbdadm pause-sync <Resource Name>

  • Resume the resynchronisation process:
# drbdadm resume-sync <Resource Name>


You May Also Like

About the Author: Andrew Joseph

4 Comments

  1. I was recommended this website by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my difficulty. You are wonderful! Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *