전체적인 설치에 대한 방법이니, 설치 및 구성에 참고 바랍니다.

 

■ 구축 환경

OS
- CentOS Linux release 7.9.2009 (Core)

테스트에 사용한 IP
- 실제로 테스트 당시에는, Public IP를 사용하였으니 참고 바랍니다.

 

■ Pacemaker Cluster 구성

 기본 설치 및 설정 같은 경우, Pacemaker + ldirectord 를 이용한 LVS 구성 를 참조 부탁드립니다.

 

■ DRBD 설치

※ DRBD란 ?

 - Distributed Replicated Block Device의 약자로, HA(High Availabilty) 구성을 위한 Block Device 입니다.

Active 상태의 서버 Disk에서 데이터를 저장할 경우, 네트워크를 통해 디스크 블럭단위로 standby 서버에 미러링 되는 방식이라고 보시면 됩니다.

 

1. /etc/hosts 에 호스트 등록

# vi /etc/hosts
192.168.0.100 active
192.168.0.101 standby

 

2. 주요 패키지 설치

# yum install https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
# yum -y install kmod-drbd84 drbd84-utils

# drbd 모듈 확인 (확인이 되지 않을 경우 모듈로드)

# lsmod |grep drbd
# modprobe drbd
drbd 585395 0
libcrc32c 12644 2 drbd,nf_conntrack

 

3. DRBD 관련 설정 ( Actvie, Standby )

# vi /etc/drbd.conf
global {
usage-count yes;
}
common {
syncer {
}
}
resource "r0" {
protocol C;
startup {
wfc-timeout 0;
degr-wfc-timeout 120;
}
disk {
on-io-error detach;
}
net {
timeout 60;
connect-int 10;
ping-int 10;
max-buffers 2048;
max-epoch-size 2048;
}


on active {
device /dev/drbd0;
disk /dev/xvda2;
address 192.168.0.100:7787;
meta-disk internal;
}


on standby {
device /dev/drbd0;
disk /dev/xvda2;
address 192.168.0.101:7787;
meta-disk internal;
}


}

 

3. DRBD Metadata 생성 (Active, Standby)

 metadata 생성 전 DRBD 볼륨으로 사용할 공간은 파일 시스템이 생성되어 있지 않아야 하며, 미리 파일시스템이 생성된 상태면 dd명령어를 이용하여 MBR 영역을 제거해야 합니다.

# drbdadm create-md r0
--== Thank you for participating in the global usage survey ==--
The server's response is:


you are the 4215th user to install this version
initializing activity log
initializing bitmap (960 KB) to all zero
Writing meta data...
New drbd meta data block successfully created.
Success


# systemctl start drbd
# systemctl status drbd
● drbd.service - DRBD -- please disable. Unless you are NOT using a cluster manager.
Loaded: loaded (/usr/lib/systemd/system/drbd.service; disabled; vendor preset: disabled)
Active: active (exited) since 목 2021-10-14 12:43:06 KST; 4 days ago
Process: 5530 ExecStart=/lib/drbd/drbd start (code=exited, status=0/SUCCESS)
Main PID: 5530 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/drbd.service

 

 정상적으로 연결되었는지 확인.

# cat /proc/drbd
GIT-hash: 66145a308421e9c124ec391a7848ac20203bb03c build by mockbuild@, 2020-04-05 02:58:18

0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:84 nr:35276312 dw:35276400 dr:2193 al:11 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

 

4. Primary 지정 및 파일시스템 생성 ( Active )

# drbdadm primary --force r0
# mkfs.ext4 /dev/drbd0
# mount /dev/drbd0 /home
/dev/drbd0 ext4 33G 49M 31G 1% /home

 

■ PCS resource 생성

CIB(Cluster Information Base), Raw xml 에 우선 설정을 저장 후 업데이트 하는 방식으로 진행

# pcs cluster cib drbd_cfg
→ 'drbd_cfg' 파일을 cib 형식으로 생성.


