keepalive笔记之二:keepalive+nginx(自定义脚本实现,上述例子也可以实现)
Posted 愤怒的绿萝
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了keepalive笔记之二:keepalive+nginx(自定义脚本实现,上述例子也可以实现)相关的知识,希望对你有一定的参考价值。
keepalive的配置文件
! Configuration File for keepalived global_defs { notification_email { [email protected] [email protected] [email protected] } notification_email_from [email protected] 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‘)
以上是关于keepalive笔记之二:keepalive+nginx(自定义脚本实现,上述例子也可以实现)的主要内容,如果未能解决你的问题,请参考以下文章