zoukankan      html  css  js  c++  java
  • 服务检测是否正常运行的shell脚本

    判断mysql服务是否正常启动
    ##############################################
    #
    # Author: yangxin - 934059036@qq.com
    #
    # QQ : 934059036
    #
    # Last modified: 2017-10-24 15:38
    #
    # Filename: Check_Mysql_Server.sh
    #!/bin/sh
     PORT=`netstat -lnt | grep 3306 | wc -l `
    Check_Mysql_Server()
    {
       
        if [ $PORT -eq 1 ]
         then
            echo "mysql is running"
        else
            echo "mysql is not running"
            echo "progrome reeady to start mysql "
            sudo service mysql start
        fi
    }
    Check_Mysql_Server
    检测ddos攻击
    #!/bin/sh
    netstat -an|grep SYN_RECV|awk '{print$5}'|awk -F: '{print$1}'|sort|uniq -c|sort -rn|awk '{if ($1>5) print $2}' >/tmp/dropip
    for i in $(cat /tmp/dropip)
    do
    /sbin/iptables -I INPUT -s $i -j DROP
    echo "$1 kill at `date`" >> /var/log/ddos
    done
     
    NGINX服务检查脚本 手动输入url判断
    #!/bin/sh  
    [ -f /etc/init.d/functions ]&&  source /etc/init.d/functions||exit 1
    if [ $# -ne 1 ];then
       echo "Usage:$0 ip"
       exit
    fi
    http_Code=`curl -I -s  $1|head -1|cut -d " " -f2`
    if [ "$http_Code" == "200" ];then
       action "nginx is running." /bin/true
    else
       action "nginx is not running." /bin/false
    sleep 1
       /application/nginx/sbin/nginx
    fi
    检测nginx服务
    #!/bin/sh
    LogPath=/application/tools/nginx-1.12.1/logs/access.log
    web_PORT=`netstat -lnt|grep 80|wc -l`
    web_Process=`ps -ef|grep nginx | grep -v grep |wc -l`
    if [ $web_PORT -eq 1 ]&&[ $web_Process -eq 2 ];then
       echo "web is running"
    else
     # nginx
       sleep 3
       web_PORT=`netstat -lnt|grep 80|wc -l`
       web_Process=`ps -ef|grep nginx | grep -v grep |wc -l`
       if [ $web_PORT -ne 1 ]&&[ $web_Process -ne 2 ];then
       while true
       do
           pkill nginx >/dev/null 2>&1
           sleep 1
          [ "$?" == "0" ] && break
          sleep 1    
      done
       nginx&&status="successful"||status="failure"
       #mail -s "web startup status is $status" 934059036@qq.com <$LogPath 
       echo "web is $status start"
      fi
    fi
    
  • 相关阅读:
    产品经理的十宗罪,你犯了几宗?
    产品经理的10大顾虑
    【FastAPI 学习 七】GET和POST请求参数接收以及验证
    【FastAPI 学习 六】异常处理
    【FastAPI 学习 五】统一响应json数据格式
    前端展示(三)
    前端展示(二)
    前端设计(一)
    后端流程分析
    生成词云图
  • 原文地址:https://www.cnblogs.com/shanghai1918/p/12842732.html
Copyright © 2011-2022 走看看