好久没用过keepalived 以前用的时候也没有做过笔记,基本上都忘的差不多了,今天整理的时候记录一下.
master配置:
global_defs { notification_email { 125698756@qq.com } notification_email_from admin@qq.com smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL}#vrrp_sync_group VG_1 {#group {#VI_1#}#notify_master /usr/local/master.sh#notify_backup /usr/local/backup.sh#}vrrp_script check_running{ script /home/check.sh interval 8 weight -10 fall 2 rise 2}vrrp_instance VI_1{ state MASTER interface eth0 virtual_router_id 51 priority 152 debug nopreempt advert_int 3 preempt_delay 60 dont_track_primary track_interface { eth0 eth1} authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 172.168.10.200/24 } track_script { check_running }notify_master /usr/local/master.shnotify_backup /usr/local/backup.sh}
backup配置:
global_defs { notification_email { 125698756@qq.com } notification_email_from admin@qq.com smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL}#vrrp_sync_group VG_1 {#group {#VI_1#}#notify_master /usr/local/master.sh#notify_backup /usr/local/backup.sh#}vrrp_script check_running{ script /home/check.sh interval 8 weight -10 fall 2 rise 2}vrrp_instance VI_1{ state BACKUP interface eth0 virtual_router_id 51 priority 151 debug# nopreempt preempt_delay 60 advert_int 3 dont_track_primary track_interface { eth0 eth1} authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 172.168.10.200/24 } track_script { check_running }notify_master /usr/local/master.shnotify_backup /usr/local/backup.sh}
对与配置文件书写,特别需要注意track_script {
之间一定要一个空格符 不然配置会解释错误
master 配置需要有nopreempt
参数,避免master恢复后抢占,再贴一下check.sh的脚本内容
#!/bin/baship add list|grep '172.168.10.200/24' || exit 0count=`ps aux | grep -v grep | grep crond | wc -l`if [[ $count -eq 0 ]]; thensleep 1.5count=`ps aux | grep -v grep | grep crond | wc -l`[ $count -eq 0 ] && exit 1elseecho $count >> /home/log.txtexit 0fi