Configure HA with DRBD on CentOS 7 #1 DRBD

고 가용성을 위한 DRBD 구성 가이드 1편 – DRBD 설치

DRBD(Distributed Replicated Block Device) 는 Network Raid 1 방식으로 Bock Device(이하 블록 디바이스) 를 미러링 하는 방식을 이용하여 고 가용성(HA, High Availability)을 보장해 줍니다.

이 가이드에서는 DRBD 의 이해를 돕기 위해 SSH 를 이용한 파일 공유 서비스인 SSHFS 서버에 DRBD 와 Pcacemaker 를 이용하여 고 가용성을 구성 하는 방법에 대해서 알아보도록 하겠습니다. 이 가이드는 DRBD 9.0 en » LINBIT 페이지를 참고하여 작성하였습니다.

구성 환경

VIP : 10.19.10.195

마스터 서버
eth0 : none (VIP용)
eth1 : 10.19.10.196

백업 서버
eth0 : none (VIP용)
eth1 : 10.19.10.197

Nic 을 eth0, eth1 두개를 사용하는 이유는 DRBD 에서 사용되는 미러링(복제) 트래픽과 실제 서비스를 위해 클라이언트와 연결되는 트래픽을 분리하기 위해서 입니다. DRBD 를 사용하기 위해 굳이 NIC 을 나눌 필요는 없습니다.

DRBD 구성

마스터 / 백업 서버 공통 작업

data 디스크 생성 (LVM 을 생성하시고 파티션 포맷은 하지 않습니다.)

[root@10-19-10-196 /]# fdisk /dev/sdb
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 0xaf4647e8.

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disk label type: dos
Disk identifier: 0xaf4647e8

   Device Boot      Start         End      Blocks   Id  System

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): 
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): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disk label type: dos
Disk identifier: 0xaf4647e8

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20971519    10484736   8e  Linux LVM

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@10-19-10-196 /]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.

[root@10-19-10-196 /]# vgcreate vg_data /dev/sdb1
  Volume group "vg_data" successfully created

[root@10-19-10-196 /]# lvcreate -n lv_data -l 100%FREE vg_data
  Logical volume "lv_data" created.

[root@10-19-10-196 /]# pvs
  PV         VG      Fmt  Attr PSize   PFree
  /dev/sda2  centos  lvm2 a--   <9.00g 4.00m
  /dev/sdb1  vg_data lvm2 a--  <10.00g    0 

[root@10-19-10-196 /]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree
  centos    1   2   0 wz--n-  <9.00g 4.00m
  vg_data   1   1   0 wz--n- <10.00g    0 

[root@10-19-10-196 /]# lvs
  LV      VG      Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root    centos  -wi-ao----   6.99g                                                    
  swap    centos  -wi-ao----   2.00g                                                    
  lv_data vg_data -wi-a----- <10.00g

의존성 패키지 설치

[root@10-19-10-196 /]# yum install -y gcc gcc-c++ make autoconf openssl openssl-devel kernel kernel-devel patch flex libxslt po4a

설치

[root@10-19-10-196 /]# cd /usr/local/src
[root@10-19-10-196 src]# wget https://www.linbit.com/downloads/drbd/9.0/drbd-9.0.22-1.tar.gz
[root@10-19-10-196 src]# tar xvzf drbd-9.0.22-1.tar.gz
[root@10-19-10-196 src]# cd drbd-9.0.22-1
[root@10-19-10-196 drbd-9.0.22-1]# make KDIR=/usr/src/kernels/$(uname -r)
[root@10-19-10-196 drbd-9.0.22-1]# make install
[root@10-19-10-196 drbd-9.0.22-1]# modprobe drbd
[root@10-19-10-196 drbd-9.0.22-1]# cat /proc/drbd
[root@10-19-10-196 drbd-9.0.22-1]# echo drbd > /etc/modules-load.d/drbd.conf
[root@10-19-10-196 drbd-9.0.22-1]# cd /usr/local/src
[root@10-19-10-196 src]# wget https://www.linbit.com/downloads/drbd/utils/drbd-utils-9.12.0.tar.gz
[root@10-19-10-196 src]# tar xvzf drbd-utils-9.12.0.tar.gz
[root@10-19-10-196 src]# cd drbd-utils-9.12.0
[root@10-19-10-196 drbd-utils-9.12.0]# ./configure
[root@10-19-10-196 drbd-utils-9.12.0]# make
[root@10-19-10-196 drbd-utils-9.12.0]# make install

