与 AWS 网络 ELB 的连接要么立即连接,要么需要很长时间才能连接

Connection to AWS Network ELB is either connecting right away or taking a long time to connect

我遇到一个问题,即与 AWS 网络 ELB 的连接要么立即连接,要么需要很长时间才能连接。我从 Internet 主机通过 telnet 检查,输出如下:

➜  ~ telnet host.elb.ap-northeast-1.amazonaws.com 8090
Trying 54.238.219.184...
telnet: connect to address 54.238.219.184: Operation timed out
Trying 35.74.146.43...
telnet: connect to address 35.74.146.43: Operation timed out
Trying 35.73.158.173...
Connected to host.elb.ap-northeast-1.amazonaws.com.
Escape character is '^]'.
^CConnection closed by foreign host.

看来问题是因为我在可用区设置了三个子网,而我的Target EC2只在一个可用区。网络 ELB 似乎在为网络 ELB 生成的三个 IP 地址之间执行某种循环机制,三个子网中的两个无法到达目标。

解决方案是创建一个网络 ELB,其中只有一个 subnet/availability 区域匹配目标 EC2 的子网。