问题原文
原帖链接 · Luis Lobo Borobia · CC BY-SA 3.0
I want to setup autoscaling in AWS. I don't want to use Elastic Load Balancer.
Autoscalling in Amazon creates EC2 instances seamlessly during demand spikes to maintain performance, and decreases automatically during demand lulls to minimize costs.
Since this EC2 instances are created automatically, their host names are unknown to NGINX.
I know and already have upstream setup in nginx to 10 EC2 instances.
I want to be able to add/update/delete automatically server names to my upstream nginx configuration, when autoscaling adds/updates/deletes EC2 instances.
已采纳解答
原帖链接 · Upendra · CC BY-SA 3.0
This can be achieved by using Amazon SDK ( I am almost done with it, will put it on github ), utilizing the SNS, EC2 and Autoscaling service.
I have followed the below steps to achieve this:
- Enable HTTP notification and subscribed my webserver.
- Added a lifecycle-hook with heartbeat of 1 min (to wait for 1 min before terminating) to my autoscaling group for terminating server
- Created an index file to parse the message to detect what kind of message it is ( i.e Launch or Terminate)
- Once type of event is decided i queried EC2 to get the private ip of the instance
- In case of Launch wait till header 200 is recieved and then add the ip to nginx config and reload
- In case of Terminate remove the IP from config and reload nginx
Please find the script here https://github.com/singhupendra/aws-autoscale
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
