主程序:keepalived
主配置文件:/etc/keepalived/keepalived.conf
单主模型ipvs:
global_defs {notification_email {root@localhost}notification_email_from keepalived@localhostsmtp_server 127.0.0.1smtp_connect_timeout 30router_id node1vrrp_mcast_group4 224.0.100.19}vrrp_instance VI_1 {state MASTERinterface eno16777736virtual_router_id 14priority 100advert_int 1authentication {auth_type PASSauth_pass 571f97b2}virtual_ipaddress {10.1.0.93/16 dev eno16777736}notify_master “/etc/keepalived/notify.sh master”notify_backup “/etc/keepalived/notify.sh backup”notify_fault “/etc/keepalived/notify.sh fault”}virtual_server 10.1.0.93 80 {delay_loop 3lb_algo rrlb_kind DRprotocol TCPsorry_server 127.0.0.1 80real_server 10.1.0.69 80 {weight 1HTTP_GET {url {path /status_code 200}connect_timeout 1nb_get_retry 3delay_before_retry 1}}real_server 10.1.0.71 80 {weight 1HTTP_GET {url {path /status_code 200}connect_timeout 1nb_get_retry 3delay_before_retry 1}}}
双主模型nginx:
global_defs {notification_email {root@localhost}notification_email_from keepalived@localhostsmtp_server 127.0.0.1smtp_connect_timeout 30router_id node1vrrp_mcast_group4 224.0.100.19}vrrp_script chk_down {script “[[ -f /etc/keepalived/down ]] && exit 1 || exit 0”interval 1weight -5}vrrp_script chk_nginx {script “killall -0 nginx && exit 0 || exit 1”interval 1weight -5fall 2rise 1}vrrp_instance VI_1 {state MASTERinterface ens33virtual_router_id 14priority 100advert_int 1authentication {auth_type PASSauth_pass 571f97b2}virtual_ipaddress {172.16.0.99/16 dev ens33}track_script {chk_downchk_nginx}notify_master “/etc/keepalived/notify.sh master”notify_backup “/etc/keepalived/notify.sh backup”notify_fault “/etc/keepalived/notify.sh fault”}vrrp_instance VI_2 {state MASTERinterface ens33virtual_router_id 24priority 96advert_int 1authentication {auth_type PASSauth_pass 571errrb2}virtual_ipaddress {172.16.0.98/16 dev ens33}track_script {chk_downchk_nginx}notify_master “/etc/keepalived/notify.sh master”notify_backup “/etc/keepalived/notify.sh backup”notify_fault “/etc/keepalived/notify.sh fault”}
示例通知脚本:
#!/bin/bash#contact=’root@localhost’notify() {mailsubject=”$(hostname) to be $1, vip floating”mailbody=”$(date +’%F %T’): vrrp transition, $(hostname) changed to be $1″echo “$mailbody” | mail -s “$mailsubject” $contact}case $1 inmaster)notify master;;backup)notify backup;;fault)notify fault;;*)echo “Usage: $(basename $0) {master|backup|fault}”exit 1;;esac
原创文章,作者:z long,如若转载,请注明出处:http://www.178linux.com/84220