簡單的haproxy TCP透傳導致網路傳輸速度非常慢

簡單的haproxy TCP透傳導致網路傳輸速度非常慢

我在全新安裝的 Debian 10 Buster 上設定了一個簡單的 haproxy 實例。我添加了一些簡單的必要配置來啟用對相關 IP 位址的直通(已在下面的配置中進行了編輯)。

設定檔:

global
    log /dev/log    local0
    log /dev/log    local1 notice

    chroot /var/lib/haproxy
    stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
    stats timeout 30s
    user haproxy
    group haproxy
    daemon

    # Default SSL material locations
    ca-base /etc/ssl/certs
    crt-base /etc/ssl/private

    # Default ciphers to use on SSL-enabled listening sockets.
    # For more information, see ciphers(1SSL). This list is from:
    #  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
    # An alternative list with additional directives can be obtained from
    #  https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy
    ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
    ssl-default-bind-options no-sslv3

defaults
    log global
    mode    http
    option  httplog
    option  dontlognull
        timeout connect 5000
        timeout client  50000
        timeout server  50000
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 403 /etc/haproxy/errors/403.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502.http
    errorfile 503 /etc/haproxy/errors/503.http
    errorfile 504 /etc/haproxy/errors/504.http


frontend myfrontend
  bind *:80
  mode tcp
  default_backend mybackendhttp

frontend myfrontendhttps
  bind *:443
  mode tcp
  use_backend mybackendhttps

backend mybackendhttp
  mode tcp
  option ssl-hello-chk
  server server1 ***********:80

backend mybackendhttps
  mode tcp
  option ssl-hello-chk
  server server1 ************:443

我所做的更改(如果我與原始文件進行比較)(編輯後的 ip):

+
+
+frontend myfrontend
+  bind *:80
+  mode tcp
+  default_backend mybackendhttp
+
+frontend myfrontendhttps
+  bind *:443
+  mode tcp
+  use_backend mybackendhttps
+
+backend mybackendhttp
+  mode tcp
+  option ssl-hello-chk
+  server server1 ***********:80
+
+backend mybackendhttps
+  mode tcp
+  option ssl-hello-chk
+  server server1 **********:443

一切正常,但由於某種原因,當從我的電腦發出瀏覽器請求、透過命令列或行動裝置發出curl請求時,網路效能非常慢,我的速度約為200-300kb/s,而通常情況下我的速度約為10 倍那。

如果我在 VPS 上透過curl 嘗試相同的請求,我會得到更高的速度(5000kb/s)。

haproxy 在 GCP 計算實例虛擬機器上運行,因此我懷疑這會是網路頻寬問題,但我可以嘗試設定一個簡單的靜態 http 服務,看看比較如何。

問題的原因可能是什麼?我該如何診斷這個問題?在 haproxy 上啟用日誌是否可以更好地洞察此問題?

我遇到了以下問題,它似乎也描述了類似的行為:

HAProxy SSL 反應非常慢

OpenSSL 庫需要在 /etc/hosts 中正確設定主機名

但是我不清楚「正確設定」是什麼意思。

答案1

回答是因為我沒有足夠的代表。

在 中/etc/hosts,您想要找到這一行:

127.0.0.1 localhost

替換localhost為您的 FQDN,例如 haproxy.domain.com 或其他任何名稱。它應該與您的伺服器的主機名稱相同。

在 Debian 上,您可以使用以下命令設定主機名稱:

hostname-ctl set-hostname haproxy.domain.com

相關內容