您好,登錄后才能下訂單哦!
? ? Keepalived高可用
1.Keepalived通知配置?
發件人配置:
[root@s2 ~]# yum install mailx -y
[root@s2 ~]# vim /etc/mail.rc
set from=398808313@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=398808313@qq.com
set smtp-auth-password=mfcjxxjezawgdgee?
set smtp-auth=login
set ssl-verify=ignore
?
set smtp-auth-password=mfcjxxjezawgdgee詳解:
(1)進入qq郵箱
開啟這個選項,然后按照一步步的生成這個值。
?
Keepalived通知腳本
[root@localhost keepalived]# cat /etc/keepalived/notify.sh
#!/bin/bash
contact='2973707860@qq.com'
notify() {
mailsubject="$(hostname) to be $1, vip 轉移"
mailbody="$(date +'%F %T'): vrrp transition, $(hostname) changed to be $1"
echo "$mailbody" | mail -s "$mailsubject" $contact
}
case $1 in
master)
notify master
;;
backup)
notify backup
;;
fault)
notify fault
;;
*)
echo "Usage: $(basename $0) {master|backup|fault}"
exit 1
;;
esac
?
Keepalived通知配置?
? 定義通知腳本:
notify_master <STRING>|<QUOTED-STRING>:
當前節點成為主節點時觸發的腳本
notify_backup <STRING>|<QUOTED-STRING>:
當前節點轉為備節點時觸發的腳本
notify_fault <STRING>|<QUOTED-STRING>:
當前節點轉為“失敗”狀態時觸發的腳本
notify <STRING>|<QUOTED-STRING>:
通用格式的通知觸發機制,一個腳本可完成以上三種狀態的轉換時的通知
?
2.?keepalived+haproxy
???當haproxy宕機后,vip也會漂移到其他的備份主機上。
??高可用HAProxy(keepalived主配置文件)?
vrrp_script chk_haproxy {
script "/etc/keepalived/chk_haproxy.sh"
interval 1
weight -80
fall 3
rise 5
timeout 2
}
有要求
track_script {
chk_haproxy
}
?
[root@s1 ~]# yum install psmisc -y (killall程序包)
[root@s1 ~]# cat /etc/keepalived/chk_haproxy.sh
#!/bin/bash
/usr/bin/killall -0 haproxy (檢查程序是否存活)
[root@s1 ~]# chmod a+x /etc/keepalived/chk_haproxy.sh
?
?
?
?
?
?
?
?
?
3.?keepalived+nginx
和上面的haproxy差不多。
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
4.Keepalived案例一:實現LVS-DR模式?
virtual_server 172.18.200.248 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
#persistence_timeout 120 #會話保持時間
protocol TCP
sorry_server 172.18.200.105 80
real_server 172.18.200.103 80 {
weight 1
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
?}
real_server 172.18.200.104 80 {
weight 1
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
?}
?}
?
?
?
?
?
?
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。