카이도스의 Tech Blog
HAproxy 설치 - 고가용성 본문
728x90
반응형
환경
- Ubuntu 22.04
- HAProxy version 2.8.7
구성
- VIP 10.10.x.181
- haproxy1 10.10.x.183
- haproxy2 10.10.x.182
HAproxy 설치
# 호스트네임 설정
sudo hostnamectl set-hostname haproxy1
sudo hostnamectl set-hostname haproxy2
# apt 최신화
sudo apt update && sudo apt upgrade -y
# haproxy 설치 및 확인
sudo apt-get install --no-install-recommends software-properties-common
sudo add-apt-repository ppa:vbernat/haproxy-2.8
sudo apt-get install -y haproxy=2.8.\*
haproxy -v
HAProxy version 2.8.7-1ppa1~jammy 2024/03/02 - https://haproxy.org/
Status: long-term supported branch - will stop receiving fixes around Q2 2028.
Known bugs: http://www.haproxy.org/bugs/bugs-2.8.7.html
Running on: Linux 6.5.0-17-generic #17~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 16 14:32:32 UTC 2 x86_64
# 실행
sudo systemctl enable haproxy.service && sudo systemctl start haproxy.service
sudo systemctl status haproxy.service
# 설정 추가(web)
sudo vi /etc/haproxy/haproxy.cfg
listen stats
bind :9000
stats enable
stats uri /
stats auth Admin:xgtest!@
# 재기동 후 확인
sudo systemctl reload haproxy && sudo systemctl status haproxy.service
# 브라우저 확인(Admin:xgtest!@)
10.10.x.182:9000
10.10.x.183:9000
HAproxy HA 설정 - keepalived
# 환경설정
sudo vi /etc/sysctl.conf
net.ipv4.ip_nonlocal_bind=1
sudo sysctl -p
# 설치
sudo apt update && sudo apt install -y keepalived
# 설정파일 생성
sudo vi /etc/keepalived/keepalived.conf
global_defs {
router_id haproxy1
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 50
priority 200
advert_int 1
authentication {
auth_type PASS
auth_pass xgtest
}
virtual_ipaddress {
10.10.x.181
}
}
---------------------------------------------------
global_defs {
router_id haproxy2
}
vrrp_instance VI_2 {
state BACKUP
interface eth0
virtual_router_id 50
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass xgtest
}
virtual_ipaddress {
10.10.x.181
}
}
# 실행 후 확인
sudo systemctl enable keepalived.service && sudo systemctl start keepalived.service
sudo systemctl status keepalived.service
# ip 확인
ip a
....
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
....
inet 10.10.x.182/24 brd 10.10.x.255 scope global eth0
valid_lft forever preferred_lft forever
inet 10.10.x.181/32 scope global eth0
valid_lft forever preferred_lft forever
....
....
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
...
inet 10.10.x.183/24 brd 10.10.x.255 scope global eth0
valid_lft forever preferred_lft forever
....
- 사이트 확인 : VIP:9000
728x90
반응형
Comments