DRBD (Distributed Replicated Block Device) is a block-level data replication software that runs on Linux operating systems. It enables data mirroring between two or more host servers connected through a network, providing high availability and disaster recovery capabilities for critical applications.
In this tutorial, we will show you how to install and configure DRBD on Linux Mint latest version.
Before installing any new software, it is essential to update the system to the latest version. Open the terminal and run the following command:
sudo apt update && sudo apt upgrade -y
This command will update the package lists and install any pending updates.
DRBD is implemented as a kernel module in Linux. To install it, run the following command:
sudo apt install -y drbd-dkms
This command will download the necessary packages and compile the DRBD kernel module on the system.
After installing the DRBD kernel module, we need to configure it for our system. In this tutorial, we will set up a simple two-node DRBD cluster.
Create a new file /etc/drbd.d/myresource.res
using any text editor:
sudo nano /etc/drbd.d/myresource.res
Add the following content to the file:
resource myresource {
protocol C;
startup {
wfc-timeout 15;
degr-wfc-timeout 60;
}
disk {
on-io-error detach;
}
net {
cram-hmac-alg "sha1";
shared-secret "mysecret";
}
syncer {
rate 100M;
}
on node1 {
device /dev/drbd0;
disk /dev/sda1;
address 192.168.1.10:7788;
meta-disk internal;
}
on node2 {
device /dev/drbd0;
disk /dev/sda1;
address 192.168.1.20:7788;
meta-disk internal;
}
}
Here's what each parameter means:
myresource
: The name of the resource that will be mirrored.protocol
: The DRBD protocol to use. In this case, we use protocol C.startup
: The startup options for the resource.disk
: The disk configuration for the resource.net
: The network configuration for the resource.syncer
: The syncer configuration for the resource.on node1
: The configuration for the first node.device
: The DRBD device that will be used.disk
: The physical disk to replicate.address
: The IP address and port to use for communication with the second node.meta-disk
: The meta-disk storage location.Save and close the file.
To start the DRBD service, run the following commands:
sudo modprobe drbd
sudo systemctl enable drbd
sudo systemctl start drbd
These commands will load the DRBD kernel module, enable the service and start it.
On the first node, initialize the DRBD device with the following command:
sudo drbdadm create-md myresource
This command will create metadata for the DRBD device.
Start the DRBD device:
sudo drbdadm up myresource
After starting the device, check the DRBD status:
sudo drbdadm status
You should see something like this:
myresource role:Secondary
disk:UpToDate/UpToDate
node1 <--> node2 sync'ed:100.00%
The Secondary
role indicates that the node is not the primary node for the resource. The sync'ed
field should show 100%
once replication is complete.
On the first node, promote the DRBD device to the primary node:
sudo drbdadm primary --force myresource
This command will make the current node the primary node for the DRBD resource.
On the first node, check the DRBD status again:
sudo drbdadm status
You should see something like this:
myresource role:Primary
disk:UpToDate/UpToDate
node1 <--> node2 sync'ed:100.00%
The Primary
role indicates that the node is the primary node for the resource.
On the first node, format the DRBD device and mount it:
sudo mkfs.ext4 /dev/drbd0
sudo mount /dev/drbd0 /mnt
This command will format the DRBD device with the EXT4 file system and mount it on /mnt
.
On the first node, create a test file on the mounted directory:
echo "hello world" > /mnt/test
On the second node, check if the file exists:
ls /mnt/test
You should see the file test
on the second node.
In this tutorial, we showed you how to install and configure DRBD on Linux Mint. With DRBD, you can create a highly available and redundant data storage system for your critical applications.
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!