ha+keeplived
环境准备
关闭selinux和防火墙
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
192.168.1.13 haproxy节点keepalived主节点
192.168.1.14 haproxy节点keepalived副节点
192.168.1.15 web服务器
192.168.1.16 web服务器
-
13和14两台服务器分别下载haproxy跟keepalived
yum -y install haproxy keepalived -
配置13跟14两台服务器的haproxy的配置文件
global log 127.0.0.1 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user haproxy group haproxy daemon # turn on stats unix socket stats socket /var/lib/haproxy/stats defaults mode http log global option httplog option dontlognull option http-server-close option forwardfor except 127.0.0.0/8 option redispatch retries 3 timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s maxconn 3000 frontend app mode http bind *:9090 option tcplog default_backend app backend app balance roundrobin server 192.168.1.15 192.168.1.15:8080 check server 192.168.1.16 192.168.1.16:8080 check listen stats bind *:1080 stats auth admin:success123 stats refresh 5s stats realm HAProxy\ Statistics stats uri /adminsystemctl start haproxy systemctl enable haproxy 测试访问 192.168.1.13:9090/test/index.html 后端监控 192.168.1.13:1080/admin配置13的keepalived
vim /etc/keepalived/keepalived.conf! Configuration File for keepalived global_defs { router_id app_router } vrrp_script check_script { script "killall -0 haproxy" interval 3 weight -2 fall 10 rise 2 } vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 41 priority 200 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.254 } tarck_script { check_haproxy } }配置14的keepalived.conf
! Configuration File for keepalived global_defs { router_id app_router } vrrp_script check_script { script "killall -0 haproxy" interval 3 weight -2 fall 10 rise 2 } vrrp_instance VI_1 { state BACKUP interface ens33 virtual_router_id 41 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.254 } tarck_script { check_haproxy } }配置13和14的keepalived
systemctl start keepalived systemctl enable keepalived测试访问
关掉13服务器查看虚拟ip是否跳到14上
并且访问虚拟ip
192.168.1.254:9090/test/index.html

浙公网安备 33010602011771号