AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1121248
Accepted
uozzyy
uozzyy
Asked: 2023-01-27 20:06:09 +0800 CST2023-01-27 20:06:09 +0800 CST 2023-01-27 20:06:09 +0800 CST

HAProxy 和 postgres

  • 772

我的 haproxy 配置如下,后端有 pg_autoctl 集群,另一个 VM (bunty4) 托管监视器并安装了 haproxy。

global
    maxconn 100

defaults
    log global
    mode tcp
    retries 2
    timeout client 30m
    timeout connect 4s
    timeout server 30m
    timeout check 5s

listen stats
    mode tcp
    bind *:7000
    stats enable
    stats uri /

listen ReadWrite
    bind *:5000
    option httpchk
    http-check expect status 200
    default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
    server bunty1 bunty1:6001 maxconn 100 check port 23267
    server bunty2 bunty2:6002 maxconn 100 check port 23267
    server bunty3 bunty3:6003 maxconn 100 check port 23267

listen ReadOnly
    bind *:5001
    option httpchk
    http-check expect status 206
    default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
    server bunty1 bunty1:6001 maxconn 100 check port 23267
    server bunty2 bunty2:6002 maxconn 100 check port 23267
    server bunty3 bunty3:6003 maxconn 100 check port 23267

这运行良好:

postgres@bunty4:~$ psql -h bunty2 -p 6002
psql (14.6 (Ubuntu 14.6-1.pgdg22.04+1))
Type "help" for help.

postgres=# \q
postgres@bunty4:~$ psql -h bunty1 -p 6001
psql (14.6 (Ubuntu 14.6-1.pgdg22.04+1))
Type "help" for help.

当我尝试连接前端端口 7000(通过 pgadmin 或 cli)时,出现错误:

postgres@bunty4:~$ psql -h localhost -p 7000
psql: error: connection to server at "localhost" (127.0.0.1), port 7000 failed: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.

psql -h 192.168.5.129 -p 7000   ## this also fails with same error.

不知道为什么,haproxy.log 没有抛出任何东西。

haproxy
  • 1 1 个回答
  • 59 Views

1 个回答

  • Voted
  1. Best Answer
    Nikita Kipriyanov
    2023-01-28T00:31:08+08:002023-01-28T00:31:08+08:00

    在这个 haproxy 端口 7000 侦听器的配置中,平衡器上没有后端,而是有stats enable. 这意味着它保留用于显示haproxy 统计信息。但是,它被错误地配置为 tcp 模式;统计页面需要 http。所以将它设置为mode http并尝试使用网络浏览器连接到 bunty4:7000。它将显示一个漂亮的统计网页。

    似乎 psql 或其他 PostgreSQL 客户端应该连接到 haproxy (bunty4) 端口 5000 进行写入和读取,或者连接到端口 5001 进行读取。然而,这些端口背后的确切逻辑隐藏在端口 23267 上的服务中,它以某种方式决定其实例是只读还是读写,并报告相应的状态 206 或 200;从您所展示的内容来看,这些端口的作用并不明显。他们的名字是唯一的提示。

    我也不明白为什么不同的服务器在不同的端口上托管服务。这使得后端配置不那么对称,因此很糟糕,因为理想情况下它们应该是彼此的精确克隆。对我来说,如果 PostgreSQL 是机器上的唯一服务,那么在默认端口 5432 上托管 PostgreSQL 是很自然的,这似乎对所有三个后端服务器都是如此。

    • 0

相关问题

  • 是否可以使用负载均衡器加密内部网络服务器之间的流量[关闭]

  • HAProxy 和后端服务器之间丢失一半的数据

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve