高可用集群
keepalived+haproxy
1、1臺client,1臺master haproxy+keepalived 1臺backup keepalived+haproxy
兩臺real server (安裝http服務(wù))
準(zhǔn)備
1、下載haproxy 配置文件
frontend? main *:80
? ? #acl? php? ? url_reg? -i? ? \.php$? ? ?
? ? acl? html? url_reg? -i? ? \.html? ? ? ///匹配html結(jié)尾的字段
? ? #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? (可以加在已經(jīng)擁有ip的網(wǎng)卡上)
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、當(dāng)個haproxy突然down機后由于keepalived并沒有影響所以會導(dǎo)致崩潰
所以的用腳本檢測
#!/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? ? ///每兩秒檢查一回
}
如何調(diào)用出這個函數(shù)
track_script {
chk_haproxy主備檢測腳本
}
將這些寫在keepalived.conf 中,就會實現(xiàn)腳本的檢測。