How to Install DRBD on nixOS Latest

Introduction

Distributed Replicated Block Device (DRBD) is a free, open-source software that allows two servers to share storage in real-time mode over a network. It can be used to build highly available (HA) clusters or redundant storage solutions.

However, installing DRBD can vary depending on the operating system you are using, and in this tutorial, we’ll walk you through the steps to install DRBD on the latest nixOS using the official DRBD site.

Prerequisites

Before installing DRBD on nixOS, you need the following:

Step 1: Installing DRBD

First, you will need to download and install DRBD packages from the official DRBD site. You can do this by following the steps below:

$ sudo su
# curl -sSL https://www.linbit.com/downloads/drbd/repo/rpm/drbd.repo | tee /etc/yum.repos.d/drbd.repo
# rpm --import https://www.linbit.com/downloads/drbd/linbit-167F52CB.asc
# yum install -y epel-release
# yum install -y kmod-drbd82 drbd82 drbd82-utils net-tools

These commands will add the DRBD repository to your server and install the DRBD packages.

Step 2: Configuring DRBD

Once DRBD is installed, you will need to modify some configuration files to complete the setup. Follow the steps below:

  1. Open the DRBD configuration file using your favorite text editor:
# vi /etc/drbd.conf
  1. Replace the existing content with the following code:
global {
 usage-count no;
}
common {
syncer {
  verify-alg sha1;
  rate 5M;
}
}
resource r0 {
device /dev/drbd0;
meta-disk internal;
on node1 {
address 192.168.1.1:7789;
  disk /dev/sdb;
  }
  on node2 {
address 192.168.1.2:7789;
disk /dev/sdb;
}
}

The configuration file above specifies the following:

Make sure to replace the IP addresses in the configuration file with the ones that correspond to your servers.

  1. Save and close the file.

Step 3: Initialize DRBD

Now that you have configured DRBD, you will need to initialize it.

  1. Start the DRBD service on both nodes:
# systemctl start drbd
  1. Create a meta-disk on both nodes:
# drbdadm create-md r0
  1. Activate the DRBD service on both nodes:
# drbdadm up r0
  1. Check the status of DRBD:
# drbdadm status r0

If everything is working correctly, you should see a status message indicating that DRBD is running.

Step 4: Testing DRBD

At this point, DRBD is ready to use. However, you should test the functionality to ensure that it works correctly.

  1. Create a file on the primary node:
# echo "Hello World" > /mnt/drbd/file.txt
  1. Check whether the file is on the primary node:
# cat /mnt/drbd/file.txt
  1. Fail-over to the secondary node:
# drbdadm primary r0 --force
  1. Check whether the file is on the secondary node:
# cat /mnt/drbd/file.txt

If the file exists on both nodes, then DRBD is set up correctly and is working correctly.

Conclusion

Now you have DRBD installed and configured on the latest nixOS, you can use it to build highly available clusters or redundant storage solutions. Before using DRBD in production, make sure to test it thoroughly to ensure that it works correctly.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!