您的位置:首页 > 理论基础 > 计算机网络

[原创]用python检测LVS real server状态实现HTTP高可用

2013-10-24 18:55 597 查看
import httplib
import os
import time

def check_http(i):
try:
conn=httplib.HTTPConnection(i, 80, timeout=2)
conn.request("GET","/")
response = conn.getresponse()
except Exception as e:
print "server "+i+" is down"
print e
print ""
os.system('./delete_real_server.sh '+i)
else:
#print response.read()
print "server "+i+" is up\n"
os.system('./add_real.server.sh '+i)

if __name__=="__main__":
httpservers=["127.0.0.1","10.0.0.1","192.168.35.28"]
while 1:
current_time=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
for i in httpservers:
check_http(i)
print current_time+" check finish\n"
time.sleep(60)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: