-
HAproxy - Keepalived - Apache 설정(수정중)OS/centos 2022. 5. 12. 17:44
수정중
keepalived 설치
VIP : 192.168.202.13
MASTER : 192.168.202.11
BACKUP : 192.168.202.12
yum install -y keepalived
vi /etc/sysctl.conf
추가
net.ipv4.ip_forward = 1
net.ipv4.ip_nonlocal_bind = 1
:wq!sysctl -p
[MASTER, SLAVE 각각]
=============================
vi /etc/keepalived/keepalived.conf
global_defs {
router_id web01
}
vrrp_instance VI_1 {
state MASTER
interface enp0s8
virtual_router_id 51
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
unicast_src_ip 192.168.202.11
unicast_peer {
192.168.202.12
}
virtual_ipaddress {
192.168.202.13/24 dev enp0s8 label enp0s8:1
}
}=============================
vi /etc/keepalived/keepalived.conf
global_defs {
router_id web02
# vrrp_skip_check_adv_addr
# vrrp_strict
# vrrp_garp_interval 0
# vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state BACKUP
interface enp0s8
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
unicast_src_ip 192.168.202.12
unicast_peer {
192.168.202.11
}
virtual_ipaddress {
192.168.202.13/24 dev enp0s8 label enp0s8:1
}
}=============================
systemctl start keepalived
systemctl status keepalived
systemctl enable keepalived
keepalived haproxy httpd 설치
VIP : 192.168.72.85
Master : 192.168.72.86
Slave : 192.168.72.87
yum -y install haproxy keepalived httpd
vi /etc/sysctl.conf
추가
net.ipv4.ip_forward = 1
net.ipv4.ip_nonlocal_bind = 1
:wq!
sysctl -p
vi /etc/httpd/conf/httpd.conf
포트변경
Listen 80 => Listen 8780
:wq!
vi /var/www/html/index.html
수정
hello
:wq!
vi /etc/keepalived/keepalived.conf
내용수정
[Master]
global_defs {
router_id web01
}
vrrp_instance VI_1 {
state MASTER
nopreempt
interface enp0s8
virtual_router_id 51
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
# vrrp_unicast_bind 192.168.72.86
# vrrp_unicast_peer 192.168.72.87
unicast_src_ip 192.168.72.86
unicast_peer {
192.168.72.87
}
virtual_ipaddress {
192.168.72.85/24 dev enp0s8 label enp0s8:1
}
}
wq:!
[Slave]
global_defs {
router_id web02
}
vrrp_instance VI_1 {
state BACKUP
nopreempt
interface enp0s8
virtual_router_id 51
priority 103
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
# vrrp_unicast_bind 192.168.72.87
# vrrp_unicast_peer 192.168.72.86
unicast_src_ip 192.168.72.87
unicast_peer {
192.168.72.86
}
virtual_ipaddress {
192.168.72.85/24 dev enp0s8 label enp0s8:1
}
}
:wq!
vi /etc/haproxy/haproxy.cfg
[Master, Slave 동일]
내용수정
frontend main *:80
acl url_static path_beg -i /static /images /javascript /stylesheets
acl url_static path_end -i .jpg .gif .png .css .js
use_backend static if url_static
default_backend app
#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
balance roundrobin
server static1 192.168.72.86:8780 check
server static2 192.168.72.87:8780 check
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
balance roundrobin
server app1 192.168.72.86:8780 check
server app2 192.168.72.87:8780 check
systemctl restart keepalived
systemctl restart haproxy
systemctl restart httpd==================
[EQUAL 사용]
global_defs {
router_id web02
}
vrrp_script chk_haproxy {
script "killall -0 haproxy"
interval 5
fall2
rise 1
weight 20
}
vrrp_instance VI_1 {
state EQUAL
interface enp0s8
virtual_router_id 51
priority 100
advert_int 1
# nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
unicast_src_ip 192.168.72.57
unicast_peer {
192.168.72.56
}
virtual_ipaddress {
192.168.72.55 dev enp0s8 label enp0s8:1
}
track_script {
chk_haproxy
}
}'OS > centos' 카테고리의 다른 글
haproxy 로깅 설정 (0) 2022.11.04 ssh 비밀번호 없이 접속하기 (0) 2022.11.04 NTP서버 구성(chrony) - Master, Client (0) 2022.05.02 CentOS7 기본설정 - VirtualBox (0) 2022.04.06 CentOS7 - NFS 연동 (0) 2022.04.06