Debian 12 bookworm
Sponsored Link

DRBD : Install2023/08/29

 

Install DRBD (Distributed Replicated Block Device) to configure Distributed Storage System.
This example is based on the environment like follows.

+----------------------+          |          +----------------------+
| [   DRBD Server#1  ] |10.0.0.51 | 10.0.0.52| [   DRBD Server#2  ] |
|   node01.srv.world   +----------+----------+   node02.srv.world   |
|                      |                     |                      |
+----------------------+                     +----------------------+

It needs that the server you'd like to install DRBD has free block-device.
[1] Install and Configure DRBD on all Nodes.
root@node01:~#
apt -y install drbd-utils
root@node01:~#
vi /etc/drbd.d/r0.res
# create new : file name ⇒ (resource name).res

resource r0 {
    net {
    	# A : write completion is determined when data is written to the local disk and the local TCP transmission buffer
        # B : write completion is determined when data is written to the local disk and remote buffer cache
        # C : write completion is determined when data is written to both the local disk and the remote disk
        protocol C;
        cram-hmac-alg sha1;
        # any secret key for authentication among nodes
        shared-secret "MySharedSecret";
    }
    disk {
    	# possible to limit bandwidth for sync (example is 10MB/sec)
        resync-rate 10M;
    }
    # on (hostname)
    on node01.srv.world {
    address 10.0.0.51:7788;
        volume 0 {
            # device name
            device /dev/drbd0;
            # specify disk to be used for devide above
            disk /dev/sdb1;
            # where to create metadata
            # specify the block device name when using a different disk
            meta-disk internal;
        }
    }
    on node02.srv.world {
        address 10.0.0.52:7788;
        volume 0 {
            device /dev/drbd0;
            disk /dev/sdb1;
            meta-disk internal;
        }
    }
}

# load module

root@node01:~#
modprobe drbd

root@node01:~#
lsmod | grep drbd

drbd                  425984  0
lru_cache              16384  1 drbd
libcrc32c              16384  1 drbd

# create DRBD resource

root@node01:~#
drbdadm create-md r0

initializing activity log
initializing bitmap (2560 KB) to all zero
Writing meta data...
New drbd meta data block successfully created.

root@node01:~#
systemctl enable --now drbd

[2] After configuring on all Nodes, Sync data on a Node.
# current status is [Secondary/Secondary]

root@node01:~#
cat /proc/drbd

version: 8.4.11 (api:1/proto:86-101)
srcversion: 0ACE0C074EBC10D79EE52CB
 0: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r-----
    ns:0 nr:0 dw:0 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:83882460

# UP DRBD resource

root@node01:~#
drbdadm up r0
# get primary role and sync data

root@node01:~#
drbdadm -- --overwrite-data-of-peer primary r0
# data sync starts

root@node01:~#
cat /proc/drbd

version: 8.4.11 (api:1/proto:86-101)
srcversion: 0ACE0C074EBC10D79EE52CB
 0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-----
    ns:1494016 nr:0 dw:0 dr:1494016 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:82388444
        [>....................] sync'ed:  1.8% (80456/81916)M
        finish: 0:36:57 speed: 37,144 (30,488) K/sec

# when the sync is complete, the status will be as follows

root@node01:~#
cat /proc/drbd

version: 8.4.11 (api:1/proto:86-101)
srcversion: 0ACE0C074EBC10D79EE52CB
 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
    ns:83882460 nr:0 dw:0 dr:83882460 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[3] That's OK. After that, you can use it by creating a file system on the DRBD device and mounting it on the primary side.
root@node01:~#
mkfs.xfs /dev/drbd0

root@node01:~#
mkdir /drbd_disk

root@node01:~#
mount /dev/drbd0 /drbd_disk

root@node01:~#
df -hT

Filesystem                  Type      Size  Used Avail Use% Mounted on
udev                        devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                       tmpfs     392M  564K  391M   1% /run
/dev/mapper/debian--vg-root ext4       28G  1.3G   26G   5% /
tmpfs                       tmpfs     2.0G     0  2.0G   0% /dev/shm
tmpfs                       tmpfs     5.0M     0  5.0M   0% /run/lock
/dev/vda1                   ext2      455M   58M  373M  14% /boot
tmpfs                       tmpfs     392M     0  392M   0% /run/user/0
/dev/drbd0                  ext4       79G   24K   75G   1% /drbd_disk

# create a test file

root@node01:~#
echo 'test file' > /drbd_disk/test.txt

root@node01:~#
ll /drbd_disk

total 20
drwx------ 2 root root 16384 Aug 28 19:53 lost+found
-rw-r--r-- 1 root root    10 Aug 28 19:55 test.txt
[4] To mount DRBD device on the secondary Host, do it like follows.
# on primary host
# unmount drbd device and set secondary

root@node01:~#
umount /drbd_disk

root@node01:~#
drbdadm secondary r0
# on secondary host
# set primary and mount drbd device

root@node02:~#
drbdadm primary r0

root@node02:~#
mount /dev/drbd0 /drbd_disk

root@node02:~#
df -hT

Filesystem                  Type      Size  Used Avail Use% Mounted on
udev                        devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                       tmpfs     392M  548K  391M   1% /run
/dev/mapper/debian--vg-root ext4       28G  1.3G   26G   5% /
tmpfs                       tmpfs     2.0G     0  2.0G   0% /dev/shm
tmpfs                       tmpfs     5.0M     0  5.0M   0% /run/lock
/dev/vda1                   ext2      455M   58M  373M  14% /boot
tmpfs                       tmpfs     392M     0  392M   0% /run/user/0
/dev/drbd0                  ext4       79G   28K   75G   1% /drbd_disk

root@node02:~#
cat /drbd_disk/test.txt

test file
Matched Content