首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使网站平安服务器和说我要下去?

如何使网站平安服务器和说我要下去?
EN

Stack Overflow用户
提问于 2014-07-30 08:01:04
回答 1查看 590关注 0票数 1

我已经成功地配置了Windows环境中的ARR,将web服务器实例添加到服务器场。

在服务器场中使用Health选项,例如超时或不响应都是不健康的.

我的问题是

  1. 而不是ARR网站场(每10秒做一次健康检查)检查网站,这有可能吗?还是web角色本身回过ARR服务器,说我要掉下去了?

  1. 是否有可能将ARR服务器从web角色中删除,然后说我要崩溃了?或者这是最好的方法。 请建议一下。
EN

回答 1

Stack Overflow用户

发布于 2014-12-16 23:30:37

我想要一些额外的通知与我们的ARR设置,我把这个PowerShell脚本放在一起,每小时运行一次,检查健康状况,并通过电子邮件通知我,当任何主机服务器被认为是不健康的。我们还使用其他外部资源,这些外部资源每分钟在外部对web场进行一次平分,并在无法看到时提醒我们(Pingdom)。我有一种感觉,你想要的不仅仅是这个,但我希望它能帮上一点忙。

代码语言:javascript
复制
#----- First add a reference to the MWA dll ----#
$dll=[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
 
#----- Get the manager and config object ----#
$mgr = new-object Microsoft.Web.Administration.ServerManager
$conf = $mgr.GetApplicationHostConfiguration()
 
#----- Get the webFarms section ----#
$section = $conf.GetSection("webFarms")
$webFarms = $section.GetCollection()

#----- Define an array for html fragments ----#
$fragments=@()

#----- Check each webfarm ----#
foreach ($webFarm in $webFarms)
{
    $Name= $webFarm.GetAttributeValue("name");
    #Get the servers in the farm
    $servers = $webFarm.GetCollection()
    #Write-Host  "Farm Name: " $Name
    $fragments+= "<b>Farm Name: $Name</b>"
    $fragments+="<br>"
    foreach($server in $servers)
    {
         $ip= $server.GetAttributeValue("address")
         $hostname= ([system.net.dns]::GetHostByAddress($ip)).hostname
         #Get the ARR section
         $arr = $server.GetChildElement("applicationRequestRouting")
         $counters = $arr.GetChildElement("counters")
         $isHealthy=$counters.GetAttributeValue("isHealthy")
         $state= $counters.GetAttributeValue("state")
         switch ($state) 
         { 
                0 {$state= "Available"} 
                1 {$state= "Drain"} 
                2 {$state= "Unavailable"} 
                default {$state= "Non determinato"}
         }
 
        if( $isHealthy)
        {
            $isHealthy="Healthy"
            $fragments+="$hostname -- $ip -- $state -- $isHealthy"
            $fragments+="<br>"
        }
        else
        {
            $isHealthy="Not Healthy"
            $notHealthy="RED ALERT!! This is what we trained for!"
            $fragments+="$hostname -- $ip -- $state -- $isHealthy"
            $fragments+="<br>"

        }        
         #Write-Host -NoNewLine $hostname " " $ip " " $state " " $isHealthy
         #NEW LINE
         #Write-Host
    }
    #NEW LINE
    #Write-Host


    if($notHealthy){
    #write the results to HTML formated email
        
        $smtpServer = "SMTP server"
        $smtpFrom = "email address"
        $smtpTo = "email address"
        $messageSubject = "Unhealthy Web Server"

        $message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
        $message.Subject = $messageSubject
        $message.IsBodyHTML = $true
        $message.Body = $fragments

        $smtp = New-Object Net.Mail.SmtpClient($smtpServer)
        $smtp.Send($message)
    }

}

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25031642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档