服务器服务运行状态监控脚本

服务器服务运行状态监控脚本

nginx反向代理,Ip经常变动不能实时刷新,所以会出现502等情况,写个Python脚本20秒请求一次,如果状态码不是200就重启nginx

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author  : Al4rm
import requests
import os
import time
while True:
    try:
        nginx = requests.get('http://localhost/',timeout=3)
        # 请求localhost,超时3
        if nginx.status_code != 200 :
        # 判断状态码
            os.system('killall nginx && service nginx restart')
            print 'nginx restart'
        else:
            print 'nginx is running'

    except Exception,e:
    # 返回异常原因
        print e
    time.sleep(20)
    # 间隔20秒请求一次


centos 部署django+nginx+redis+uwsgi+supervisor

centos 部署django+nginx+redis+uwsgi+supervisor

系统版本

[root@localhost conf.d]# cat /etc/issue
CentOS release 6.9 (Final)
Kernel \r on an \m

[root@localhost conf.d]# uname -a
Linux localhost.localdomain 2.6.32-696.6.3.el6.x86_64 #1 SMP Wed Jul 12 14:17:22 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost conf.d]#
yum update
#这些都是报错过程中装的
yum install gcc zlib zlib-devel openssl -y openssl-devel -y pcre-devel openssl-devel  mysql-server
yum install mysql mysql-devel

更多