Проверка HAProxy не проверяет содержимое в IIS

Я новичок в HAproxy, и я прочитал в Google все возможные фразы, которые мог придумать, но я не могу заставить haproxy прочитать содержимое, возвращаемое моей тестовой страницей.

Вот настройка: Конфигурация одной руки - 1x CentOS 7 haproxy 1.5.14 - 2x Windows Server 2012r2 IIS 8.5

Конфигурация внутреннего сервера:

backend mt-http
balance     roundrobin
mode http
option httpchk /check.aspx?appserver=dev-cluster.xxxx.com&databaseserver=test.xxxx.com&database=######dev
http-check expect string 200\ OK
server  WebLB-test2 xx.xx.xx.xx:80 check
server  WebLB-test1 xx.xx.xx.xx:80 check

check.aspx подключается к определенной базе данных через именованный кластер серверов приложений, чтобы подтвердить сквозное соединение от веб-сервера через базу данных. Если проверка прошла успешно, проверка вернет 200 OK на веб-странице в виде текста. Если один из компонентов недоступен, check.aspx возвращает ошибку 500. Успех:

 <!DOCTYPE html>
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head><title>
        Mediatools Check
 </title></head>
 <body id="bodyID">200 OK</body>
 </html>

Ошибка:

 <html xmlns="http://www.w3.org/1999/xhtml">
 <head><title>
     Mediatools Check
 </title></head>
 <body id="bodyID">500 Internal Server Error</body>
 </html>

Когда я использую опцию «http-check expect string 200 \ OK» (я пробовал с escape-символом «\» в строке и без него), серверы показывают ошибку это «Недопустимый ответ уровня 7: проверка содержимого http обнаружила пустое тело ответа».

Когда я использую опцию «http-check, ожидайте статус 200 OK», страница возврата будет успешной независимо от того, равен ли текст состояния 200 или нет (потому что я Предположим, check.aspx возвращается успешно, даже если возвращается код 500).

Любая помощь будет принята с благодарностью.