# pcs -f drbd_cfg resource create Data ocf:linbit:drbd drbd_resource=r0 op monitor timeout="30" interval="20" role="Master" op monitor timeout="30" interval="10" role="Slave"
→ “drbd r0” 리소스의 대한 설정으로 Primary/Secondary가 변경이 된다.

# pcs -f drbd_cfg resource master DataSync Data1 master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true
→ Master / Slave 구성 제약조건.

# pcs -f drbd_cfg resource create storage ocf:heartbeat:Filesystem device="/dev/drbd0" directory="/home" fstype="ext4"
drbd 파티션과 파일시스템을 지정하여 mount 시키는 리소스로, 노드별로 Master 노드에 마운트 시킨다.

# pcs -f drbd_cfg resource create VirtualIP ocf:heartbeat:IPaddr2 ip=[VIP] cidr_netmask=32 nic=eth0:1 op monitor timeout="30" interval="20" role="Master" op monitor timeout="30" interval="10" role="Slave"

→ VIP에 대한 Resource 설정.

# pcs -f drbd_cfg resource group add HA-GROUP VirtualIP storage
→ HA-GROUP에 VIP, DRBD mount 순서대로 구동되도록 그룹화.

# pcs -f drbd_cfg constraint colocation add HA-GROUP DataSync INFINITY with-rsc-role=Master
→ HA-GROUP & DataSync 리소스의 Master 가 공통된 Master 에서 실행되도록 설정.

# pcs -f drbd_cfg constraint order promote DataSync then start storage
→ DataSync1 리소스가 실행된 후 storge1 리소스 (/dev/drbd0 mount) 실행

 

■ Failover 테스트

 

1. ative 서버에서 서비스 중 확인.

# pcs status

 

2. active cluster 를 standby 상태로 변경하여 테스트 진행.

→ 등록한 resource들이 정상적으로 넘어갔는지 확인진행.

[active]
# pcs cluster standby active

[standby]
# pcs status


# cat /proc/drbd

 

■ 그 외 서비스들 추가.

실제로 DRBD로 이중화 구성할 경우 WEB, DB와 같은 서비스들을 같이 사용한다. 자신이 구축할 서버에 용도에 맞게 리소스를 추가하시면 됩니다. 아래의 예는 Apache , Mysql 설치 후 추가로 등록한 예시입니다.  LSB 방식으로 구동되도록 설정 진행하였으니, /etc/init.d 아래에 실행파일을 등록하시면 됩니다.

 

※ Apache

→ /etc/init.d/ 경로에 아래와 같은 스크립트 작성

#!/bin/sh


case "$1" in
start)
echo -n "Starting apahce: "
/usr/local/httpd2/bin/apachectl start
;;
stop)
echo -n "Shutting down apache"
/usr/local/httpd2/bin/apachectl stop
;;
*)
echo "Usage: $0 {start|stop}"
esac


exit 0

 

※ Mysql

→ Mysql 설치 시 제공되는 mysql.server 실행파일을 /etc/init.d/ 경로에 옮겨 사용하였습니다.

 

1. resource 추가

# pcs -f drbd_cfg resource create Apache lsb:apache op monitor timeout="30s" interval="20s" role="Master" op monitor timeout="30s" interval="10s" role="Slave"

# pcs -f drbd_cfg resource create Mysql lsb:mysql.server op start timeout=60s op stop timeout=60s op monitor interval=20s timeout=30s


 

2. HA-GROUP에  추가

 서비스의 시작 순서를 판단하여 넣어주도록 합니다.

# pcs -f drbd_cfg resource group add HA-GROUP VirtualIP storage Apache Mysql

 

'Linux > HA' 카테고리의 다른 글

PDNS 이중화 구성  (0) 2022.03.28
Pacemaker + ldirectord 를 이용한 LVS 구성  (0) 2022.03.24

+ Recent posts