설정 파일 링크

[root@10-19-10-196 drbd-9.0.22-1]# ln -s /usr/local/etc/drbd.conf /etc/drbd.conf
[root@10-19-10-196 drbd-9.0.22-1]# ln -s /usr/local/etc/drbd.d /etc/drbd.d

설정

HOSTNAME 은 /etc/hosts 파일안에 있는 HOSTNAME 은 인식을 못하고 uname -n 커맨드로 확인된 HOSTNAME 만 인식합니다. device 설정에 있는 drbd0 은 가상 device 로써 data 디스크의 LVM 과 매핑 된다고 보시면 됩니다.

meta-disk 를 internal 로 설정하면 drbd device 내에 metadata 를 저장하고 별도의 device(ex. /dev/sdc1)로 저장하기 원한다면 직접 지정할 수도 있습니다. (참고: metadata 의 크기는 device 의 크기에 따라서 다릅니다.)

: vi /etc/drbd.d/file_storage.res

resource "file_storage" {
    protocol C;
    disk {
        on-io-error detach;
    }

    on 10-19-10-196 {
        device    /dev/drbd0;
        disk      /dev/mapper/vg_data-lv_data;
        address   10.19.10.196:7788;
        meta-disk internal;
    }

    on 10-19-10-197 {
        device    /dev/drbd0;
        disk      /dev/mapper/vg_data-lv_data;
        address   10.19.10.197:7788;
        meta-disk internal;
    }
}

Protocol : DRBD 에서는 3가지의 복제 모드가 존재합니다. 이 복제 모드는 Protocol A, Protocol B, Protocol C 로 명명 됩니다.

Protocol A : 비동기(Async) 방식입니다. 비동기 방식이기 때문에 DR 과 같은 장거리 복제 시나리오에서 주로 사용됩니다. 마스터에 쓰기가 완료된 후에 복제 패킷이 백업 TCP 송신 버퍼에 배치 되는 순간 복제가 된 것으로 간주합니다.

Protocol B : 반동기(Semi-Async) 방식입니다. 마스터에 쓰기가 완료 되고 복제 패킷이 백업 서버에 도달 하는 순간 복제가 된 것으로 간주합니다.

Protocol C : 일반적인 상황에서 가장 많이 쓰이는 복제 방식으로 동기(Sync) 방식입니다. 마스터와 백업 서버 모두 쓰기가 완료되어야 복제가 된 것으로 간주합니다.

metadata 생성
metadata 를 생성하면 res 파일에 설정되어 있는 device 값을 참조하여 가상 디바이스인 /dev/drbd0 이 생성 됩니다.

[root@10-19-10-196 /]# drbdadm create-md file_storage --force
[root@10-19-10-196 /]# drbdadm up file_storage
[root@10-19-10-196 /]# mkdir /data

마스터 서버 작업

primary 설정

[root@10-19-10-196 /]# drbdadm primary file_storage --force
[root@10-19-10-196 /]# drbdadm -- --overwrite-data-of-peer primary file_storage

디스크 포맷 및 마운트

[root@10-19-10-196 /]# mkfs.xfs /dev/drbd0
[root@10-19-10-196 /]# mount /dev/drbd0 /data

기본적인 설치 및 구성 작업이 완료되었습니다. 백업 서버는 디스크가 마운트 되지 않기 때문에 복제가 잘 되고 있는지 확인하기 위해서는 drbdadm 커맨드를 이용하여 상태 확인만 가능합니다. drbdadm 은 아래 예제와 같이 리소스 네임 대신 all 인자를 사용할 수도 있습니다.
ex) drbdadm up all, drbdadm down all, drbdadm status all 등

