# Automatic Failover?

## CurtE

I'm not sure if that is the right term for what I need but we will see.

I have two servers, each with their own static IP's (x.x.x.9 and x.x.x.10).  Recently, the x.x.x.10 server's fan was getting too loud and I proceeded to copy the web pages over to x.x.x.9 to let it do the job.  I turned off x.x.x.10 and expected the other server would be working.  

My domain names are pointed at both IP's, so what am I missing

----------

## erik258

Hello CurtE, 

DNS round-robin load balancing, unfortunately, does not constitute failover.  Your DNS servers are likely to continue serving both the domain that's offline and the domain that's online.  Depending on the system you're using to test, you could very well be caching the wrong IP and never trying the other.

Typically if you're not caching any IPs - at least on my linux workstations - and also depending on the dns server in use - you'd see first results with A before B, then results with B before A (where A and B are your round-robin addresses).  So in other words you'd probably only get the website up half the time. 

If you want _real_ failover, you need to do something more complicated than load balancing in DNS.  You could use virtual IPs or something.  DNS results are cached typically at multiple points in the DNS lookup path and so DNS is way too slow to provide any failover.  Even if the TTL on your records is slow, DNS servers are typically too ill behaved to actually allow quick fail-over.  

But the good news for you is your don't really need failover.  You just want to stop serving the website on .10.  Failover is only appropriate if you have more than one server capable of serving the webpage*.  You appear to only want one of your servers doing so.  

To achieve that,  there are several options.   One is to simply forward the traffic on .10:80 to .9:80 with iptables.  If you're familiar with iptables you might find this easy.  Another is to set up an HTTP load balancer or reverse proxy like pound (http://www.apsis.ch/pound/) -- though nginx is much faster and way better threaded, at least up until recent versions of pound, you'll probably find no difference unless you're serving large amounts of traffic, at least dozens of hits a second.  The cool thing about pound is it's super trivial to configure.  But it comes at a price; it is in the middle of web transactions, and that can lead to unexpectedness - most notably, your client's IP will be the load balancer's IP , and the real client's ip will be in a different header.  

* by the way, serving web pages from 2 servers w/ failover isn't actually quite as simple as just giving them both the docs to store, even once your incoming connections fail over.  Have you thought about sessions at all?  (a solution: memcached).  Shared storage without a single point of failure?  (a solution: gluster).  It's a tricky problem, but actually not too difficult.  Sessions are the big one that are easy to miss.

----------

## CurtE

I guess the concept is the problem.  As sophisticated as systems are, you would think it could understand that if IP #1 didn't work, try #2.

At this point and time, how many files do I need to change to make the server's IP's switch (x.x.x.9 <--> x.x.x.10)?

/etc/hosts

/etc/resolv.conf

Are there more?

At this point and time, there is no problem of loss of data because one server is down and the other taking over.  The only issue would be the family photo section and I can handle that easy enough.

As for the other options, correct me if I'm wrong, they all go on the assumption that both servers are up and running, not that there is a system failure.  It looks like they are examining a working system to decide where to go.

----------

## richard.scott

You could install keepalived and use the VRRP feature.

You'd have a new IP for your website x.x.x.11 for example, and this would automatically be setup on the master node.

If you reboot the master node, the secondary node will detect this and become the master.

You'd only have about 3 seconds of downtime while the IP moves server.

Rich

----------

