• keepalive笔记之二:keepalive+nginx(自定义脚本实现,上述例子也可以实现)


    keepalive的配置文件

    ! Configuration File for keepalived
     
    global_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 check_80 {                         //定义vrrp脚本
       script '/root/check_code.py'               //脚本路径
       interval 2                                   //脚本检测时间间隔,脚本必须在间隔时间内返回状态,不然日志报错
    //Keepalived_vrrp[7813]: Process [7894] didn't respond to SIGTERM
       weight -2                                    //当脚本返回的状态码不是0时,操作权重
    }
    vrrp_instance VI_1 {
        state MASTER
        interface eth0
        virtual_router_id 51
        priority 100
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        virtual_ipaddress {
            192.168.89.100
        }
        track_script {                       //定义监控脚本
        check_80
        }
    }

    使用的脚本:/root/check_code.py

    (该脚本检查http的状态吗,如果不是200,则关闭keepalive服务,使VIP漂移到备份机上)
    #!/usr/bin/env python
    import urllib2
    import os
    url = 'http://192.168.89.81/index.html'
    try:
        check_code = urllib2.urlopen(url,timeout=1).code
    except Exception,e:
        print e
        check_code = 444
    print check_code
    if check_code == 200:
        pass
    else:
        os.system('service keepalived stop')
     
  • 相关阅读:
    java.util.Properties类
    java中log日志的使用(完全版)
    解读HDFS(转载)
    说明
    定时器中断和串口
    python day3
    python day2 基础总结:列表,元组,字典,集合
    python第二天作业:购物车
    作业总结:
    python第一天作业:用户登陆
  • 原文地址:https://www.cnblogs.com/djoker/p/6396673.html
Copyright © 2020-2023  润新知