#1. 前期准备
IP
|
角色 | Haproxy |
Keepalived
|
192.168.68.133 |
MASTER
|
安装配置
|
安装配置
|
192.168.68.134
|
BACKUP
|
安装配置
|
安装配置
|
高可用搭建规划图:
: Undefined array key "dark" in /www/wwwroot/wql_luoqin_ltd/wp-content/themes/Sakura/functions.php on line 694
class="post-template-default single single-post postid-3043 single-format-standard wp-custom-logo chinese-font ">
发布于 2022-07-28 2.61k 次阅读
IP
|
角色 | Haproxy |
Keepalived
|
192.168.68.133 |
MASTER
|
安装配置
|
安装配置
|
192.168.68.134
|
BACKUP
|
安装配置
|
安装配置
|
高可用搭建规划图:
① 编写检测haproxy的shell脚本haproxy_check.sh
#!/bin/bash ##判断haproxy的进程是否存在,不存在即为0 A=`ps -C haproxy --no-header | wc -l` if [$A -eq 0];then #不存在就重新启动 /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.conf echo "haproxy restart……" &> /dev/null #延时3秒 sleep 3s #当haproxy宕机时,关闭keepalived if [`ps -C haproxy --no-header | wc -l` -eq 0];then kill -9 $(ps -ef | grep keepalived) fi fi
② 192.168.68.133配置文件
global_defs { notification_email { #邮箱可以随便添 fq@qq.com } #邮箱可以随便添 notification_email_from wql@qq.com #必须填写同一个网段 smtp_server 192.168.68.1 smtp_connect_timeout 30 #名称改为haproxy01 router_id haproxy01 #使用默认 vrrp_skip_check_adv_addr vrrp_strict vrrp_garp_interval 0 vrrp_gna_interval 0 } vrrp_script chk_haproxy{ ##引入一个脚本 script "/etc/keepalived/haproxy_check.sh" interval 2 weight 2 } vrrp_instance VI_1 { #标记为MASTER state MASTER #填写自己的网卡,我的为ens33,有些为eth0需要根据自己的linux虚拟机而定 interface ens33 #两台keepalived用同一个id virtual_router_id 51 #优先级,MASTER要比BACKUP的数字大 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } ##将track_script块加入instance配置块 track_script{ chk_haproxy ##检查Haproxy服务是否存活 } virtual_ipaddress { #虚拟的主机IP,也可以填写多个 192.168.68.222 } }
global_defs { notification_email { #邮箱可以随便添 fq@qq.com } #邮箱可以随便添 notification_email_from wql@qq.com #必须填写同一个网段 smtp_server 192.168.68.1 smtp_connect_timeout 30 #名称改为haproxy01 router_id haproxy01 #使用默认 vrrp_skip_check_adv_addr vrrp_strict vrrp_garp_interval 0 vrrp_gna_interval 0 } vrrp_script chk_haproxy{ ##引入一个脚本 script "/etc/keepalived/haproxy_check.sh" interval 2 weight 2 } vrrp_instance VI_1 { #标记为MASTER state BACKUP #填写自己的网卡,我的为ens33,有些为eth0需要根据自己的linux虚拟机而定 interface ens33 #两台keepalived用同一个id virtual_router_id 51 #优先级,MASTER要比BACKUP的数字大 priority 77 advert_int 1 authentication { auth_type PASS auth_pass 1111 } ##将track_script块加入instance配置块 track_script{ chk_haproxy ##检查Haproxy服务是否存活 } virtual_ipaddress { #虚拟的主机IP,也可以填写多个 192.168.68.222 } }
④ 启动keepalived
/usr/local/sbin/keepalived start
⑤ 配置完成后重启,并查看虚拟IP是否绑定:
ip a
① 配置文件(133和134两台服务器都一样)
global maxconn 100000 chroot /apps/haproxy stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin uid 99 gid 99 daemon pidfile /var/lib/haproxy/haproxy.pid log 127.0.0.1 local2 info defaults option http-keep-alive option forwardfor maxconn 100000 mode http timeout connect 300000ms timeout client 300000ms timeout server 300000ms listen stats mode http bind 0.0.0.0:9999 stats enable log global stats uri /haproxy-status stats auth haadmin:123456 listen web_port bind 0.0.0.0:80 mode http log global server web1 127.0.0.1:8080 check inter 3000 fall 2 rise 5
② 启动Haproxy
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.conf
③ 使用虚拟IP访问haproxy监控台
Comments | NOTHING
Warning: Undefined variable $return_smiles in /www/wwwroot/wql_luoqin_ltd/wp-content/themes/Sakura/functions.php on line 1109