The goal of this post is to set up an architecture composed of two nodes that can both simultaneously have read/write access to a synchronized partition. Each node will access the synchronized partition as any other classical partition, the only difference is that every modification will also be forwarded to the other node.
DRBD8 configuration file
System requirements
[tux]# apt-get update
[tux]# apt-get install linux-image-2.6.24-etchnhalf.1-686
[tux]# apt-get install linux-headers-2.6.24-etchnhalf.1-686
[tux]# reboot
Configuration requirements
[tux]# vi /etc/hosts
192.168.9.xx hostname1.domain.org hostname1
192.168.9.xx hostname2.domain.org hostname2
Update your source list to be able to get packages from debian backports
deb http://www.backports.org/debian etch-backports main contrib non-free
[tux]# apt-get install debian-backports-keyring
[tux]# apt-get update
Install DRBD8
[tux]# apt-get install drbd8-source drbd8-utils
[tux]# module-assistant auto-install drbd8
Prepare the partition that will be synchronized thanks to DRBD
[tux]# fdisk -l Disk /dev/sda: 6442 MB, 6442450944 bytes 255 heads, 63 sectors/track, 783 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 743 5968116 83 Linux /dev/sda2 744 783 321300 5 Extended /dev/sda5 744 783 321268+ 82 Linux swap / Solaris Disk /dev/sdb: 1073 MB, 1073741824 bytes 255 heads, 63 sectors/track, 130 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk /dev/sdb doesn't contain a valid partition table
[tux]# fdisk /dev/sdb Command (m for help): n Command action e extended p primary partition (1-4) e Partition number (1-4): 1 First cylinder (1-130, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-130, default 130): Using default value 130 Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First cylinder (1-130, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-130, default 130): Using default value 130 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
[tux]# fdisk -l /dev/sdb Disk /dev/sdb: 1073 MB, 1073741824 bytes 255 heads, 63 sectors/track, 130 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 130 1044193+ 5 Extended /dev/sdb5 1 130 1044162 83 Linux
Configure DRBD8
on hostname1 { device /dev/drbd0; disk /dev/sdb5; address 192.168.9.xx:7789; meta-disk internal; } on hostname2 { device /dev/drbd0; disk /dev/sdb5; address 192.168.9.xx:7789; meta-disk internal; }
Create DRBD resource
[tux]# drbdadm create-md r0 You want me to create a v08 style flexible-size internal meta data block. There apears to be a v08 flexible-size internal meta data block already in place on /dev/sdb5 at byte offset 106917888 Do you really want to overwrite the existing v08 meta-data? [need to type 'yes' to confirm] yes Writing meta data... initialising activity log NOT initialized bitmap New drbd meta data block sucessfully created.
[tux]# drbdadm create-md r0 md_offset 1069215744 al_offset 1069182976 bm_offset 1069150208 Found ext3 filesystem which uses 1044160 kB current configuration leaves usable 1044092 kB Device size would be truncated, which would corrupt data and result in 'access beyond end of device' errors. You need to either * use external meta data (recommended) * shrink that filesystem first * zero out the device (destroy the filesystem) Operation refused. Command 'drbdmeta /dev/drbd0 v08 /dev/sdb5 internal create-md' terminated with exit code 40 drbdadm aborting
[tux]# e2fsck -f /dev/sdb5 && resize2fs /dev/sdb5 1044092K
[tux]# dd if=/dev/zero of=/dev/sdb5
[tux]# drbdadm create-md r0
Start DRBD8 and ensure it works correctly
[hostname1]# /etc/init.d/drbd start
[hostname2]# /etc/init.d/drbd start
[hostname1]# drbdadm attach r0
[hostname1]# drbdadm connect r0
[hostname2]# drbdadm attach r0
[hostname2]# drbdadm connect r0
[hostame1]# drbdsetup /dev/drbd0 primary -o
[hostname1]# /etc/init.d/drbd status drbd driver loaded OK; device status: version: 8.0.13 (api:86/proto:86) GIT-hash: ee3ad77563d2e87171a3da17cc002ddfd1677dbe build by phil@fat-tyre, 2008-08-04 15:28:07 m:res cs st ds p mounted fstype ... sync'ed: 20.8% (830012/1044092)K 0:r0 SyncSource Primary/Secondary UpToDate/Inconsistent C
[hostame2]# drbdadm primary r0
[tux]# /etc/init.d/drbd status drbd driver loaded OK; device status: version: 8.0.13 (api:86/proto:86) GIT-hash: ee3ad77563d2e87171a3da17cc002ddfd1677dbe build by phil@fat-tyre, 2008-08-04 15:28:07 m:res cs st ds p mounted fstype 0:r0 Connected Primary/Primary UpToDate/UpToDate C
[hostname1]# mke2fs -j /dev/drbd0
[hostname1]# mkdir /synchronized
[hostname2]# mkdir /synchronized
[hostname1]# mount /dev/drbd0 /synchronized
[hostname2]# mount /dev/drbd0 /synchronized
[tux] # mount /dev/drbd0 /synchronized/
mount: you must specify the filesystem type
[hostname1]# /etc/init.d/drbd status drbd driver loaded OK; device status: version: 8.0.13 (api:86/proto:86) GIT-hash: ee3ad77563d2e87171a3da17cc002ddfd1677dbe build by phil@fat-tyre, 2008-08-04 15:28:07 m:res cs st ds p mounted fstype 0:r0 Connected Primary/Primary UpToDate/UpToDate C /synchronized ext3
[hostname1]# touch /synchronized/from_host1
[hostname2]# touch /synchronized/from_host2
[hostname1]# ls /synchronized
lost+found from_host1
[hostname2]# ls /synchronized
lost+found from_host2
Other considerations
You have to keep in mind that there is no integrity guaranty between the two machines. Therefore we are in any case force to implement a lock mechanism to avoid data corruption. DRBD8 deals only with synchronization between nodes. In order to circumvent this drawback, the DRBD synchronized partition must use a specific file system like GFS2 for example if you want to see modifications from both nodes almost in real time. A next post will go into further details and explain how to build a shared nothing architecture between two nodes using DRBD8 + GFS2 on debian etch. I can already claim this time it will work as expected, so do not become discouraged.
评论