AWS 负载均衡器 502 [英] AWS Load Balancer 502

本文介绍了AWS 负载均衡器 502的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 EC2 实例上运行微服务(使用不同的编程语言).在生产中,当这些服务尝试相互交互时,我注意到一些 502 Bad Gateway Errors.同样在请求的服务的日志中,它没有显示任何 api 调用被点击

I have microservices(in different programming languages) running on an EC2 instance. On production I notice a few 502 Bad Gateway Errors when these services try to interact with each other. Also in the logs of the requested service it doesn't show any api call is being hit

示例服务 A 调用服务 B,但在服务 B 日志中没有任何内容表明调用来自服务 A.

example service A calls service B, but in service B logs there is nothing to indicate that a call came from service A.

这可能是 AWS 负载均衡器的问题吗?任何帮助,将不胜感激.提前致谢.

Can it be AWS load balancer issue? Any help would be appreciated. Thanks in advance.

尝试的解决方案:我们尝试在每个服务中创建 http/https 连接代理,但仍然出现此问题.

Solution tried: We tried making http/https connection agents in each service but still we get this issue.

更新:在 lb 日志中,api 被记录,但目标响应代码显示-",而 lb 响应代码显示 502 或 504.这是否意味着 lb 无法处理流量或我的应用程序?

Update: In lb logs, the api is logged, but the target response code shows "-" whereas lb response code shows 502 or 504. Does it mean that lb is not able to handle the traffic or my application?

还有什么可能的解决方案?

Also what can be the possible solution?

推荐答案

我们遇到了同样的问题.

We had the same problem.

在我们的设置中,AWS 应用程序 ELB 的目标组包含 4 个 EC2 实例.在每个 EC2 实例上,都有一个转发到 Tomcat 的 Apache2.

In our setup, an AWS Application ELB has a target group of 4 EC2 instances. On each of the EC2 instances, there is an Apache2 which forwards to a Tomcat.

ELB 的默认连接 KeepAlive 为 60 秒.Apache2 的默认连接 KeepAlive 为 5 秒.如果 5 秒结束,Apache2 将关闭其连接并重置与 ELB 的连接.然而,如果一个请求恰好在正确的时间到来,ELB 将接受它,决定将它转发到哪个主机,在那一刻,Apache 关闭连接.这将导致上述 502 错误代码.

The ELB has a default connection KeepAlive of 60 seconds. Apache2 has a default connection KeepAlive of 5 seconds. If the 5 seconds are over, the Apache2 closes its connection and resets the connection with the ELB. However, if a request comes in at precisely the right time, the ELB will accept it, decide which host to forward it to, and in that moment, the Apache closes the connection. This will result in said 502 error code.

解决方案是:当您有级联代理/LB 时,要么对齐它们的 KeepAlive 超时,或者 - 最好 - 甚至让它们越长越长.

The solution is: When you have cascading proxies/LBs, either align their KeepAlive timeouts, or - preferrably - even make them a little longer the further down the line you get.

我们将 ELB 超时设置为 60 秒,将 Apache2 超时设置为 120 秒.问题解决了.

We set the ELB timeout to 60 seconds and the Apache2 timeout to 120 seconds. Problem gone.

这篇关于AWS 负载均衡器 502的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