您好,登录后才能下订单哦!
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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。