Назад | Перейти на главную страницу

HAProxy не регистрирует все запросы

Я установил HAProxy на Ubuntu 14.04 с отдельным внутренним сервером также на Ubuntu 14.04 и Apache2.

При выполнении запросов не все эти запросы регистрируются. Даже при запуске HAProxy в режиме отладки он не отображает все запросы на терминале.

У меня есть index.html, который включает изображение. При запросе страницы с помощью Google Chrome я вижу в инспекторе, что всего запрашиваются 3 файла (index.html, header.gif и favicon.ico).

Однако HAProxy будет регистрировать только фактический запрос для index.html, и если я очень быстро перезагружу страницу, он даже не будет регистрировать все запросы для index.html.

Я пытался отлаживать с помощью socat, но ошибок не было. Я пытался установить формат журнала tcplog, но это тоже не помогло, не все запросы регистрировались.

Что я делаю не так?

Конфигурация rsyslogd:

$ModLoad imudp
$UDPServerAddress 127.0.0.1
$UDPServerRun 514

local0.* -/var/log/haproxy/haproxy.log

& ~

Конфигурация HAProxy:

global
  log 127.0.0.1 local0
  log-send-hostname
  daemon
  maxconn 256
  stats socket    /tmp/haproxy

defaults
  log global
  timeout connect 5000ms
  timeout client 50000ms
  timeout server 50000ms

frontend http-in
  mode http
  option httplog
  # bind to all ip's port 9200
  bind 0.0.0.0:80
  default_backend http-out

backend http-out
  mode http
  balance leastconn
  server web2 xxx.xxx.xxx.xxx:80

журнал haproxy

  Sep 17 14:38:16 front2.xxx.net haproxy[5436]: xxx.xxx.xxx.xxx:61745 [17/Sep/2015:14:38:06.771] http-in http-in/ -1/-1/-1/-1/10000 400 187 - - CR-- 2/2/0/0/0 0/0 ""
  Sep 17 14:38:16 front2.xxx.net haproxy[5436]: xxx.xxx.xxx.xxx:61744 [17/Sep/2015:14:38:06.771] http-in http-out/web2 0/0/1/2/10001 200 23198 - - ---- 1/1/0/0/0 0/0 "GET /index.html HTTP/1.1"
  Sep 17 14:38:26 front2.xxx.net haproxy[5436]: xxx.xxx.xxx.xxx:61746 [17/Sep/2015:14:38:06.772] http-in http-in/ -1/-1/-1/-1/20000 400 187 - - CR-- 0/0/0/0/0 0/0 ""

журнал apache2

  registered.xxx.net:80 185.92.61.11 - - [17/Sep/2015:14:38:06 +0200] "GET /index.html HTTP/1.1" 200 1192 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36"
  registered.xxx.net:80 185.92.61.11 - - [17/Sep/2015:14:38:06 +0200] "GET /header.gif HTTP/1.1" 200 4145 "http://xxx.xxx.xxx.xxx/index.html" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36"
  registered.xxx.net:80 185.92.61.11 - - [17/Sep/2015:14:38:06 +0200] "GET /favicon.ico HTTP/1.1" 200 17861 "http://xxx.xxx.xxx.xxx/index.html" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36"

Со всеми версиями HAProxy до 1.5-dev22 при использовании в mode http, это сработало в tunnel «подрежим», если не указан другой «подрежим». Я понимаю, что на самом деле в HAProxy нет такой вещи, как «подрежим», но я не уверен, как еще это назвать. В документы просто используйте слово «режим», но я нахожу это еще более запутанным ...

В любом случае, в tunnel "подрежим" обрабатываются только первый запрос и ответ, а все остальное пересылается без анализа. Этот режим не следует использовать, поскольку он создает множество проблем с ведением журнала и обработкой HTTP.

Начиная с версии 1.5-dev22, "подрежим" по умолчанию был изменен с tunnel к keep alive, означающий, что все запросы и ответы обрабатываются, а соединения остаются открытыми, но неактивными между ответами и новыми запросами.

Это можно изменить, используя option http-keep-alive, option http-tunnel, option httpclose, option http-server-close и option forceclose ключевые слова во внешних и внутренних интерфейсах, при этом эффективный режим (или «подрежим», если хотите) описан в документации. В разделе 4 есть таблица, которая показывает эффективный «подрежим» на основе того, какие параметры установлены во внешнем интерфейсе и используются для конкретного соединения.

Для полноты, вот соответствующий раздел документации, включая таблицу и ее различные "подрежимы", как они существуют на момент написания этой статьи (1.5.14):

In HTTP mode, the processing applied to requests and responses flowing over
a connection depends in the combination of the frontend's HTTP options and
the backend's. HAProxy supports 5 connection modes :

  - KAL : keep alive ("option http-keep-alive") which is the default mode : all
    requests and responses are processed, and connections remain open but idle
    between responses and new requests.

  - TUN: tunnel ("option http-tunnel") : this was the default mode for versions
    1.0 to 1.5-dev21 : only the first request and response are processed, and
    everything else is forwarded with no analysis at all. This mode should not
    be used as it creates lots of trouble with logging and HTTP processing.

  - PCL: passive close ("option httpclose") : exactly the same as tunnel mode,
    but with "Connection: close" appended in both directions to try to make
    both ends close after the first request/response exchange.

  - SCL: server close ("option http-server-close") : the server-facing
    connection is closed after the end of the response is received, but the
    client-facing connection remains open.

  - FCL: forced close ("option forceclose") : the connection is actively closed
    after the end of the response.

The effective mode that will be applied to a connection passing through a
frontend and a backend can be determined by both proxy modes according to the
following matrix, but in short, the modes are symmetric, keep-alive is the
weakest option and force close is the strongest.

                          Backend mode

                | KAL | TUN | PCL | SCL | FCL
            ----+-----+-----+-----+-----+----
            KAL | KAL | TUN | PCL | SCL | FCL
            ----+-----+-----+-----+-----+----
            TUN | TUN | TUN | PCL | SCL | FCL
 Frontend   ----+-----+-----+-----+-----+----
   mode     PCL | PCL | PCL | PCL | FCL | FCL
            ----+-----+-----+-----+-----+----
            SCL | SCL | SCL | FCL | SCL | FCL
            ----+-----+-----+-----+-----+----
            FCL | FCL | FCL | FCL | FCL | FCL