Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EC2 instance is out of service in loadbalancer

I have an EC2 instance up and running. I have a load balancer where its associated with EC2 instance.

Ping Target         : HTTP:3001/healthCheck
Timeout             : 5 seconds
Interval            : 24 seconds
Unhealthy threshold : 2
Healthy threshold   : 10

enter image description here Now the instance is shown as OutofService. I even tried changing listening ports and all. Things were working until,rebooted my EC2 instance. Any help would be higly appreciated.

Just for the info: I have rails app running at port 3001 and I have one listenser for HTTP:80(loadbalancer) to HTTP:3001.

I also have checked the working app through ssh in the terminal.

like image 378
Sunil B N Avatar asked Nov 07 '16 10:11

Sunil B N


People also ask

Why is ELB out of service?

An instance might fail the ELB health check because an application running on the instance has issues that cause the load balancer to consider the instance out of service.

How do I fix AWS load balancer?

If the load balancer is not responding to requests, check for the following issues: Your internet-facing load balancer is attached to a private subnet. You must specify public subnets for your load balancer. A public subnet has a route to the Internet Gateway for your virtual private cloud (VPC).

What happens if Loadbalancer is down?

If your load balancer now loses its internet connection, power, or breaks for any reason, you will now lose connection to all of your backend servers. We call this moving up the single point of failure, as you have moved the single point of failure up from the application servers to the load balancer.


2 Answers

Suggestion#1:

If the current state of some or all your instances is OutOfService and the description field displays the message that the Instance has failed at least the Unhealthy Threshold number of health checks consecutively, the instances have failed the load balancer health check.

The following are the issues to look for, the potential causes, and the steps you can take to resolve the issues by following this link: Troubleshoot a Classic Load Balancer: Health Checks

Suggestion#2:

chrisa_pm has given some advice for this issue:

If you can confirm that your EC2 instance is reachable, you can remove it from your Load Balancer and add it back again. The Load Balancer will recognize it after a few minutes though.

Keep in mind that you need to confirm the health as it is set in your Health Check configuration:

  1. For HTTP:80 you need to specify a page that is actually reachable (like index.html)
  2. For TCP:80 it will only be needed access to the 80 TCP port.

Suggestion#3:

qh2 has make a solution by the following way

Create a service in startup to deregister and register again your instance.

Example: file awsloadbalancer

#!/bin/sh
chkconfig: 2345 95 20

When a isntance is stopped a load balancer is missed. this rebuild load balancer

case "$1" in
start)
aws --region eu-west-1 elb deregister-instances-from-load-balancer --load-balancer-name test --instances i-3c339b7c
aws --region eu-west-1 elb register-instances-with-load-balancer --load-balancer-name test --instances i-3c339b7c
;;
stop)
echo "stopping aws instances"
;;
restart)
echo "Restarting aws, nothing to do"
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac

create file in /etc/init.d/ after that, register as service.

Suggestion#4:

Kenneth Snyder also solved the issue for specific ELB issue.

I also had similar issue but I was able to fix that.

I had created a security group for ELB which accepts request on port 80 and forward to EC2 on port 80. The security group that was earlier created for EC2 has also inbound rules for port 80 and RDP.

Still the instances were showing as OutOfService under ELB. Later i tried to add another inbound rule in the EC2's security group to allow port 80 for the SG that was created for ELB. and that worked.

I guess it requires the ELB SG to be allowed in the rules created for individual instance's SG. Hope that helps.

Resource Link:

https://forums.aws.amazon.com/thread.jspa?messageID=733153

like image 133
SkyWalker Avatar answered Oct 13 '22 11:10

SkyWalker


Did you provide a health check endpoint and specified it in the EC2 console? Something like:

Health check snapshot

Note the port 80 and a valid route. You probably didn't set the port 3001 in your nginx/apache config

In the rails app, create an action like so:

class HealthCheckController < ActionController::Base
  def ping
    head :ok
  end
end

and route:

get 'health_check/ping'

The AWS load balancer will ping his endpoint and if the response is a 200 OK enough times (as per the Healthy threshold, it will deem the instance as "Healthy".

like image 41
Vedant Agarwala Avatar answered Oct 13 '22 12:10

Vedant Agarwala