使用 HAProxy 对 PHP-FPM 进行负载平衡导致服务不可用

使用 HAProxy 对 PHP-FPM 进行负载平衡导致服务不可用

我需要使用 HAProxy 对两个后端服务器进行 PHP-FPM 负载平衡(Apache 也运行在这两个后端服务器上)。

我有这个前端:

frontend fr_fpm
  bind *:9000
  mode tcp
  default_backend bk_fpm

我有这个后端:

backend bk_fpm
  mode tcp
  balance leastconn
  server app0.test.cyberfusion.cloud 10.10.0.4:9000
  server app1.test.cyberfusion.cloud 10.10.0.5:9000

我已将 PHP-FPM 设置为绑定0.0.0.0,并且可以远程登录该端口。我已将ProxyPassApache 配置设置为负载均衡器。

我看到来自 HAProxy 的请求:

Nov 18 15:27:51 public-lb0 haproxy[3598]: 10.10.0.5:37652 [18/Nov/2018:15:27:51.995] fr_fpm bk_fpm/app0.test.cyberfusion.cloud 1/0/0 0 SD 5/0/0/0/0 0/0

当请求进入时,流量出去:

root@public-lb0:/etc/haproxy# tcpdump -i any -n dst port 9000
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
15:32:04.353294 IP 10.10.0.5.37654 > 10.10.0.174.9000: Flags [S], seq 372704667, win 29200, options [mss 1460,sackOK,TS val 777738 ecr 0,nop,wscale 6], length 0
15:32:04.353394 IP 10.10.0.5.37654 > 10.10.0.174.9000: Flags [.], ack 1286887776, win 457, options [nop,nop,TS val 777739 ecr 4037378], length 0
15:32:04.353423 IP 10.10.0.5.37654 > 10.10.0.174.9000: Flags [P.], seq 0:16, ack 1, win 457, options [nop,nop,TS val 777739 ecr 4037378], length 16
15:32:04.353451 IP 10.10.0.5.37654 > 10.10.0.174.9000: Flags [P.], seq 16:1134, ack 1, win 457, options [nop,nop,TS val 777739 ecr 4037378], length 1118
15:32:04.353465 IP 10.10.0.5.37654 > 10.10.0.174.9000: Flags [P.], seq 1134:1142, ack 1, win 457, options [nop,nop,TS val 777739 ecr 4037378], length 8
15:32:04.353477 IP 10.10.0.5.37654 > 10.10.0.174.9000: Flags [P.], seq 1142:1150, ack 1, win 457, options [nop,nop,TS val 777739 ecr 4037378], length 8
15:32:04.354064 IP 10.10.0.174.46364 > 10.10.0.5.9000: Flags [S], seq 4004335738, win 29200, options [mss 1460,sackOK,TS val 4037378 ecr 0,nop,wscale 6], length 0
15:32:04.354155 IP 10.10.0.174.46364 > 10.10.0.5.9000: Flags [.], ack 1976670206, win 457, options [nop,nop,TS val 4037378 ecr 777739], length 0
15:32:04.354251 IP 10.10.0.174.46364 > 10.10.0.5.9000: Flags [P.], seq 0:1150, ack 1, win 457, options [nop,nop,TS val 4037378 ecr 777739], length 1150
15:32:04.354644 IP 10.10.0.5.37654 > 10.10.0.174.9000: Flags [F.], seq 1150, ack 2, win 457, options [nop,nop,TS val 777739 ecr 4037379], length 0

不幸的是,我收到服务不可用的消息,除非HTTP 流量和 PHP-FPM 请求都到达同一台服务器(或看起来如此)。

我的配置有什么问题吗?

答案1

该问题似乎已通过替换得到listen 0.0.0.0:9000解决listen 9000

相关内容