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 /admin
systemctl 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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?