مقدمه
دسترسی بالا برای سرویسها نیاز به load balancing (HAProxy) و failover برای خود load balancer (Keepalived با VRRP) دارد.
معماری
TEXT
کلاینتها → [IP مجازی: 10.0.0.100]
|
[HAProxy-1 (Master)] [HAProxy-2 (Backup)]
| |
[Web-1:80] [Web-2:80] [Web-3:80]پیکربندی HAProxy
TEXT
frontend web-frontend
bind *:80
bind *:443 ssl crt /etc/haproxy/certs/combined.pem
redirect scheme https if !{ ssl_fc }
default_backend web-servers
backend web-servers
balance roundrobin
option httpchk GET /health HTTP/1.1
Host: localhost
server web-1 10.0.1.10:80 check inter 2s rise 2 fall 3
server web-2 10.0.1.11:80 check inter 2s rise 2 fall 3پیکربندی Keepalived
Master (10.0.0.10):TEXT
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass YourSecretPass123
}
virtual_ipaddress {
10.0.0.100/24 dev eth0
}
}آزمایش Failover
BASH
while true; do curl -s http://10.0.0.100/ | grep "server"; sleep 1; done
systemctl stop haproxy # روی master
# IP مجازی باید ظرف ۲-۴ ثانیه به backup منتقل شود