#yum 명령어는 상용 서버에서 정상동작 하지 않으므로 아래와 같이 수행
cd /root/pkgs/keepalived
yum install -y glibc
rpm -ivh ipset-libs<TAB>
rpm -ivh net-snmp-libs<TAB> net-snmp-agent<TAB>
rpm -ivh keepalived<TAB>
[root@fa-test01 network-scripts]# cat /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state BACKUP # backup node는 MASTER -> BACKUP // nopreempt 모드기에 둘다 backup
interface eth1 # vip를 secondary ip로 매핑한 인터페이스
virtual_router_id 51 # VRRP 프로토콜로 advertisement 를 교환할 가상의 라우터
# 동일한 id를 사용하는 virtual router가 있으면 오류 발생!
priority 100 # 숫자가 높은 쪽이 Master가 되므로 backup은 100보다 낮게 설정
advert_int 1 # 1초마다 advertisement 패킷 교환
nopreempt #Active 살아나도 절체 안함
authentication {
auth_type PASS # 패스워드 인증방식
auth_pass 1111 # 비밀번호 1111
}
virtual_ipaddress {
10.30.31.171 dev eth1 # VIP 주소와, 해당 VIP를 사용하여 통신할 인터페이스 지정
# dev eth1 부분은 생략해도 정상 동작
}
}
[root@fa-test02 network-scripts]# cat /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state MASTER # backup node는 MASTER -> BACKUP
interface eth1 # vip를 secondary ip로 매핑한 인터페이스
virtual_router_id 51 # VRRP 프로토콜로 advertisement 를 교환할 가상의 라우터
priority 90 # 숫자가 높은 쪽이 Master가 되므로 backup은 100보다 낮게 설정
advert_int 1 # 1초마다 advertisement 패킷 교환
authentication {
auth_type PASS # 패스워드 인증방식
auth_pass 1111 # 비밀번호 1111
}
virtual_ipaddress {
10.30.31.171 dev eth1 # VIP 주소와, 해당 VIP를 사용하여 통신할 인터페이스 지정
# dev eth1 부분은 생략해도 정상 동작
}
}
# systemctl restart network
# systemctl restart keepalived
# systemctl restart network
$ systemctl enable keepalived
# ping 10.30.31.171
[root@fa-test02 network-scripts]# arp -a
? (10.30.31.172) at 1e:00:a7:04:13:c3 [ether] on eth1
gateway (172.27.0.1) at 02:00:39:a3:07:8c [ether] on eth0
? (10.30.31.161) at 1e:00:79:04:13:b8 [ether] on eth1
r-109017-VM.cs7001cloud.internal (172.27.0.223) at 02:00:39:a3:07:8c [ether] on eth0
You have new mail in /var/spool/mail/root
# tailf /var/log/messages
# poweroff
혹은
# ifconfig eth1 down
(업시킬땐 ifconfig eth1 up)
Jul 14 10:05:37 fa-test02 Keepalived_vrrp[15744]: VRRP_Instance(VI_1) Transition to MASTER STATE
Jul 14 10:05:38 fa-test02 Keepalived_vrrp[15744]: VRRP_Instance(VI_1) Entering MASTER STATE
Jul 14 10:05:38 fa-test02 Keepalived_vrrp[15744]: VRRP_Instance(VI_1) setting protocol VIPs.
Jul 14 10:05:38 fa-test02 Keepalived_vrrp[15744]: Sending gratuitous ARP on eth1 for 10.30.31.171
Jul 14 10:05:38 fa-test02 Keepalived_vrrp[15744]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth1 for 10.30.31.171
Jul 14 10:05:38 fa-test02 Keepalived_vrrp[15744]: Sending gratuitous ARP on eth1 for 10.30.31.171
Jul 14 10:05:40 fa-test02 ntpd[3858]: Listen normally on 16 eth1 10.30.31.171 UDP 123
[root@fa-test03 ~]# arp -a
? (10.30.31.168) at 1e:00:c3:04:13:bf [ether] on eth1
? (10.30.31.161) at 1e:00:79:04:13:b8 [ether] on eth1
? (10.30.31.171) at 1e:00:c3:04:13:bf [ether] on eth1
gateway (172.27.0.1) at 02:00:39:a3:07:8c [ether] on eth0
? (10.30.31.170) at 1e:00:ec:04:13:c1 [ether] on eth1
r-109017-VM.cs7001cloud.internal (172.27.0.223) at 02:00:39:a3:07:8c [ether] on eth0
[root@fa-test03 ~]# arp -a
? (10.30.31.168) at 1e:00:c3:04:13:bf [ether] on eth1
? (10.30.31.161) at 1e:00:79:04:13:b8 [ether] on eth1
? (10.30.31.171) at 1e:00:ec:04:13:c1 [ether] on eth1 # ARP Table에서 VIP에 매핑된 MAC addr이 변경됨을
gateway (172.27.0.1) at 02:00:39:a3:07:8c [ether] on eth0
? (10.30.31.170) at 1e:00:ec:04:13:c1 [ether] on eth1
r-109017-VM.cs7001cloud.internal (172.27.0.223) at 02:00:39:a3:07:8c [ether] on eth0
[root@fa-test01 network-scripts]# cat /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# uname -a
# cd /root/pkgs/drbd
yum install kernel-ml<TAB>
-------------------------
상용 서버에서는 인터넷이 없으므로 위 내용이 아닌 rpm -ivh kernel-ml<TAB>으로 설치 수행
# cat /boot/grub2/grub.cfg | grep menuentry | cut -d "'" -f2 #부팅순서확인
# grub2-set-default "CentOS Linux (5.4.12-1.el7.elrepo.x86_64) 7 (Core)" #최신버전의 kernel을 default 설정
# grub2-editenv li
st #부팅될 커널 확인
# reboot #재부팅
# uname -a #재부팅 후 로드된 커널 확인
# yum -y install kmod-drbd90 drbd90-utils
# fdisk /dev/xvdb -> primary, 파티션넘버, 전체 섹터로 생성 후 t를 눌러 시스템을 linux LVM으로 변경(n, p, 1, wq, t, 8e 순서대로 입력)
# pvcreate /dev/xvdb1 -> /dev/xvdb의 파티션인 xvdb1에 pv 생성
# vgcreate drbdnode1 /dev/xvdb1 -> pv(/dev/xvdb1)에 vg을 drbd1의 이름으로 생성
# lvcreate -l 100%FREE -n drbdnode1lv drbdnode1 -> -l: 로지컬볼륨(PE), 9.9G, -n drbdnode1lv 이름으로, drbdnode1에 vg 생성
# /etc/drbd.d/global_common.conf
global {
usage-count yes;
}
common {
net {
protocol C;
}
}
[root@fa-test01 ~]# cat /etc/drbd.d/r0.res
resource r0 {
startup {
wfc-timeout 30;
degr-wfc-timeout 30;
}
net {
cram-hmac-alg sha1;
shared-secret sync_disk;
}
syncer {
rate 100M;
al-extents 257;
on-no-data-accessible io-error;
}
on NODE1 { #NODE1은 uname -a에서 확인되는 hostname이어야하며, /etc/hosts에도 동일한 이름으로 지정되어있어야한다.
device /dev/drbd0;
disk /dev/mapper/drbd1-drbd1lv;
address 10.30.31.168:7788;
meta-disk internal;
}
on NODE2 { #NODE1은 uname -a에서 확인되는 hostname이어야하며, /etc/hosts에도 동일한 이름으로 지정되어있어야한다.
device /dev/drbd0;
disk /dev/mapper/drbd2-drbd2lv;
address 10.30.31.170:7788;
meta-disk internal;
}
}
# lsmod | grep drbd
# modprobe drbd
# lsmod | grep drbd
drbdadm create-md r0 #r0: 리소스이름
[root@fa-test02 ~]# systemctl is-enabled drbd
disabled
[root@fa-test02 ~]# systemctl enable drbd
Created symlink from /etc/systemd/system/multi-user.target.wants/drbd.service to /usr/lib/systemd/system/drbd.service.
[root@fa-test02 ~]# systemctl is-enabled drbd
enabled
[root@fa-test01 ~]# systemctl start drbd
[root@fa-test01 ~]# cat /proc/drbd
version: 8.4.11 (api:1/proto:86-101)
srcversion: C83CE761848B9DE61379370
0: cs:WFConnection ro:Secondary/Unknown ds:Inconsistent/DUnknown C r----s
ns:0 nr:0 dw:0 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:10481308
[root@fa-test01 ~]# drbdadm status
r0 role:Secondary
disk:Inconsistent
peer role:Secondary
replication:Established peer-disk:Inconsistent
위 설정까지 master와 backup에서 모두 수행한다.
현재부터 Master에서만 설정
[root@fa-test01 ~]# drbdadm primary --force r0
[root@fa-test01 ~]# cat /proc/drbd
version: 8.4.11 (api:1/proto:86-101)
srcversion: C83CE761848B9DE61379370
0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-----
ns:434176 nr:0 dw:0 dr:436296 al:8 bm:0 lo:0 pe:156 ua:0 ap:0 ep:1 wo:f oos:10050460
[>....................] sync'ed: 4.2% (9812/10232)M
finish: 0:04:16 speed: 39,168 (39,168) K/sec
[root@fa-test01 ~]# drbdadm status
r0 role:Primary
disk:UpToDate
peer role:Secondary
replication:SyncSource peer-disk:Inconsistent done:21.52
[root@fa-test01 ~]# drbdadm up r0
[root@fa-test01 ~]# drbdadm status
r0 role:Primary
disk:UpToDate
peer role:Secondary
replication:Established peer-disk:UpToDate
[root@fa-test01 ~]# drbdadm status
r0 role:Primary
disk:UpToDate
peer role:Secondary
replication:Established peer-disk:UpToDate
[root@fa-test01 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 20G 0 disk
├─xvda2 202:2 0 19.1G 0 part
│ ├─centos-swap 253:1 0 1.9G 0 lvm [SWAP]
│ └─centos-root 253:0 0 17.2G 0 lvm /
└─xvda1 202:1 0 953M 0 part /boot
sr0 11:0 1 1024M 0 rom
xvdb 202:16 0 10G 0 disk
└─xvdb1 202:17 0 10G 0 part
└─drbdnode1-drbdnode1lv 253:2 0 10G 0 lvm
└─drbd0 147:0 0 10G 0 disk
[root@fa-test01 ~]# mount | grep ^/dev # df -T 혹은 mount | grep ^/dev 로 확인 가능
/dev/mapper/centos-root on / type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/xvda1 on /boot type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
[root@fa-test01 ~]# mkfs -t xfs /dev/drbd0
meta-data=/dev/drbd0 isize=512 agcount=4, agsize=655082 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=2620327, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@fa-test01 ~]# mkdir /drbd-fs
[root@fa-test01 ~]# find / -name drbd-fs
/drbd-fs
[root@fa-test01 /]# df /drbd-fs
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/centos-root 18028544 2178684 15849860 13% /
[root@fa-test01 /]# mount /dev/drbd0 /drbd-fs
[root@fa-test01 /]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 977M 0 977M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 8.6M 982M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/mapper/centos-root 18G 2.1G 16G 13% /
/dev/xvda1 950M 214M 736M 23% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/drbd0 10G 33M 10G 1% /drbd-fs
[root@fa-test01 /]# vim /drbd-fs/testdata
[root@fa-test01 /]# ls /drbd-fs
testdata
#ACTIVE NODE
[root@fa-test01 /]# cat /proc/drbd
version: 8.4.11 (api:1/proto:86-101)
srcversion: C83CE761848B9DE61379370
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:10493946 nr:0 dw:12638 dr:10502422 al:15 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
#STBY NODE
[root@fa-test02 ~]# cat /proc/drbd
version: 8.4.11 (api:1/proto:86-101)
srcversion: C83CE761848B9DE61379370
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
ns:0 nr:10493946 dw:10493946 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[root@fa-test01 /]# systemctl stop drbd
[root@fa-test01 /]# cat /proc/drbd
cat: /proc/drbd: No such file or directory
[root@fa-test01 /]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 977M 0 977M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 8.6M 982M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/mapper/centos-root 18G 2.1G 16G 13% /
/dev/xvda1 950M 214M 736M 23% /boot
tmpfs 199M 0 199M 0% /run/user/0
[root@fa-test01 /]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 20G 0 disk
├─xvda2 202:2 0 19.1G 0 part
│ ├─centos-swap 253:1 0 1.9G 0 lvm [SWAP]
│ └─centos-root 253:0 0 17.2G 0 lvm /
└─xvda1 202:1 0 953M 0 part /boot
sr0 11:0 1 1024M 0 rom
xvdb 202:16 0 10G 0 disk
└─xvdb1 202:17 0 10G 0 part
└─drbdnode1-drbdnode1lv 253:2 0 10G 0 lvm
[root@fa-test02 ~]# cat /proc/drbd
version: 8.4.11 (api:1/proto:86-101)
srcversion: C83CE761848B9DE61379370
0: cs:WFConnection ro:Secondary/Unknown ds:UpToDate/DUnknown C r-----
ns:0 nr:10494004 dw:10494004 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[root@fa-test02 ~]# drbdadm status
r0 role:Secondary
disk:UpToDate
peer connection:Connecting
[root@fa-test02 ~]# drbdadm primary r0
[root@fa-test02 ~]# cat /proc/drbd
version: 8.4.11 (api:1/proto:86-101)
srcversion: C83CE761848B9DE61379370
0: cs:WFConnection ro:Primary/Unknown ds:UpToDate/DUnknown C r-----
ns:0 nr:10494004 dw:10494004 dr:2120 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[root@fa-test02 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 20G 0 disk
├─xvda2 202:2 0 19.1G 0 part
│ ├─centos-swap 253:1 0 1.9G 0 lvm [SWAP]
│ └─centos-root 253:0 0 17.2G 0 lvm /
└─xvda1 202:1 0 953M 0 part /boot
sr0 11:0 1 1024M 0 rom
xvdb 202:16 0 10G 0 disk
└─xvdb1 202:17 0 10G 0 part
└─drbdnode2-drbdnode2lv 253:2 0 10G 0 lvm
└─drbd0 147:0 0 10G 0 disk
[root@fa-test02 ~]# mkdir /drbd-fs
[root@fa-test02 ~]# mount /dev/drbd0 /drbd-fs
[root@fa-test02 ~]# ls /drbd-fs
testdata
[root@fa-test01 /]# systemctl start drbd
[root@fa-test01 /]# cat /proc/drbd
version: 8.4.11 (api:1/proto:86-101)
srcversion: C83CE761848B9DE61379370
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
ns:0 nr:2105 dw:2105 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[root@fa-test01 /]# drbdadm status
r0 role:Secondary
disk:UpToDate
peer role:Primary
replication:Established peer-disk:UpToDate
[root@fa-test02 ~]# umount /dev/drbd0
You have new mail in /var/spool/mail/root
[root@fa-test02 ~]# drbdadm secondary r0
[root@fa-test02 ~]# drbdadm status
r0 role:Secondary
disk:UpToDate
peer role:Secondary
replication:Established peer-disk:UpToDate
[root@fa-test01 /]# drbdadm primary r0
[root@fa-test01 /]# cat /proc/drbd
version: 8.4.11 (api:1/proto:86-101)
srcversion: C83CE761848B9DE61379370
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:0 nr:2108 dw:2108 dr:2120 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[root@fa-test01 /]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 977M 0 977M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 8.6M 982M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/mapper/centos-root 18G 2.1G 16G 13% /
/dev/xvda1 950M 214M 736M 23% /boot
tmpfs 199M 0 199M 0% /run/user/0
[root@fa-test01 /]# mount /dev/drbd0 /drbd-fs
[root@fa-test01 /]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 977M 0 977M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 8.6M 982M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/mapper/centos-root 18G 2.1G 16G 13% /
/dev/xvda1 950M 214M 736M 23% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/drbd0 10G 33M 10G 1% /drbd-fs
[root@fa-test01 /]# ls /drbd-fs
fa-test02_made testdata
[root@fa-test01 sbin]# pwd
/usr/local/sbin
[root@fa-test01 sbin]# cat drbd_master.sh
#!/bin/sh
sudo drbdadm primary r0
sudo mkdir /drbd-fs
sudo mount /dev/drbd0 /drbd-fs
[root@fa-test01 sbin]# cat drbd_backup.sh
#!/bin/sh
sudo umount -f /dev/drbd0
sudo rmdir /drbd-fs
sudo drbdadm secondary r0
[root@fa-test01 sbin]# scp drbd_master.sh drbd_backup.sh root@10.30.31.170:/usr/local/sbin
The authenticity of host '10.30.31.170 (10.30.31.170)' can't be established.
ECDSA key fingerprint is SHA256:KHR7lHxKSdo3lCB2aX5K5mXX2lYilbGC4P3V+EDPZeM.
ECDSA key fingerprint is MD5:e2:d5:f5:f4:a2:40:04:70:c3:5a:5c:de:22:a3:60:ec.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.30.31.170' (ECDSA) to the list of known hosts.
root@10.30.31.170's password:
drbd_master.sh 100% 59 26.1KB/s 00:00
drbd_backup.sh 100% 49 19.6KB/s 00:00
# sudo chmod 755 ./*
[root@fa-test01 sbin]# cat /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state MASTER
interface eth1
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.30.31.171 dev eth1
}
notify_master "/usr/local/sbin/drbd_master.sh" #추가된 부분
notify_backup "/usr/local/sbin/drbd_backup.sh" #추가된 부분
notify_fault "/usr/local/sbin/drbd_backup.sh" #추가된 부분
}
[root@fa-test02 ~]# chmod 755 /usr/local/sbin/drbd_backup.sh
[root@fa-test02 ~]# chmod 755 /usr/local/sbin/drbd_master.sh
systemctl restart keepalived
DRBD node dual down시 Split-brain 현상 발생
Split-Brain : 데이터가 싱크되는 중 외부 요인으로 인해 두 데이터가 다르게 되어 데이터 싱크 실패
해결방법 : Secondary의 데이터를 모두 지우고 다시 싱크 실행
# Both node
drbdadm disconnect all
# Secondary node - 아래 명령어로 데이터 모두 삭제
drbdadm --discard-my-data connect all
# Both node - 아래 명령어를 통해 Secondary node의 Data를 모두 지우고 다시 Sync
drbdadm connect all
drbd 절체 잘 안되면 스크립트 경로 확인 및 스크립트 내 sudo 추가(drbd_master/bkup.sh)
keepalived + DRBD 서비스 구성 완료
참고