Distributed Replicated Block Device is a great way to replicate filesystem over the network to another server or host. Distributed Replicated Block Device actually mirrors a whole block device over the network therefore it is often used for High Availability (HA) clusters. Distributed Replicated Block Device is actually a network based RAID 1.
Distributed Replicated Block Device has a number of advantages over a conventional shared storage solutions – read more HERE.
REQUIREMENTS:
- additional disk for synchronization on BOTH MACHINES (preferably same size)
- network connectivity between machines
- working DNS resolution (can fix with /etc/hosts file)
- NTP synchronized times on both nodes
Let’s configure DRBD on Ubuntu Server 12.04!
1. Install following package (BOTH NODES)
root@foo1:~# apt-get install python-software-properties
root@foo2:~# apt-get install python-software-properties
2. Add PPA reporitory for DRBD (BOTH NODES)
Since the Distributed Replicated Block Device kernel module shipped with latest Ubuntu Server 12.04 is 8.4.2 version and only available Distributed Replicated Block Device utils from Ubuntu repositories are 8.3 version (did not get it to work) we need to add a Personal Package Archive to get the 8.4.3 version of Distributed Replicated Block Device utils.
root@foo1:~# add-apt-repository ppa:icamargo/drbd
root@foo2:~# add-apt-repository ppa:icamargo/drbd
1. Update repo information (BOTH NODES)
root@foo1:~# apt-get update
root@foo2:~# apt-get update
2. Install required packages (BOTH NODES)
root@foo1:~# apt-get install drbd8-utils
root@foo2:~# apt-get install drbd8-utils
3. Insert module (BOTH NODES)
root@foo1:~# modprobe drbd root@foo1:~# lsmod |grep drbd drbd 273218 0 lru_cache 14731 1 drbd libcrc32c 12543 1 drbd
root@foo2:~# modprobe drbd root@foo2:~# lsmod |grep drbd drbd 273218 0 lru_cache 14731 1 drbd libcrc32c 12543 1 drbd
4. Create resource configuration file (BOTH NODES)
We need to create Distributed Replicated Block Device resource configuration file where we define the disks we want to replicate and both nodes IP address and hostname. The newly created resource configuration file must be located at /etc/drbd.d/ directory and have .res file extension. Resource configuration files must be the same on both Distributed Replicated Block Device nodes – we will copy it in our next step! Our resource file /etc/drbd.d/disk1.res is as follows:
resource disk1 { startup { wfc-timeout 30; outdated-wfc-timeout 20; degr-wfc-timeout 30; } net { cram-hmac-alg sha1; shared-secret sync_disk; } syncer { rate 100M; verify-alg sha1; } on foo1.geekpeek.net { # Node1 defined device /dev/drbd0; disk /dev/sdb; # Device to use with DRBD address 192.168.1.100:7789; # IP Address and port of Node1 meta-disk internal; } on foo2.geekpeek.net { # Node2 defined device /dev/drbd0; disk /dev/sdb; # Device to use with DRBD address 192.168.1.101:7789; # IP Address and port of Node2 meta-disk internal; } }
5. Edit /etc/hosts file (BOTH NODES)
If you do not have a working DNS resolution edit your hosts file and enter the IP address and FQDN of both nodes!
192.168.1.100 foo1 foo1.geekpeek.net 192.168.1.101 foo2 foo2.geekpeek.net
6. Configure NTP synchronization (BOTH NODES)
Put this in your /etc/crontab file:
1 * * * * root ntpdate your.ntp.server
7. Initialize meta data (BOTH NODES)
root@foo1:~# drbdadm create-md disk1
root@foo2:~# drbdadm create-md disk1
8. Start services (BOTH NODES)
root@foo1:~# /etc/init.d/drbd start
root@foo2:~# /etc/init.d/drbd start
You might get a warning that versions of module and userland are not matching – as long as Distributed Replicated Block Device resource is up and connected it is OK.
9. Check resource
Check if DRBD resource “disk1” is up and connected.
root@foo1:~# cat /proc/drbd version: 8.4.2 (api:1/proto:86-101) srcversion: 18C7EBE1B3F8CCCB5CF512C 0: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r----- ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:1048508
10. Make one node primary
We need to make one Distributed Replicated Block Device node primary and wait for synchronization.
root@foo1:~# drbdadm -- --overwrite-data-of-peer primary all
root@foo1:~# cat /proc/drbd version: 8.4.2 (api:1/proto:86-101) srcversion: 18C7EBE1B3F8CCCB5CF512C 0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r---n- ns:262000 nr:0 dw:0 dr:269976 al:0 bm:15 lo:1 pe:2 ua:8 ap:0 ep:1 wo:f oos:788412 [====>...............] sync'ed: 25.0% (788412/1048508)K finish: 0:00:09 speed: 86,696 (86,696) K/sec
root@foo1:~# cat /proc/drbd version: 8.4.2 (api:1/proto:86-101) srcversion: 18C7EBE1B3F8CCCB5CF512C 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----- ns:1048508 nr:0 dw:0 dr:1049172 al:0 bm:64 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
11. Make filesystem on primary node
root@foo1:~# mkfs.ext4 /dev/drbd0
12. Mount disk on primary node
root@foo1:~# mount /dev/drbd0 /mnt/ root@foo1:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 7.3G 1008M 5.9G 15% / udev 240M 4.0K 240M 1% /dev tmpfs 100M 288K 99M 1% /run none 5.0M 8.0K 5.0M 1% /run/lock none 248M 0 248M 0% /run/shm /dev/drbd0 992M 1.3M 940M 1% /mnt
We are now replicating /dev/drbd0 to our second machine foo2.geekpeek.net. In order to mount /dev/drbd0 on the second node we must switch primary -> secondary and secondary -> primary and then mount device.
5 Comments
Leave a ReplyOne Ping
Pingback: Part 2: Setting up HA Storage using DRBD | dea.nbird.com.au