DRBD : Install2026/04/28 |
|
Install DRBD (Distributed Replicated Block Device) to configure Distributed Storage System. +----------------------+ | +----------------------+ | [ 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 device 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:~# drbd 499712 0 lru_cache 16384 1 drbd # if UFW is enabled, allow ports root@node01:~# ufw allow 7788:7800/tcp Rule added Rule added (v6) # create DRBD resource root@node01:~# drbdadm create-md r0 initializing activity log initializing bitmap (5120 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: 0D106BD495E4B4E67834B98
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:167765980
# 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: 0D106BD495E4B4E67834B98
0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-----
ns:270328 nr:0 dw:0 dr:271664 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:167495652
[>....................] sync'ed: 0.2% (163568/163832)M
finish: 2:14:12 speed: 20,792 (20,792) K/sec
# when sync is complete, the status will be as follows root@node01:~# cat /proc/drbd
version: 8.4.11 (api:1/proto:86-101)
srcversion: 0D106BD495E4B4E67834B98
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:167765980 nr:0 dw:0 dr:167767316 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.ext4 /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 tmpfs tmpfs 680M 1.1M 679M 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv ext4 14G 5.7G 7.4G 44% / tmpfs tmpfs 1.7G 0 1.7G 0% /dev/shm none tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-journald.service none tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-resolved.service tmpfs tmpfs 1.7G 0 1.7G 0% /tmp /dev/vda2 ext4 2.0G 96M 1.7G 6% /boot none tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-networkd.service none tmpfs 1.0M 0 1.0M 0% /run/credentials/getty@tty1.service none tmpfs 1.0M 0 1.0M 0% /run/credentials/serial-getty@ttyS0.service tmpfs tmpfs 340M 8.0K 340M 1% /run/user/0 /dev/drbd0 ext4 157G 2.1M 149G 1% /drbd_disk # create a test file root@node01:~# echo 'test file' > /drbd_disk/test.txt root@node01:~# ll /drbd_disk total 28 drwxr-xr-x 3 root root 4096 Apr 28 03:19 ./ drwxr-xr-x 21 root root 4096 Apr 28 03:18 ../ drwx------ 2 root root 16384 Apr 28 03:18 lost+found/ -rw-r--r-- 1 root root 10 Apr 28 03:19 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 tmpfs tmpfs 680M 1.1M 679M 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv ext4 14G 5.7G 7.4G 44% / tmpfs tmpfs 1.7G 0 1.7G 0% /dev/shm none tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-journald.service none tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-resolved.service tmpfs tmpfs 1.7G 0 1.7G 0% /tmp /dev/vda2 ext4 2.0G 96M 1.7G 6% /boot none tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-networkd.service none tmpfs 1.0M 0 1.0M 0% /run/credentials/getty@tty1.service none tmpfs 1.0M 0 1.0M 0% /run/credentials/serial-getty@ttyS0.service tmpfs tmpfs 340M 8.0K 340M 1% /run/user/0 /dev/drbd0 ext4 157G 2.1M 149G 1% /drbd_diskroot@node02:~# cat /drbd_disk/test.txt test file |
| Sponsored Link |
|
|