我正在尝试使用 HAProxy 作为故障转移 TCP 解决方案,以防我们的主服务器出现故障。但是它似乎根本不起作用。
haproxy配置文件
frontend haproxy_sync
bind *:8090
mode tcp
option tcplog
default_backend sync
backend sync
mode tcp
option tcplog
balance roundrobin
server server1 sync1:8090 check on-marked-down shutdown-sessions on-marked-up shutdown-backup-sessions
server server2 sync2:8090 check backup
HAProxy 能够看到两台服务器并连接到开放端口
root@scw-haproxy:~# nc -vz sync1 8090
sync1 [hidden] 8090 (?) open
root@scw-haproxy:~# nc -vz sync2 8090
sync2 [hidden] 8090 (?) open
当我通过关闭 sync1 haproxy 日志测试配置时显示:
May 2 13:22:54 scw-haproxy haproxy[8985]: Server sync/server1 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 81ms. 0 active and 1 backup servers left. Running on backup. 0 sessions active, 0 requeued, 0 remaining in queue.
May 2 13:22:54 scw-haproxy haproxy[8985]: Server sync/server1 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 81ms. 0 active and 1 backup servers left. Running on backup. 0 sessions active, 0 requeued, 0 remaining in queue.
但最终没有流量流经 server2/sync2 (备份服务器)
知道我在这里配置错误的地方吗?
答案1
解决。
这是我的错,我的 DNS 没有指向 haproxy,而是直接指向 server1