把EC2实例放回ELB中用于90%的时间。 不幸的是,最近的部署经常会失败,出现下一个错误:
15:51:59 TASK: [Start the app] ********************************************************* 15:51:59 changed: [app-01a] => {"changed": true, "enabled": true, "name": "app", "state": "started"} 15:51:59 15:51:59 TASK: [Wait for the app to be ready] ****************************************** 15:52:17 ok: [app-01a] => {"changed": false, "elapsed": 17, "path": null, "port": 8080, "search_regex": null, "state": "started"} 15:52:17 15:52:17 TASK: [Check health check on localhost] *************************************** 15:52:22 ok: [app-01a] => {"cache_control": "must-revalidate,no-cache,no-..."status": 200,... 15:52:22 15:52:22 TASK: [Exit if health check fails] ******************************************** 15:52:22 skipping: [app-01a] 15:52:22 15:52:22 TASK: [Register restapp instance back into load balancer] ********************* 15:52:39 failed: [app-01a -> 127.0.0.1] => (item=app-ELB) => {"failed": true, "item": "app-ELB"} 15:52:39 msg: The instance i-b1234567 could not be put in service on LoadBalancer:app-ELB. Reason: Instance has not passed the configured HealthyThreshold number of health checks consecutively. 15:52:39 15:52:39 FATAL: all hosts have already failed -- aborting
这是Ansible代码:
- name: Start the app service: name={{ app_name }} state=started enabled=yes - name: Wait for the app to be ready wait_for: port={{ app_port }} state=started timeout=120 - name: Check health check on localhost action: uri url=http://localhost:8081/healthcheck register: webpage - name: Exit if health check fails command: /bin/false when: webpage.status != 200 - name: Register restapp instance back into load balancer sudo: false local_action: module: ec2_elb instance_id: "{{ appInstanceId }}" ec2_elbs: "{{ item }}" state: 'present' region: "eu-west-1" with_items: appLoadBalancer
ELB设置:

您可能需要将ping目标从HTTP:8081 / pin(剪切)更改为HTTP:8081 / healthcheck,就像它在您的Ansible游戏中一样。
这是预期的AWS行为。 如果您修复了您的应用,ELB将重新启用您的端点的stream量。 试图强制离线主机投入使用违背了健康检查正在尝试完成的内容。
您无法在ELB控制台中执行此操作,即使删除并重新添加主机,也需要等待健康状况检查通过才能通过stream量。
如果您希望主机更快恢复服务,请更改您的健康检查容差。