DRBD : Install2024/05/03 |
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 458752 0 lru_cache 16384 1 drbd libcrc32c 12288 3 btrfs,drbd,raid456 # 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: 211FB288A383ED945B83420 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: 211FB288A383ED945B83420 0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r----- ns:392596 nr:0 dw:0 dr:394740 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:167373384 [>....................] sync'ed: 0.3% (163448/163832)M finish: 1:53:37 speed: 24,536 (24,536) 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: 211FB288A383ED945B83420 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----- ns:167765980 nr:0 dw:0 dr:167768124 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 392M 1.1M 391M 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv ext4 28G 6.1G 20G 24% / tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock /dev/vda2 ext4 2.0G 95M 1.7G 6% /boot tmpfs tmpfs 392M 12K 392M 1% /run/user/0 /dev/drbd0 ext4 157G 28K 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 May 3 06:37 ./ drwxr-xr-x 24 root root 4096 May 3 06:36 ../ drwx------ 2 root root 16384 May 3 06:36 lost+found/ -rw-r--r-- 1 root root 10 May 3 06:37 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 392M 1.1M 391M 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv ext4 28G 6.1G 20G 24% / tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock /dev/vda2 ext4 2.0G 95M 1.7G 6% /boot tmpfs tmpfs 392M 12K 392M 1% /run/user/0 /dev/drbd0 ext4 157G 32K 149G 1% /drbd_diskroot@node02:~# cat /drbd_disk/test.txt test file |
Sponsored Link |