테스트 환경 OS: CentOS 7

dr01 active 192.168.122.50 /dev/vdb
dr02 standby 192.168.122.60 /dev/vdb

 

1. hostname 설정 (dr01 , dr02)

[root@dr01 ~]# vi /etc/hosts
192.168.122.50          dr01
192.168.122.60          dr02

 

2. disk 준비 (dr01 , dr02)

[root@drbd01 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  4.3G  0 rom
vda    253:0    0   20G  0 disk
├─vda1 253:1    0    1G  0 part /boot
├─vda2 253:2    0    1G  0 part [SWAP]
└─vda3 253:3    0   18G  0 part /
vdb    253:16   0   10G  0 disk
[root@drbd01 ~]#

[root@drbd01 ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x21877a4c.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@drbd01 ~]#

 

3. drbd 패키지 설치 (dr01 , dr02)

[root@dr01 ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[root@dr01 ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
Retrieving http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:elrepo-release-7.0-3.el7.elrepo  ################################# [100%]
[root@dr01 ~]#

[root@dr01 ~]# yum install -y kmod-drbd84 drbd84-utils

 

4. drbd 설정 (dr01 , dr02)

[root@dr01 ~]# mv /etc/drbd.d/global_common.conf /etc/drbd.d/global_common.conf.org
[root@dr01 ~]# vi /etc/drbd.d/global_common.conf
global {
 usage-count  yes;
}
common {
 net {
  protocol C;
 }
}


[root@dr01 ~]# vi /etc/drbd.d/dr0.res
resource dr0 {
        on dr01 {
                device /dev/drbd0;
                        disk /dev/vdb1;
                        meta-disk internal;
                        address 192.168.122.50:7789;
        }
        on dr02  {
                device /dev/drbd0;
                        disk /dev/vdb1;
                        meta-disk internal;
                        address 192.168.122.60:7789;
        }
}

 

5. dr0 메터데이터 블록 생성

[root@dr01 ~]# drbdadm create-md dr0
initializing activity log
initializing bitmap (320 KB) to all zero
Writing meta data...
New drbd meta data block successfully created.
[root@dr01 ~]#


[root@dr02 ~]# drbdadm create-md dr0
initializing activity log
initializing bitmap (320 KB) to all zero
Writing meta data...
New drbd meta data block successfully created.
[root@dr02 ~]#

 

6. drbd 데몬 구동 (dr01 , dr02)

[root@dr01 ~]# systemctl start drbd ; systemctl enable drbd
[root@dr02 ~]# systemctl start drbd ; systemctl enable drbd

 

7. drbd primary 설정 (dr01 에서만 실행)

[root@dr01 ~]# drbdadm primary --force dr0

[root@dr01 ~]# drbdadm status dr0
dr0 role:Primary
  disk:UpToDate
  peer role:Secondary
    replication:SyncSource peer-disk:Inconsistent done:0.29

[root@dr01 ~]#

[root@dr01 ~]# drbdadm -- --overwrite-data-of-peer primary dr0

 

8. 동기화 확인 (dr01 , dr02)

[root@dr01 ~]# cat /proc/drbd
version: 8.4.11-1 (api:1/proto:86-101)
GIT-hash: 66145a308421e9c124ec391a7848ac20203bb03c build by mockbuild@, 2018-11-03 01:26:55
 0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-----
    ns:455960 nr:0 dw:0 dr:458080 al:8 bm:0 lo:0 pe:7 ua:0 ap:0 ep:1 wo:f oos:10031116
        [>....................] sync'ed:  4.4% (9796/10236)M
        finish: 0:08:22 speed: 19,972 (13,732) K/sec
[root@dr01 ~]# 


[root@dr02 ~]# cat /proc/drbd
version: 8.4.11-1 (api:1/proto:86-101)
GIT-hash: 66145a308421e9c124ec391a7848ac20203bb03c build by mockbuild@, 2018-11-03 01:26:55
 0: cs:SyncTarget ro:Secondary/Primary ds:Inconsistent/UpToDate C r-----
    ns:0 nr:1981844 dw:1981844 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:8502536
        [==>.................] sync'ed: 19.0% (8300/10236)M
        finish: 0:03:48 speed: 37,124 (25,408) want: 41,040 K/sec
[root@dr02 ~]#

 

9. drbd 상태 확인

[root@dr01 ~]# drbdadm status dr0
dr0 role:Primary
  disk:UpToDate
  peer role:Secondary
    replication:Established peer-disk:UpToDate

[root@dr01 ~]#

[root@dr02 ~]# drbdadm status dr0
dr0 role:Secondary
  disk:UpToDate
  peer role:Primary
    replication:Established peer-disk:UpToDate

[root@dr02 ~]#

 

10. 디렉토리 추가 및 파일시스템 포멧

[root@dr01 ~]# mkdir /data
[root@dr02 ~]# mkdir /data

포멧은 dr01 에서만 진행 합니다. 
[root@dr01 ~]# mkfs.xfs /dev/drbd0


drbd0 Device 를 /data 에 마운트 합니다. 
[root@dr01 ~]# mount /dev/drbd0 /data


Test 를 위하여 0 ~ 5 까지 빈파일을 생성 합니다. 
[root@dr01 ~]# cd /data
[root@dr01 data]# touch 0 1 2 3 4 5

 

11.장애 테스트

장애 테스트를 위하여 dr01 시스템을 Down 시킵니다.

dr02 에서 /dev/drbd0 를 /data 에 mount 합니다.

[root@dr01 data]# init 0


[root@dr02 ~]# drbdadm primary dr0
[root@dr02 ~]# mount /dev/drbd0 /data
[root@dr02 ~]# ls -al /data/
total 0
drwxr-xr-x   2 root root  60 Sep  9 14:45 .
dr-xr-xr-x. 18 root root 236 Sep  9 14:42 ..
-rw-r--r--   1 root root   0 Sep  9 14:45 0
-rw-r--r--   1 root root   0 Sep  9 14:45 1
-rw-r--r--   1 root root   0 Sep  9 14:45 2
-rw-r--r--   1 root root   0 Sep  9 14:45 3
-rw-r--r--   1 root root   0 Sep  9 14:45 4
-rw-r--r--   1 root root   0 Sep  9 14:45 5
[root@dr02 ~]#

 

12. dr0 상태를 확인 합니다.

[root@dr02 ~]# drbdadm status dr0
dr0 role:Primary
  disk:UpToDate
  peer connection:Connecting

[root@dr02 ~]#

 

13. 장애 원복

dr02 시스템 에서 primary 를 secondary 로 변경 하고, dr01 시스템을 primary 로 지정 합니다.

[root@dr02 ~]# umount /data
[root@dr02 ~]# drbdadm secondary dr0


[root@dr01 ~]# drbdadm primary dr0
[root@dr01 ~]# mount /dev/drbd0 /data
[root@dr01 ~]# ls -al /data
total 0
drwxr-xr-x   2 root root  60 Sep  9 14:45 .
dr-xr-xr-x. 18 root root 236 Sep  9 14:42 ..
-rw-r--r--   1 root root   0 Sep  9 14:45 0
-rw-r--r--   1 root root   0 Sep  9 14:45 1
-rw-r--r--   1 root root   0 Sep  9 14:45 2
-rw-r--r--   1 root root   0 Sep  9 14:45 3
-rw-r--r--   1 root root   0 Sep  9 14:45 4
-rw-r--r--   1 root root   0 Sep  9 14:45 5
[root@dr01 ~]#

 

14. 상태 확인 

[root@dr01 ~]# drbdadm status dr0
dr0 role:Primary
  disk:UpToDate
  peer role:Secondary
    replication:Established peer-disk:UpToDate

[root@dr01 ~]#




[root@dr02 /]# drbdadm status dr0
dr0 role:Secondary
  disk:UpToDate
  peer role:Primary
    replication:Established peer-disk:UpToDate

[root@dr02 /]#