Amazon EC2 Elastic Load Balancing – strategy for zero downtime server restart

amazon ec2amazon-web-servicesload balancingmonitoringreverse-proxy

I have 5 web servers (Apache/mod_perl) behind Amazon EC2 Elastic Load Balancing, when I deploy codes to the web servers, I am doing this..

  1. For each machine, shutdown the Apache
  2. Update the code
  3. Start over the server and proceed to the next server

I think when my server is shutdown, ELB will not distribute request to my server, but how about the request still serving?

I think a better approach is

  1. Stop accepting new request from ELB
  2. Sleep for sometimes, shutdown web server only if all requests are responded
  3. Update the codes
  4. Start the server again

But how to perform (1) and (2) from my local sever? Do I need to use AWS API? or other easy way to do it?

Thanks.

Best Answer

I run apache/mod_perl as load-balanced EC2 instances, and do code upgrades regularly just as you say. My process is:

  1. take an instance or two out of rotation
  2. shut down apache on that instance
  3. upgrade the instance(s)
  4. return to rotation, and remove the others

The AWS documentation goes over how to add and remove instance from rotation using either the API or the Console, your choice. You'll notice that with my approach, webservers go out of rotation gracefully, so I'm not worrying about whether a particular user request gets killed. As @cyberx86 mentioned, you can use the command apachectl -k graceful to shut down your apache server after each request is processed.

Related Topic