※ root 계정으로 작업
1. Kernel 설정 (ip forwarding 및 VIP binding 허용)
# vi /etc/sysctl.conf
...
net.ipv4.ip_forward = 1
net.ipv4.ip_nonlocal_bind = 1
...
# sysctl -p
2. 필수 프로그램 및 관련 라이브러리 설치
# yum install keepalived
3. 설정 파일 수정
# vi /etc/keepalived/keepalived.conf
(아래는 149 MASTER 서버에 151 VIP 및 150 BACKUP 서버 등록하는 예제로, 빨간색 부분은 서버에 맞게 설정)
1) 1번 서버 내용
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server localhost
smtp_connect_timeout 30
}
vrrp_instance VI_1 {
state MASTER
interface ens192
virtual_router_id 151
priority 200
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
unicast_src_ip 192.168.0.149
unicast_peer {
192.168.0.150
}
virtual_ipaddress {
192.168.0.151
}
}
2) 2번 서버 내용 (150 BACKUP 서버에 151 VIP 및 149 MASTER 서버 등록)
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server localhost
smtp_connect_timeout 30
}
vrrp_instance VI_1 {
state BACKUP
interface ens192
virtual_router_id 151
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
unicast_src_ip 192.168.0.150
unicast_peer {
192.168.0.149
}
virtual_ipaddress {
192.168.0.151
}
}
4. 부팅시 keepalived 켜기, 시작
# systemctl enable keepalived
# systemctl start keepalived
# systemctl status keepalived
5. MASTER 서버의 VIP 등록 여부 확인 (BACKUP 쪽은 VIP가 나오지 않음)
# ip a
...
2: ens192: mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.149/24 brd 192.168.0.255 scope global noprefixroute ens192
valid_lft forever preferred_lft forever
inet 192.168.0.151/32 scope global ens192
valid_lft forever preferred_lft forever
...
6. 외부에서 PING 체크하면서 한쪽 서버 내려보는 등 이중화 테스트