Вот результат команды curl -v: Похоже, мой запрос слишком длинный?

 curl -v xx.xx.xx.xx/yourDB/check.aspx?appserver=dev-cluster.yourdomain.com&databaserver=test.yourdomain.com&database=yourDBdev
 [1] 16077
 [2] 16078
 [root@dev-cluster log]# * About to connect() to xx.xx.xx.xx port 80 (#0)
 *   Trying xx.xx.xx.xx...
 * Connected to xx.xx.xx.xx (xx.xx.xx.xx) port 80 (#0)
 > GET /customer/check.aspx?appserver=dev-cluster.yourdomain.com HTTP/1.1
 > User-Agent: curl/7.29.0
 > Host: xx.xx.xx.xx
 > Accept: */*
 > 
 < HTTP/1.1 500 Internal Server Error
 < Cache-Control: private
 < Content-Type: text/html; charset=utf-8
 < Server: Microsoft-IIS/8.5
 < X-AspNet-Version: 4.0.30319
 < X-UA-Compatible: IE=EmulateIE7
 < Date: Wed, 17 Feb 2016 22:16:59 GMT
 < Content-Length: 3428
 < 
 <!DOCTYPE html>
 <html>
  <head>
    <title>Runtime Error</title>
    <meta name="viewport" content="width=device-width" />
    <style>
     body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
     p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
     b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
     H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
     H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
     pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}
     .marker {font-weight: bold; color: black;text-decoration: none;}
     .version {color: gray;}
     .error {margin-bottom: 10px;}
     .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
     @media screen and (max-width: 639px) {
      pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }
     }
     @media screen and (max-width: 479px) {
      pre { width: 280px; }
     }
    </style>
</head>

<body bgcolor="white">

        <span><H1>Server Error in '/customer' Application.<hr width=100% size=1 color=silver></H1>

        <h2> <i>Runtime Error</i> </h2></span>

        <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

        <b> Description: </b>An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
        <br><br>

        <b>Details:</b> To enable the details of this specific error message to be viewable on remote machines, please create a &lt;customErrors&gt; tag within a &quot;web.config&quot; configuration file located in the root directory of the current web application. This &lt;customErrors&gt; tag should then have its &quot;mode&quot; attribute set to &quot;Off&quot;.<br><br>

        <table width=100% bgcolor="#ffffcc">
           <tr>
              <td>
                  <code><pre>

 &lt;!-- Web.Config Configuration File --&gt;

  &lt;configuration&gt;
  &lt;system.web&gt;
    &lt;customErrors mode=&quot;Off&quot;/&gt;
&lt;/system.web&gt;
 &lt;/configuration&gt;</pre></code>

              </td>
           </tr>
        </table>

        <br>

        <b>Notes:</b> The current error page you are seeing can be replaced by a custom error page by modifying the &quot;defaultRedirect&quot; attribute of the application&#39;s &lt;customErrors&gt; configuration tag to point to a custom error page URL.<br><br>

        <table width=100% bgcolor="#ffffcc">
           <tr>
              <td>
                  <code><pre>

 &lt;!-- Web.Config Configuration File --&gt;

 &lt;configuration&gt;
 &lt;system.web&gt;
    &lt;customErrors mode=&quot;RemoteOnly&quot; defaultRedirect=&quot;mycustompage.htm&quot;/&gt;
&lt;/system.web&gt;
 &lt;/configuration&gt;</pre></code>

              </td>
           </tr>
        </table>

        <br>

</body>
 </html>
  * Connection #0 to host xx.xx.xx.xx left intact

 [1]-  Done                    curl -v xx.xx.xx.xx/customer/check.aspx?appserver=dev-cluster.yourdomain.com
 [2]+  Done                    databaserver=test.yourdomain.com

Хорошо, еще раз! Я попросил веб-разработчика вытащить сервер приложений, сервер базы данных и параметр базы данных из web.config вместо того, чтобы отправлять их в check.aspx

Новая конфигурация выглядит так:

 backend mt-http
 balance     roundrobin
 mode http
 option httpchk GET /customer/check.aspx
 http-check expect status 200 OK
 server  WebLB-test2 xx.xx.xx.xx:80 check
 server  WebLB-test1 xx.xx.xx.xx:80 check

New Return from Curl:

 curl -v xx.xx.xx.xx/pgglobal/check.aspx
 * About to connect() to xx.xx.xx.xx port 80 (#0)
 *   Trying xx.xx.xx.xx...
 * Connected to xx.xx.xx.xx (xx.xx.xx.xx) port 80 (#0)
 > GET /customer/check.aspx HTTP/1.1
 > User-Agent: curl/7.29.0
 > Host: xx.xx.xx.xx
 > Accept: */*
 > 
 < HTTP/1.1 200 OK
 < Cache-Control: private
 < Content-Type: text/html; charset=utf-8
 < Server: Microsoft-IIS/8.5
 < Set-Cookie: ASP.NET_SessionId=whvmaboyg03lsl3rd1gcsbxl; path=/; secure; HttpOnly
 < X-AspNet-Version: 4.0.30319
 < X-UA-Compatible: IE=EmulateIE7
 < Date: Wed, 17 Feb 2016 23:00:07 GMT
 < Content-Length: 162
 < 


 <!DOCTYPE html>

 <html xmlns="http://www.w3.org/1999/xhtml">
 <head><title>
Happiness Check
 </title></head>
 <body id="bodyID">Success</body>
 </html>
 * Connection #0 to host xx.xx.xx.xx left intact

haproxy по-прежнему сообщает «Неверный статус уровня 7: проверка статуса HTTP вернула <500>»

Вот вывод curl для неудачного check.aspx (один из проверенных компонентов отключен, чтобы вызвать страницу с ошибкой).

 curl -v xx.xx.xx.xx/Customer/check.aspx
 * About to connect() to xx.xx.xx.xx port 80 (#0)
 *   Trying xx.xx.xx.xx...
 * Connected to xx.xx.xx.xx (xx.xx.xx.xx) port 80 (#0)
 > GET /Customer/check.aspx HTTP/1.1
 > User-Agent: curl/7.29.0
 > Host: xx.xx.xx.xx
 > Accept: */*
 > 
 < HTTP/1.1 500 Internal Server Error
 < Cache-Control: private
 < Content-Type: text/html; charset=utf-8
 < Server: Microsoft-IIS/8.5
 < X-AspNet-Version: 4.0.30319
 < X-UA-Compatible: IE=EmulateIE7
 < Date: Thu, 18 Feb 2016 17:17:01 GMT
 < Content-Length: 3428
 < 
 <!DOCTYPE html>
 <html>
  <head>
    <title>Runtime Error</title>
    <meta name="viewport" content="width=device-width" />
    <style>
     body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
     p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
     b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
     H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
     H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
     pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}
     .marker {font-weight: bold; color: black;text-decoration: none;}
     .version {color: gray;}
     .error {margin-bottom: 10px;}
     .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
     @media screen and (max-width: 639px) {
      pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }
     }
     @media screen and (max-width: 479px) {
      pre { width: 280px; }
     }
    </style>
 </head>

 <body bgcolor="white">

        <span><H1>Server Error in '/Customer' Application.<hr width=100% size=1 color=silver></H1>

        <h2> <i>Runtime Error</i> </h2></span>

        <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

        <b> Description: </b>An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
        <br><br>

        <b>Details:</b> To enable the details of this specific error message to be viewable on remote machines, please create a &lt;customErrors&gt; tag within a &quot;web.config&quot; configuration file located in the root directory of the current web application. This &lt;customErrors&gt; tag should then have its &quot;mode&quot; attribute set to &quot;Off&quot;.<br><br>

        <table width=100% bgcolor="#ffffcc">
           <tr>
              <td>
                  <code><pre>

 &lt;!-- Web.Config Configuration File --&gt;

 &lt;configuration&gt;
  &lt;system.web&gt;
    &lt;customErrors mode=&quot;Off&quot;/&gt;
  &lt;/system.web&gt;
 &lt;/configuration&gt;</pre></code>

              </td>
           </tr>
        </table>

        <br>

        <b>Notes:</b> The current error page you are seeing can be replaced by a custom error page by modifying the &quot;defaultRedirect&quot; attribute of the application&#39;s &lt;customErrors&gt; configuration tag to point to a custom error page URL.<br><br>

        <table width=100% bgcolor="#ffffcc">
           <tr>
              <td>
                  <code><pre>

 &lt;!-- Web.Config Configuration File --&gt;

 &lt;configuration&gt;
  &lt;system.web&gt;
    &lt;customErrors mode=&quot;RemoteOnly&quot; defaultRedirect=&quot;mycustompage.htm&quot;/&gt;
  &lt;/system.web&gt;
 &lt;/configuration&gt;</pre></code>

              </td>
           </tr>
        </table>

        <br>

  </body>
 </html>
 * Connection #0 to host xx.xx.xx.xx left intact
1
задан 18 February 2016 в 19:33
1 ответ

Ваша конфигурация идеальна, за исключением одной мелочи. Вы не указали, что проверка работоспособности должна на самом деле получать запрашиваемую страницу, и в результате содержимое будет пустым.

Согласно HAProxy docs , option httpchk по умолчанию использует метод OPTIONS , который не получает тело страницы.

option httpchk
option httpchk <метод>
option httpchk

Включить протокол HTTP для проверки работоспособности серверов


- это дополнительный HTTP-метод, используемый с запросами. Если не задан, используется метод «OPTIONS», поскольку он обычно требует низкой обработки на сервере и его легко отфильтровать из журналов. Можно использовать любой метод, но не рекомендуется изобретать нестандартные.


- это URI, на который ссылаются HTTP-запросы. По умолчанию используется «/», который доступен по умолчанию практически на любом сервере, но может быть изменен на любой другой URI. Разрешены строки запроса.

<версия>
- необязательная строка версии HTTP. По умолчанию используется «HTTP / 1.0», но некоторые серверы могут работать некорректно в HTTP 1.0, поэтому переключение на HTTP / 1.1 иногда может помочь. Обратите внимание, что поле Host является обязательным в HTTP / 1.1, и в качестве уловки его можно передать после "\ r \ n" после строки версии.

У вас есть несколько вариантов решения этой проблемы.

  1. Вы можете изменить свой метод на GET :

     backend mt-http
      баланс раундробин
      режим http
      вариант httpchk GET /check.aspx?appserver=dev-cluster.xxxx.com&databaseserver=test.xxxx.com&database=######dev
      http-check ожидает строку 200 \ OK
      сервер WebLB-test2 xx.xx.xx.xx: 80 проверок
      сервер WebLB-test1 xx.xx.xx.xx: проверка 80
     

    Я пробовал это на своем тестовом балансировщике нагрузки, и он работает должным образом.

  2. Вы можете изменить check.aspx , чтобы выдать что-то другое, кроме 200 OK HTTP статус при неудачной проверке.
    Однажды у меня была потребность проверить, работает ли конкретная служба, потому что IIS всегда возвращал 200 OK , даже если фактическое приложение не работало на сервере. Для этого я написал простой сценарий C #:

     <% @ Page Language = "C #"%>
     <% @ Import Namespace = "System"%>
     <% @ Import Namespace = "System.ServiceProcess"%>
     <% @ Import Namespace = "System.Net"%>
     <%
    
    ServiceController sc = новый ServiceController (Request.QueryString ["служба"]);
    
    переключатель (sc.Status)
     {
      case ServiceControllerStatus.Running:
      Response.StatusCode = (целое) HttpStatusCode.OK;
      Response.ContentType = "текст / простой";
      Response.Write ("Выполняется");
      сломать;
    
      по умолчанию:
      Response.StatusCode = (int) HttpStatusCode.ServiceUnavailable;
      Response.ContentType = "текст / простой";
      Response.Write («Ошибка»);
      сломать;
     }
     %>
     

    Вы бы использовали его так:

     backend FooBar
      баланс раундробин
      режим http
      вариант httpchk GET /ServiceCheck/check.aspx?service=ServiceName
      http-check ожидать статус 200
      сервер WebLB-test2 xx.xx.xx.xx: 80 проверок
      сервер WebLB-test1 xx.xx.xx.xx: проверка 80
     
2
ответ дан 3 December 2019 в 20:41

Теги

Похожие вопросы