高可用集群
keepalived+haproxy
1、1台client,1台master haproxy+keepalived 1台backup keepalived+haproxy
两台real server (安装http服务)
准备
1、下载haproxy 配置文件
frontend main *:80
#acl php url_reg -i \.php$
acl html url_reg -i \.html ///匹配html结尾的字段
#use_backend php-server if php
use_backend html-server if html
#default_backend html-server
backend html-server
#mode http
balance roundrobin
option httpchk GET /index.html
#cookie SERVERID insert indirect nocache
server html-A 172.25.3.134:80 weight 1 check inter 2000 rise 2 fall 5 ///配置real server 的ip
server html-A 172.25.111.175:80 weight 3 check inter 2000 rise 2 fall 5
2、使用 ip addr add vip dev eth0 (可以加在已经拥有ip的网卡上)
curl - L vip 测试 (主,备用都测试)
3、下载keepalived
配置keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 172.25.111.176
smtp_connect_timeout 30
router_id HAproxy1
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.25.111.170/16 ////浮动ip
}
###############################################################################
此时是由漏洞的
1、当个haproxy突然down机后由于keepalived并没有影响所以会导致崩溃
所以的用脚本检测
#!/bin/bash
A=`ps -C haproxy --no-header | wc -l`
if [ $A -eq 0 ]
then
systemctl restart haproxy
sleep 3
if [ `ps -C haproxy --no-header | wc -l ` -eq 0 ]
then /etc/init.d/keepalived stop
fi
fi
如何使用脚本添加检测:
在高可用集群中如何用脚本检查完善的步骤
vrrp_scriptchk_haproxy{
script "/etc/keepalived/chk_haproxy.sh"
interval 2 ///每两秒检查一回
}
如何调用出这个函数
track_script {
chk_haproxy主备检测脚本
}
将这些写在keepalived.conf 中,就会实现脚本的检测。