zoukankan      html  css  js  c++  java
  • 合格linux运维人员必会的30道shell编程实践题及讲解-13

    企业实践题13:

    1、监控web服务是否正常,不低于3种监控策略。

    2、监控db服务是否正常,不低于3种监控策略。
    要求间隔1分钟,持续监控。

    我的脚本1==============

    #!/bin/bash
    [ -f /etc/init.d/functions ] && . /ect/init.d/functions
    if [ `netstat -nelp |grep -w 80|wc -l` -ne 0 ];then
        action "web service" /bin/true
    else
        action "web service" /bin/false
    
    if [ `netstat -nelp|grep -w 3306|wc -l` -ne 0 ];then
         action "db service" /bin/true
    else
         action "db service" /bin/false
    
    用定时任务crontab控制监控间隔时间
    */1 * * * * /bin/bash /scripts/listen_service.sh

    我的脚本2===============

    #!/bin/bash
    [ -f /etc/init.d/functions ] && . /ect/init.d/functions
    if [ `ps aux|grep -w http|wc -l` -ne 0 ];then
        action "web service" /bin/true
    else
        action "web service" /bin/false
    
    if [ `ps aux|grep -w http|wc -l` -ne 0 ];then
         action "db service" /bin/true
    else
         action "db service" /bin/false
    
    用定时任务crontab控制监控间隔时间
    */1 * * * * /bin/bash /scripts/listen_service.sh

    我的脚本3================

    #!/bin/bash
    [ -f /etc/init.d/functions ] && . /ect/init.d/functions
    if [ "`curl -I http://127.0.0.1 2>/dev/null|head -1|egrep "200|302|301" -ne 0 ];then
        action "web service" /bin/true
    else
        action "web service" /bin/false
    
    if [ `mysql -uroot -p123456 -P 3306 -e "show databases;"|wc -l` -ne 0 ];then
         action "db service" /bin/true
    else
         action "db service" /bin/false
    
    用定时任务crontab控制监控间隔时间
    */1 * * * * /bin/bash /scripts/listen_service.sh
  • 相关阅读:
    本地复现Zabbix v2.2.x, 3.0.0-3.0.3 jsrpc 参数 profileIdx2 SQL 注入漏洞
    本地搭建复现st2-045漏洞
    Ubuntu安装Vulapps漏洞靶场
    如何在腾讯云Ubuntu服务器安装kali下的神器
    nginx 跳转配置
    Chocolatey 的安装
    MySQL 5.1 主从同步配置
    针对Windows Server 2008 Web 服务 IIS+php 配置的一些心得
    解决IIS7+php的组合上传限制30M的问题
    ssh 文件权限影响登录
  • 原文地址:https://www.cnblogs.com/oliver-blogs/p/7723849.html
Copyright © 2011-2022 走看看