[root@10-19-10-196 /]# cat /proc/drbd
version: 9.0.22-1 (api:2/proto:86-116)
GIT-hash: 449d6bf22b01af7d14a297a4ed3e281aa84c94a5 build by root@10-19-10-196, 2020-03-20 14:58:43
Transports (api:16): tcp (9.0.22-1)

[root@10-19-10-197 /]# cat /proc/drbd
version: 9.0.22-1 (api:2/proto:86-116)
GIT-hash: 449d6bf22b01af7d14a297a4ed3e281aa84c94a5 build by root@10-19-10-197, 2020-03-20 14:58:43
Transports (api:16): tcp (9.0.22-1)

[root@10-19-10-196 /]# drbdadm status file_storage
file_storage role:Primary
  disk:UpToDate
  10-19-10-197 role:Secondary
    peer-disk:UpToDate

[root@10-19-10-197 /]# drbdadm status file_storage
file_storage role:Secondary
  disk:UpToDate
  10-19-10-196 role:Primary
    peer-disk:UpToDate

마스터 / 백업 서버 교체 방법

마스터 서버와 백업 서버를 교체하여 실제로 복제가 잘 되는지 확인 해 봅시다.

1. 마스터를 백업으로 변경 합니다.

umount /data
drbdadm secondary file_storage

2. 백업을 마스터로 변경 합니다.

drbdadm primary file_storage
mount /dev/drbd0 /data

metadata 크기 계산 스크립트

위에서 metadata 의 크기는 device 의 크기에 따라서 다르다고 언급한 부분이 있습니다. 아래 스크립트는 metadata 의 크기를 계산해 주는 스크립트 입니다. 이 스크립트는 Calculating DRBD Meta Size – Server Fault 페이지를 참고 하였습니다.

이 스크립트를 실행하려면 bc 패키키가 설치되어 있어야 합니다. yum install bc 커맨드를 이용해서 설치하실 수 있습니다.
Usage) metacalc.sh /dev/mapper/vg_data-lv_data

#!/bin/bash

which bc >/dev/null 2>&1
if [ ! $? -eq 0 ]; then
    echo "Error: bc is not installed"
    exit 1
fi

if [ $# -lt 1 ]; then
    echo "Error: Please supply block device path"
    echo "Eg. /dev/vg1/backups"
    exit 1
fi

DEVICE=$1

SECTOR_SIZE=$( blockdev --getss $DEVICE )
SECTORS=$( blockdev --getsz $DEVICE )
MD_SIZE=$( echo "((($SECTORS + (2^18)-1) / 262144 * 8) + 72)" | bc )
FS_SIZE=$( echo "$SECTORS - $MD_SIZE" | bc )

MD_SIZE_MB=$( echo "($MD_SIZE / 4 / $SECTOR_SIZE) + 1" | bc )
FS_SIZE_MB=$( echo "($FS_SIZE / 4 / $SECTOR_SIZE)" | bc )

echo "Filesystem: $FS_SIZE_MB MiB"
echo "Filesystem: $FS_SIZE Sectors"
echo "Meta Data:  $MD_SIZE_MB MiB"
echo "Meta Data:  $MD_SIZE Sectors"
echo "--"
echo "Resize commands: resize2fs -p "$DEVICE $FS_SIZE_MB"M; drbdadm create-md res"
[root@10-19-10-196 src]# bash metacalc.sh /dev/mapper/vg_data-lv_data 
Filesystem: 511980 MiB
Filesystem: 1048535736 Sectors
Meta Data:  16 MiB
Meta Data:  32072 Sectors
--
Resize commands: resize2fs -p /dev/mapper/vg_data-lv_data 511980M; drbdadm create-md res

You may also like...

Subscribe
Notify of
guest

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x