15 C
Texas
angeloma
Senior Writer and partner

Install and configure DRBD on Debian 10

Replicating partitions is a great way to back up data in real-time. This is one of the most useful operations we can do as sysadmin as it can save us a lot of time. Imagine that a server has a lot of information and suddenly stops working. It would be a problem. However, if we are replicating all its information through the network there would be no need to be alarmed. So, in this post, I will explain how to install and configure DRBD on Debian 10.

0. What we need

First of all, we need two Debian 10 teams. Both must have a static IP address and a defined hostname. Also, they have a partition defined for replication of the same size. Then, be connected to the same network and that the Firewall allows connections through the DRBD network port. In short, this will be our environment.

Node 1:

  • IP address: 192.168.250.100
  • Hostname: osradar1
  • OS: Debian 10
  • Disk: /dev/sda
  • Partition to replicate: /dev/sda2

Node 2:

  • IP address: 192.168.250.110
  • Hostname: osradar2
  • OS: Debian 10
  • Disk: /dev/sda
  • Partition to replicate: /dev/sda2
- Advertisement -

Each node must have a /dev/sda2/ partition of at least several GB in size.

1) Install DRBD on Debian 10

DRBD is available in the official repositories of the distribution. So the installation is not complicated.

On both nodes, run the following command:

:~$ sudo apt install drbd-utils

Of course, DRBD incorporates a module that has to be loaded into the kernel. In both nodes, it has to be loaded. To do this, run the following command:

:~$ sudo modprobe drbd

Then, check the module was added.

:~$ lsmod | grep drbd

1.- check the drbd module
1.- check the drbd module

2) Configure DRBD

The package is already installed and the module loaded to the kernel. Now it remains to make the appropriate settings for the replication to be a success.

DRBD has the particularity of being flexible, that is, the configuration file has many options that we can manipulate and adapt to our needs.

However, it is recommended to make a backup of the configuration file before starting to work on it.

:~$ sudo cp /etc/drbd.conf /etc/drbd.conf.bak

Then, erase the entire file.

:~$ sudo cat /dev/null > /etc/drbd.conf

Now, you need to edit the configuration file:

:~$ sudo nano /etc/drbd.conf

And add the following:

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 osradar1 {
                device /dev/drbd0;
                disk /dev/sda2;
                address 192.168.250.100:7788;
                meta-disk internal;
        }
        on osradar2 {
                device /dev/drbd0;
                disk /dev/sda2;
                address 192.168.0.110:7788;
                meta-disk internal;
        }
}

2.- Install DRBD on Debian 10
2.- Install DRBD on Debian 10

The truth is that I think that many of the options are very explicit but I will briefly explain the most important ones.

In global and common some global configurations are defined to both nodes and resources.

Then, in the resource section, we define the name. In this case r0, of course, you can modify it. Next, in protocol, startup, and net, specific configurations to the resource.

Then, there is the configuration in each node identified by the hostname. In each of them, we define the DRBD device and the partition we are going to replicate (disk). Also, the IP address of the node as well as the communication port.

As you can see it is not very complex or long to understand.

3) Start DRBD on Debian 10

Remember this same file must be on both nodes. Then, in both nodes run the following commands to start the DRBD service.

:~$ sudo systemctl stop drbd
:~$ sudo drbdadm create-md r0
:~$ sudo drbdadm attach r0

Remember that isr0 the name of the resource. You can change it in the configuration file.

After that, you can start the service.

:~$ sudo systemctl start drbd

And set which node will be the master. In this case, the node1 will be the master. So, in the node1 run this command:

:~$ sudo drbdadm -- --overwrite-data-of-peer primary all

With that, we should have an effective replication. It would be enough to create a new file system and mount it.

:~$ sudo mkfs.ext4 /dev/drbd0
:~$ sudo mkdir /testdata
:~$ sudo mount /dev/drbd0 /testdata

There, you can create new files. And that is it.

If you want more post about Debian 10, please click here.

Please share this post with your friends and join our Telegram Channel.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article