8.13和8.14的keepalived配置文件
8.13上的如下:
[robin@lb8-ha13 keepalived]$ pwd
/etc/keepalived
[robin@lb8-ha13 keepalived]$ ls
keepalived.conf scripts
[robin@lb8-ha13 keepalived]$ cd scripts/
[robin@lb8-ha13 scripts]$ ls
chk_haproxy.sh notify.sh
[robin@lb8-ha13 scripts]$ cat chk_haproxy.sh
#!/bin/bash
pid=`ps -C haproxy --no-header |wc -l`
if [ $pid -eq 0 ];then
service haproxy start
sleep 2
if [ `ps -C haproxy --no-header |wc -l` -eq 0 ];then
service keepalived stop
fi
fi
[robin@lb8-ha13 scripts]$ cat notify.sh
#!/bin/bash
Date=`date +%Y%m%d-%l:%M`
echo $Date>>/var/log/sms.log
echo "will send sms " >> /var/log/sms.log
Content="haproxy $(hostname) into $1"
Mobile="156********"
wget --post-data="token=***&mobile=$Mobile&content=$Content" http://sms.service.domain.com/task/create -O /dev/null
echo "send sms finish $Content $Mobile" >> /var/log/sms.log
#echo "Mobile=$Mobile Content=$Content"
[robin@lb8-ha13 scripts]$
[robin@lb8-ha13 keepalived]$ cat keepalived.conf
global_defs {
notification_email {
robin@qq.com
}
notification_email_from haproxy-support@qq.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id HAPROXY
}
vrrp_script chk_haproxy {
script "/etc/keepalived/scripts/chk_haproxy.sh"
interval 4
# weight 2
}
vrrp_sync_group VG1 {
group {
VI1_GATEWAY
}
}
vrrp_sync_group VG2 {
group {
VI2_GATEWAY
}
}
vrrp_instance VI1_GATEWAY {
state MASTER
interface eth0
lvs_sync_daemon_interface eth0
virtual_router_id 56
priority 51
smtp_alert
advert_int 1
sorry_server 127.0.0.1 80
authentication {
auth_type PASS
auth_pass hapass8
}
track_script {
chk_haproxy
}
virtual_ipaddress {
192.168.8.50
192.168.8.51
192.168.8.52
192.168.8.53
192.168.8.54
192.168.8.55
192.168.8.56
192.168.8.57
192.168.8.58
192.168.8.59
}
notify_master "/bin/bash /etc/keepalived/scripts/notify.sh master"
notify_backup "/bin/bash /etc/keepalived/scripts/notify.sh backup"
}
vrrp_instance VI2_GATEWAY {
state MASTER
interface eth0
lvs_sync_daemon_interface eth0
virtual_router_id 57
priority 50
smtp_alert
advert_int 1
sorry_server 127.0.0.1 80
authentication {
auth_type PASS
auth_pass hapass8
}
track_script {
chk_haproxy
}
virtual_ipaddress {
192.168.8.60
192.168.8.61
192.168.8.62
192.168.8.63
192.168.8.64
192.168.8.65
}
notify_master "/bin/bash /etc/keepalived/scripts/notify.sh master"
notify_backup "/bin/bash /etc/keepalived/scripts/notify.sh backup"
}
#include conf.d/*.conf
[robin@lb8-ha13 keepalived]$
8.14上如下:
[root@lb8-ha14 keepalived]# pwd
/etc/keepalived
[root@lb8-ha14 keepalived]# ls
keepalived.conf scripts
[root@lb8-ha14 keepalived]# cd scripts/
[root@lb8-ha14 scripts]# ls
chk_haproxy.sh notify.sh
[root@lb8-ha14 scripts]# cat chk_haproxy.sh
#!/bin/bash
pid=`ps -C haproxy --no-header |wc -l`
if [ $pid -eq 0 ];then
service haproxy start
sleep 2
if [ `ps -C haproxy --no-header |wc -l` -eq 0 ];then
service keepalived stop
fi
fi
[root@lb8-ha14 scripts]# cat notify.sh
#!/bin/bash
Date=`date +%Y%m%d-%l:%M`
echo $Date>>/var/log/sms.log
echo "will send sms " >> /var/log/sms.log
Content="haproxy $(hostname) into $1"
Mobile="156********" #过个手机号,用逗号分隔
wget --post-data="token=51********&mobile=$Mobile&content=$Content" http://sms.service.domain.com/task/create -O /dev/null
echo "send sms finish $Content $Mobile" >> /var/log/sms.log
#echo "Mobile=$Mobile Content=$Content"
[root@lb8-ha14 scripts]#
[root@lb8-ha14 keepalived]# cat keepalived.conf
global_defs {
notification_email {
robin@qq.com
}
notification_email_from haproxy-support@qq.cn
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id HAPROXY
}
vrrp_script chk_haproxy {
script "/etc/keepalived/scripts/chk_haproxy.sh"
interval 4
# weight 2
}
vrrp_sync_group VG1 {
group {
VI1_GATEWAY
}
}
vrrp_sync_group VG2 {
group {
VI2_GATEWAY
}
}
vrrp_instance VI1_GATEWAY {
state MASTER
interface eth0
lvs_sync_daemon_interface eth0
virtual_router_id 56
priority 50
smtp_alert
advert_int 1
sorry_server 127.0.0.1 80
authentication {
auth_type PASS
auth_pass hapass8
}
track_script {
chk_haproxy
}
virtual_ipaddress {
192.168.8.50
192.168.8.51
192.168.8.52
192.168.8.53
192.168.8.54
192.168.8.55
192.168.8.56
192.168.8.57
192.168.8.58
192.168.8.59
}
notify_master "/bin/bash /etc/keepalived/scripts/notify.sh master"
notify_backup "/bin/bash /etc/keepalived/scripts/notify.sh backup"
}
vrrp_instance VI2_GATEWAY {
state MASTER
interface eth0
lvs_sync_daemon_interface eth0
virtual_router_id 57
priority 51
smtp_alert
advert_int 1
sorry_server 127.0.0.1 80
authentication {
auth_type PASS
auth_pass hapass8
}
track_script {
chk_haproxy
}
virtual_ipaddress {
192.168.8.60
192.168.8.61
192.168.8.62
192.168.8.63
192.168.8.64
192.168.8.65
}
notify_master "/bin/bash /etc/keepalived/scripts/notify.sh master"
notify_backup "/bin/bash /etc/keepalived/scripts/notify.sh backup"
}
#include conf.d/*.conf
[root@lb8-ha14 keepalived]#
本文转自Tenderrain 51CTO博客,原文链接:http://blog.51cto.com/tenderrain/1630609,如需转载请自行联系原作者