故意使附加到 ELB 的实例不健康

Purposefully make instance attached to ELB as unhealthy

是否有任何方法可以使用 boto 故意使附加到 ELB 的实例不健康?

我尝试了几种方法,但到目前为止没有一个有效。

感谢您的帮助!!

不,这是不可能的。没有可以更改实例健康状态的 AWS API 调用。 (Auto Scaling 具有此功能,但负载平衡没有)。

您可以使用 deregister_instances() API 调用,这将有效地实现相同的结果。

Register or Deregister EC2 Instances for Your Classic Load Balancer 文档说:

Deregistering an EC2 instance removes it from your load balancer. The load balancer stops routing requests to an instance as soon as it is deregistered. If demand decreases, or you need to service your instances, you can deregister instances from the load balancer. An instance that is deregistered remains running, but no longer receives traffic from the load balancer, and you can register it with the load balancer again when you are ready.

When you deregister an instance, Elastic Load Balancing waits until in-flight requests have completed if connection draining is enabled.

是的,我们可以在下面的场景中做到这一点。 假设您有 loadblancer(myloadbalancer),一个附加的实例和 PingPath 配置如下。

Ping Protocol: HTTP
Ping Port: 80
Ping Path: /

只需添加 boto3 代码来编辑健康检查配置,如下所示,您就可以看到魔法(Instance OutOfService)。

client.configure_health_check(
LoadBalancerName='myloadbalancer',
HealthCheck={
    'Target': 'HTTP:80/hjkx',
    'Interval': 30,
    'Timeout': 5,
    'UnhealthyThreshold': 5,
    'HealthyThreshold': 3
}

)

另外两个选项: 1. 暂时禁用响应健康检查的 Web 服务器/进程。在我们的例子中,我们是 运行 Java webapps,前面有 nginx 代理。关闭 nginx 代理使健康检查失败,而 Java 应用程序仍为 运行。 2. 对ELB进行健康检查的端口进行临时防火墙。您可以通过调用 AWS api.

来完成此操作