keepalived高可用

    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高可用

开启这个选项,然后按照一步步的生成这个值。

 

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高可用 

Keepalived通知配置 

•定义通知脚本:

notify_master |

当前节点成为主节点时触发的脚本

notify_backup |

当前节点转为备节点时触发的脚本

notify_fault |

当前节点转为“失败”状态时触发的脚本

notify |

通用格式的通知触发机制,一个脚本可完成以上三种状态的转换时的通知

 

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

}

keepalived高可用要求keepalived高可用

track_script {

chk_haproxy

}

keepalived高可用 

[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

}

 }

 }

 

 

 

 

 

 


分享题目:keepalived高可用
文章路径:http://scyanting.com/article/gsdjch.html