系统环境:
操作系统:CentOS7.2
依赖软件:Keepalived + Nginx
网络环境:
Zabbix Master:192.168.5.251
Zabbix Backup:192.168.5.252
Nginx编译
Keepalived Master
! Configuration File for keepalivedglobal_defs { notification_email { acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc } notification_email_from Alexandre.Cassen@firewall.loc smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id LVS_DEVEL}vrrp_script chk_mantaince_down { script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0" interval 1 weight -5}vrrp_script chk_nginx_status { script "[[ service nginx status | grep -q "active (running)" ]] && exit 0 || exit 1" interval 1 weight -5}vrrp_instance VI_1 { state MASTER interface eno16777736 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.5.100/24 label eno16777736:0 } track_script { chk_mantaince_down chk_nginx_status } notify_master "/etc/keepalived/notify.sh master" notify_backup "/etc/keepalived/notify.sh backup" notify_fault "/etc/keepalived/notify.sh fault"}
Keepalived BACKUP
! Configuration File for keepalivedglobal_defs { notification_email { acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc } notification_email_from Alexandre.Cassen@firewall.loc smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id LVS_DEVEL}vrrp_script chk_mantaince_down { script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0" interval 1 weight -5}vrrp_script chk_nginx_status { script "[[ service nginx status | grep -q "active (running)" ]] && exit 0 || exit 1" interval 1 weight -5}vrrp_instance VI_1 { state BACKUP interface eno16777736 virtual_router_id 51 priority 98 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.5.100/24 label eno16777736:0 } track_script { chk_mantaince_down chk_nginx_status } notify_master "/etc/keepalived/notify.sh master" notify_backup "/etc/keepalived/notify.sh backup" notify_fault "/etc/keepalived/notify.sh fault"}
Notify脚本
# !/bin/bash# Author: MageEdu# description: An example of notify script#vip=172.16.100.1contact='root@localhost'notify() { mailsubject="`hostname` to be $1: $vip floating" mailbody="`date '+%F %H:%M:%S'`: vrrp transition, `hostname` changed to be $1" echo $mailbody | mailx -s "$mailsubject" $contact}case "$1" in master) notify master service nginx start exit 0 ;; backup) notify backup service nginx stop exit 0 ;; fault) notify fault service nginx stop exit 0 ;; *) echo 'Usage: `basename $0` {master|backup|fault}' exit 1 ;;esac