drbd 설정하기

vm1, vm2 서버의 /dev/hda5 파티션을 drbd로 구성하는 예제.

 

1. drbd 패키지 설치

yum install drbd83
yum install kmod-drbd83

—————————————————————————————————————

 

2. drbd.conf 파일 설정

[root@vm1 drbd.d]# cat /etc/drbd.conf
#
# please have a a look at the example configuration file in
# /usr/share/doc/drbd83/drbd.conf
#
include “drbd.d/global_common.conf”;
include “drbd.d/*.res”;
[root@vm1 drbd.d]# cat /etc/drbd.d/global_common.conf
# please have a a look at the example configuration file in
# /usr/share/doc/drbd83/drbd.conf
#
global { usage-count yes; }
common { syncer { rate 10M; } }

resource jook {
protocol C;
disk { on-io-error detach; }
syncer {
}

on vm1.jook.pe.kr {
device     /dev/drbd0;
disk       /dev/hda5;
address   192.168.122.10:7788;
flexible-meta-disk internal;
}

on vm2.jook.pe.kr {
device    /dev/drbd0;
disk      /dev/hda5;
address   192.168.122.20:7788;
meta-disk internal;
}

}
[root@vm1 drbd.d]#
[root@vm2 /]# cat /etc/drbd.conf
#
# please have a a look at the example configuration file in
# /usr/share/doc/drbd83/drbd.conf
#
include “drbd.d/global_common.conf”;
include “drbd.d/*.res”;
[root@vm2 /]# cat /etc/drbd.d/global_common.conf
# please have a a look at the example configuration file in
# /usr/share/doc/drbd83/drbd.conf
#
global { usage-count yes; }
common { syncer { rate 10M; } }

resource jook {
protocol C;
disk { on-io-error detach; }
syncer {
}

on vm1.jook.pe.kr {
device     /dev/drbd0;
disk       /dev/hda5;
address   192.168.122.10:7788;
flexible-meta-disk internal;
}

on vm2.jook.pe.kr {
device    /dev/drbd0;
disk      /dev/hda5;
address   192.168.122.20:7788;
meta-disk internal;
}

}
[root@vm2 /]#

—————————————————————————————————————

 

3. meta data 생성
[root@vm1 drbd.d]# drbdadm create-md all
md_offset 929419264
al_offset 929386496
bm_offset 929357824

Found ext3 filesystem
907576 kB data area apparently used
907576 kB left usable by current configuration

Even though it looks like this would place the new meta data into
unused space, you still need to confirm, as this is only a guess.

Do you want to proceed?
[need to type ‘yes’ to confirm] yes

You want me to create a v08 style flexible-size internal meta data block.
There appears to be a v08 flexible-size internal meta data block
already in place on /dev/hda5 at byte offset 929419264
Do you really want to overwrite the existing v08 meta-data?
[need to type ‘yes’ to confirm] yes

Writing meta data…
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.

 

[root@vm2 drbd.d]# drbdadm create-md all
md_offset 929419264
al_offset 929386496
bm_offset 929357824

Found ext3 filesystem
907576 kB data area apparently used
907576 kB left usable by current configuration

Even though it looks like this would place the new meta data into
unused space, you still need to confirm, as this is only a guess.

Do you want to proceed?
[need to type ‘yes’ to confirm] yes

You want me to create a v08 style flexible-size internal meta data block.
There appears to be a v08 flexible-size internal meta data block
already in place on /dev/hda5 at byte offset 929419264
Do you really want to overwrite the existing v08 meta-data?
[need to type ‘yes’ to confirm] yes

Writing meta data…
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
[root@vm2 drbd.d]#

—————————————————————————————————————

 

4. drbd 데몬 실행

[root@vm1 drbd.d]# service drbd start
Starting DRBD resources: [
jook
Found valid meta data in the expected location, 929419264 bytes into /dev/hda5.
d(jook) s(jook) n(jook) ]……….
***************************************************************
DRBD’s startup script waits for the peer node(s) to appear.
– In case this node was already a degraded cluster before the
reboot the timeout is 0 seconds. [degr-wfc-timeout]
– If the peer was available before the reboot the timeout will
expire after 0 seconds. [wfc-timeout]
(These values are for resource ‘jook’; 0 sec -> wait forever)
To abort waiting enter ‘yes’ [  12]:
.
[root@vm1 drbd.d]#

[root@vm2 drbd.d]# service drbd start
Starting DRBD resources: [
jook
Found valid meta data in the expected location, 929419264 bytes into /dev/hda5.
d(jook) s(jook) n(jook) ].
[root@vm2 drbd.d]#

—————————————————————————————————————

 

5. Disk Sync

primary 서버에서만 실행
[root@vm1 drbd.d]# drbdadm — –overwrite-data-of-peer primary all
[root@vm1 drbd.d]# cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r—-
ns:281600 nr:0 dw:0 dr:281600 al:0 bm:17 lo:32 pe:0 ua:32 ap:0 ep:1 wo:b oos:625976
[=====>…………..] sync’ed: 31.6% (625976/907576)K delay_probe: 52
finish: 0:00:57 speed: 10,964 (10,428) K/sec

[root@vm2 drbd.d]# cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
0: cs:SyncTarget ro:Secondary/Primary ds:Inconsistent/UpToDate C r—-
ns:0 nr:353664 dw:353280 dr:0 al:0 bm:21 lo:13 pe:20 ua:12 ap:0 ep:1 wo:b oos:554296
[======>………….] sync’ed: 39.2% (554296/907576)K queue_delay: 0.1 ms
finish: 0:00:48 speed: 11,336 (10,388) want: 10,240 K/sec
[root@vm2 drbd.d]#
—————————————————————————————————————

 

6. 상태 확인

[root@vm1 drbd.d]# cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r—-
ns:907576 nr:0 dw:0 dr:907576 al:0 bm:56 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
[root@vm1 drbd.d]#

[root@vm2 /]# cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r—-
ns:36 nr:938728 dw:938764 dr:93 al:1 bm:57 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
[root@vm2 /]#

—————————————————————————————————————

 

7. 파일시스템 생성, 쓰기 테스트

[root@vm1 drbd.d]# mkfs.ext3 /dev/drbd0
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
113568 inodes, 226894 blocks
11344 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=234881024
7 block groups
32768 blocks per group, 32768 fragments per group
16224 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@vm1 drbd.d]#
[root@vm1 drbd.d]# mount /dev/drbd0  /mnt/
[root@vm1 mnt]# touch a b c d e
[root@vm1 mnt]# ls
a  b  c  d  e  lost+found
[root@vm1 mnt]# cd
[root@vm1 ~]# umount /mnt/

—————————————————————————————————————

 

8. secondary 서버에서 마운트 하기 위해서는 primary를 secondary로 변경, secondary를 primary로 변경 한 후 mount 가능

[root@vm1 ~]# drbdsetup /dev/drbd0 secondary

[root@vm2 drbd.d]# drbdsetup  /dev/drbd0 primary
[root@vm2 drbd.d]# mount /dev/drbd0  /mnt/
[root@vm2 drbd.d]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hda2              3470204   2082684   1208396  64% /
/dev/hda1               101086     17075     78792  18% /boot
tmpfs                   257436         0    257436   0% /dev/shm
/dev/drbd0              893292     17312    830604   3% /mnt
[root@vm2 drbd.d]# cd /mnt/
[root@vm2 mnt]# ls
a  b  c  d  e  lost+found
[root@vm2 /]# drbdsetup  /dev/drbd0 secondary
[root@vm1 ~]# drbdsetup /dev/drbd0 primary