2018-12-03

高可用集群

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)腳本的檢測。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 本文描述的是haproxy做代理,負(fù)載均衡,haproxy狀態(tài)查看,后端主機的上下線,keepalived高可用 ...
    think_lonely閱讀 5,905評論 0 7
  • 一、高可用集群 (一)提升系統(tǒng)高可用性的解決方案:冗余(redundant) 工作模式active/passive...
    哈嘍別樣閱讀 1,811評論 2 5
  • 轉(zhuǎn)載自:http://blog.csdn.net/u010391029/article/details/48311...
    Chris_Zheng閱讀 1,551評論 0 2
  • nginx+php集群 利用nginx訪問網(wǎng)頁,php做解析 1、1臺主機(只開啟nginx,php不需要開啟) ...
    4e0b3c520bb8閱讀 173評論 0 0
  • 昨天到一個新村子探望親戚,晚上沒事我出來走走。由于不熟悉,之前往返只走一條路,整個村子像一個口袋,我們?nèi)サ臅r候鉆進...
    Inker閱讀 195評論 0 1

友情鏈接更多精彩內(nèi)容