haproxy+keepalived配置
2017-07-05 15:06
295 查看
haproxy+keepalived配置
1. cat keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
1041126478@qq.com
}
notification_email_from jzyc5@jzyc.com
smtp_server 192.168.44.27
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_state_down {
script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"
interval 2
weight 3
}
vrrp_script chk_haproxy {
script "/etc/keepalived/chk_haproxy.sh" #
interval 2 # script
weight 2
}
vrrp_instance VI_1 {
state MASTER
interface em2
virtual_router_id 27
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.44.102
}
track_script {
chk_haproxy #
chk_state_down
}
notify_master "/etc/keepalived/notify.sh master 192.168.44.102"
notify_backup "/etc/keepalived/notify.sh backup 192.168.44.102"
notify_fault "/etc/keepalived/notify.sh fault 192.168.44.102"
}
2. cat chk_haproxy.sh
#!/bin/bash
#
# author: weizhifeng
# description:
# ?¨?2?haproxyˇ·委???1?????ˉhaproxy£?
# ?1??°?????keepalived
#
status=$(ps aux|grep haproxy | grep -v grep | grep -v bash | wc -l)
if [ "${status}" = "0" ]; then
/etc/init.d/haproxy start
status2=$(ps aux|grep haproxy | grep -v grep | grep -v bash |wc -l)
if [ "${status2}" = "0" ]; then
/etc/init.d/keepalived stop
fi
3. cat notify.sh
# desccription: An example of notify script
#
contact='jzyc5@jzyc.com'
notify() {
mailsubject="`hostname` to be $1: $2 floating"
mailbody="`date '+%F %H:%M:%S'`: vrrp transition, `hostname` changed to be $1"
echo $mailbody | mail -s "$mailsubject" $contact
}
case "$1" in
master)
notify master
/etc/rc.d/init.d/haproxy start
exit 0
;;
backup)
notify backup
/etc/rc.d/init.d/haproxy stop
exit 0
;;
fault)
notify fault
/etc/rc.d/init.d/haproxy stop
exit 0
;;
*)
echo 'Usage: `basename $0` {master|backup|fault}'
exit 1
;;
esac
1. cat keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
1041126478@qq.com
}
notification_email_from jzyc5@jzyc.com
smtp_server 192.168.44.27
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_state_down {
script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"
interval 2
weight 3
}
vrrp_script chk_haproxy {
script "/etc/keepalived/chk_haproxy.sh" #
interval 2 # script
weight 2
}
vrrp_instance VI_1 {
state MASTER
interface em2
virtual_router_id 27
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.44.102
}
track_script {
chk_haproxy #
chk_state_down
}
notify_master "/etc/keepalived/notify.sh master 192.168.44.102"
notify_backup "/etc/keepalived/notify.sh backup 192.168.44.102"
notify_fault "/etc/keepalived/notify.sh fault 192.168.44.102"
}
2. cat chk_haproxy.sh
#!/bin/bash
#
# author: weizhifeng
# description:
# ?¨?2?haproxyˇ·委???1?????ˉhaproxy£?
# ?1??°?????keepalived
#
status=$(ps aux|grep haproxy | grep -v grep | grep -v bash | wc -l)
if [ "${status}" = "0" ]; then
/etc/init.d/haproxy start
status2=$(ps aux|grep haproxy | grep -v grep | grep -v bash |wc -l)
if [ "${status2}" = "0" ]; then
/etc/init.d/keepalived stop
fi
3. cat notify.sh
# desccription: An example of notify script
#
contact='jzyc5@jzyc.com'
notify() {
mailsubject="`hostname` to be $1: $2 floating"
mailbody="`date '+%F %H:%M:%S'`: vrrp transition, `hostname` changed to be $1"
echo $mailbody | mail -s "$mailsubject" $contact
}
case "$1" in
master)
notify master
/etc/rc.d/init.d/haproxy start
exit 0
;;
backup)
notify backup
/etc/rc.d/init.d/haproxy stop
exit 0
;;
fault)
notify fault
/etc/rc.d/init.d/haproxy stop
exit 0
;;
*)
echo 'Usage: `basename $0` {master|backup|fault}'
exit 1
;;
esac
相关文章推荐
- HAProxy+Keepalived高可用负载均衡配置
- haproxy+keepalived配置
- keepalived+haproxy配置故障
- Haproxy+keepalived负载均衡配置
- keepalived原理(主从配置+haproxy)及配置文件详解
- haproxy + keepalived “一键安装包” 配置与测试HOWTO
- Keepalived+HAProxy实现MySQL高可用负载均衡的配置
- HAProxy+Keepalived高可用负载均衡配置
- Keepalived&Haproxy的简单安装配置
- HAproxy Keepalived Tomcat Ftp 负载均衡配置
- haproxy + keepalived 安装配置
- Haproxy+Keepalived配置WEB负载均衡及动静分离 推荐
- CentOS6.4 配置HAProxy+Keepalived
- HaProxy+keepalived+mycat集群高可用配置
- 基于keepalived的Haproxy高可用配置 推荐
- haproxy+keepalived实现高可用负载均衡(实例配置)
- Centos6.3下haproxy+keepalived+apache配置笔记
- Haproxy+Keepalived配置WEB负载均衡及动静分离
- haproxy+keepalived配置
- HaProxy+Keepalived+Mycat高可用群集配置