zoukankan      html  css  js  c++  java
  • IIS状态监测(如果状态错误则重启IIS)

    步骤:

    1:建立健康监测文件。文件内容随意,这里以healthcheck.aspx命名,内容是<span>hellow word</span>

    2:利用vbs语言执行IIS重启

    文件名称:AppPoolRecycle.vbs

    注意:自行修改进程池的名称这里是“DefaultAppPool”

    strComputer = "."
    Set objWMIService = GetObject _
        ("winmgmts:{authenticationLevel=pktPrivacy}\" _
            & strComputer & "
    ootmicrosoftiisv2")
    '回收名为DefaultAppPool的应用程序池
    Set colItems = objWMIService.ExecQuery _
        ("Select * From IIsApplicationPool Where Name = " & _
            "'W3SVC/AppPools/DefaultAppPool'")
    For Each objItem in colItems
        objItem.Recycle
    Next
    

    2:利用VBS调用curl进行探测,利用grep对探测结果进行筛选

    文件名称:IISchk.vbs

    注意:

    A:文件路径中不能有空格,自行修改探测的文件地址这里是http://localhost/healthcheck.aspx

    B:本代码位置是C:healthcheck

    C:附件清单(文件夹curl里面有32位64位两个版本外部的curl.exe是32位;grep文件夹里是该软件的安装程序;AppPoolRecycle.vbs 重启脚本;IISchk.vbs检查脚本;curl.txtcurl结果文件;grep.txt grep结果文件;)

    d:C:ProgramFilesGnuWin32ingrep.exe 这个是我的grep安装目录,路径不能有空格

    E:建立计划任务周期执行IISchk.vbs脚本就可以了

    Set objShell = CreateObject("Wscript.Shell")
    '利用curl获取目标网页的http头信息
    strcmd1 = "%comspec% /c C:healthcheckcurl -I http://localhost/healthcheck.aspx -o c:healthcheckcurl.txt"
    '利用grep筛选出curl获取的关键行HTTP/1.1
    strcmd2 = "%comspec% /c C:ProgramFilesGnuWin32ingrep.exe -i HTTP/1.1 c:healthcheckcurl.txt > c:healthcheckgrep.txt"
    objShell.Run(strcmd1)
    '等待500毫秒让strcmd1的文件写完,因为strcmd2需要这个文件
    WScript.Sleep 500
    objShell.Run(strcmd2)
    '打开经过筛选后的grep.txt文本
    Const ForReading=1
    Dim strLine,strnewline
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile("c:healthcheckgrep.txt", ForReading)
    strLine = objTextFile.ReadLine
    '去掉头尾的空格
    strnewline  = Trim(strLine)
    '判断行是否等于HTTP/1.1 200 OK,如果不等于则运行c:healthcheckAppPoolRecycle.vbs
    If not strnewline = "HTTP/1.1 200 OK" then
    objShell.Run("c:healthcheckAppPoolRecycle.vbs")
    End if
    

    F:用到的文件

  • 相关阅读:
    百度地图中循环输出坐标点信息是重复的问题解决方法
    质问微软 WP8.1开发HTTPS 真费劲
    WebService 页面重定向错误
    Oracle 错误 maximum number of processes(150) exceeded 解决办法
    spring quartz定时任务 配置
    centos 7安装完后出现please make your choice from '1' to e
    centos单机安装Hadoop2.6
    centos 关闭防火墙
    CentOS 7 系统下安装gnome图形界面
    CentOS 7 ifconfig: command not found
  • 原文地址:https://www.cnblogs.com/tommyli/p/3156448.html
Copyright © 2011-2022 走看看