【问题标题】:Health checks failed with these codes: [502]健康检查失败,代码如下:[502]
【发布时间】:2020-04-25 23:50:59
【问题描述】:

我想提一下,我不是一个经验丰富的技术人员,但我一直在尝试通过在线课程学习 AWS,但我遇到了一个特定的问题:

我创建了两个目标组,每个目标组由两个 EC2 linux 实例组成,以及一些简单的代码作为每个实例的用户数据的一部分。

#/bin/bash
yum update -y
yum install httpd -y
systemctl start httpd
systemctl enable httpd
cd /var/www/html
echo "This is an INSTANCE" > index.html

然后,我创建了一个带有 HTTP 侦听器(端口 80)的应用程序负载平衡器。 ALB 已与使用绝对具有公共访问权限的安全组的子网相关联(我在其他具有公共访问权限的练习中使用了相同的安全组)

但每次,两个目标群体都会显示“
健康检查失败,代码如下:[502]"。我已经尝试了所有我能想到的方法,我什至尝试进行一些研究,但无法弄清楚。

在任何人被激怒之前,我之前没有使用过堆栈溢出,所以如果这是一个重复的线程,我很抱歉,但在我看到的其他线程中,还有其他更复杂的情况。

有人有什么想法吗?

【问题讨论】:

  • 实例的 SG 怎么样?它们是否允许从 ALB 的安全组入站?

标签: amazon-web-services amazon-ec2 aws-application-load-balancer


【解决方案1】:

HTTP 502 错误的标题是Bad gateway

我遇到了同样的错误,这是因为运行状况检查是通过不同的协议 (HTTP) 和目标组协议 (HTTPS) 配置的。

提到了其他可能的原因here

HTTP 502: Bad gateway

Possible causes:

 - The load balancer received a TCP RST from the target when attempting to establish a connection.

 - The load balancer received an unexpected response from the target, such as "ICMP Destination unreachable (Host unreachable)", when attempting to establish a connection. Check whether traffic is allowed from the load balancer subnets to the targets on the target port.

 - The target closed the connection with a TCP RST or a TCP FIN while the load balancer had an outstanding request to the target. Check whether the keep-alive duration of the target is shorter than the idle timeout value of the load balancer.

 - The target response is malformed or contains HTTP headers that are not valid.

 - The load balancer encountered an SSL handshake error or SSL handshake timeout (10 seconds) when connecting to a target.

 - The deregistration delay period elapsed for a request being handled by a target that was deregistered. Increase the delay period so that lengthy operations can complete.

 - The target is a Lambda function and the response body exceeds 1 MB.

 - The target is a Lambda function that did not respond before its configured timeout was reached.

(*) 附加资源 - How do I troubleshoot and fix failing health checks for Application Load Balancers?

【讨论】:

  • 是的!谢谢;我不敢相信我错过了这个。我的协议是 HTTP,但我的目标组协议是 HTTPS。将我的协议更新为 HTTP 解决了这个问题。谢谢!
【解决方案2】:

您的脚本从未运行,因为用户数据需要以 #! 开头,但您的脚本仅以 # 开头。

如果没有#!,则不会作为脚本执行。

在调试负载均衡器的情况时,一个好的过程是:

  • 尝试直接访问实例,以确认它们作为 Web 服务器响应。如果没有,请登录实例并检查 /var/log/cloud-init-output.log 以查看用户数据是否产生任何错误。
  • 检查安全组以确认它们配置正确,通常是:
    • 负载均衡器 (ELB-SG) 上的安全组允许来自 Internet 的入站 Web 流量
    • Amazon EC2 实例 (App-SG) 上的安全组,允许来自 ELB-SG 的入站 Web 流量。也就是说,App-SG 专门引用了ELB-SG

另外,请注意systemctlAmazon Linux 2 上正常工作,但在“Amazon Linux” (v1) 上不能正常工作。

【讨论】:

  • 非常感谢你,约翰!有效!很难相信一个“!”做出了这样的改变。也感谢您的提示。就像我说的,我不是程序员,我感谢您的友好和耐心的回应。
猜你喜欢
  • 2020-06-29
  • 2019-05-05
  • 1970-01-01
  • 1970-01-01
  • 2020-12-18
  • 2015-01-23
  • 2017-06-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多