我的 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 没有抛出任何东西。