haproxy+keepalived配置
来源:互联网 发布:暗黑2 1.13 完美 mac 编辑:程序博客网 时间:2024/06/05 04:45
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
阅读全文
0 0
- Haproxy+keepalived安装配置
- haproxy+keepalived配置
- Haproxy+keepalived负载均衡配置
- Haproxy+keepalived负载均衡配置
- Keepalived&Haproxy的简单安装配置
- HaProxy+keepalived+mycat集群高可用配置
- HaProxy+Keepalived+Mycat高可用群集配置
- haproxy+keepalived 主备模式安装配置
- RabbitMQ高可用配置(Haproxy + Keepalived)
- hive+haproxy+keepalived高可用配置
- SaltStack-02Haproxy以及Keepalived配置
- haproxy+keepalived
- HAProxy+Keepalived
- haproxy+keepalived
- HAproxy+keepalived
- haproxy+keepalived
- haproxy+keepalived
- 高可用的负载均衡配置方法(Haproxy+KeepAlived)
- 4556: [Tjoi2016&Heoi2016]字符串 后缀自动机 详细
- SFP光模块大全,你想了解的这里都有!
- scala 九大排序算法
- Django-Cookie的使用
- 常见的视频流协议
- haproxy+keepalived配置
- 多边形划分-卡特兰数
- Merge into使用详解-
- Django-Cookie与装饰器
- MySQL主从
- Java读写Excel之POI超入门
- 0.0纯虚函数
- IntelliJ IDEA 设置代码提示或自动补全的快捷键
- XlistView上拉刷新下拉加载