4

I have two identical storage hosts where the master is the only one the users can access. If the master fails, then I want to manually change the DHCP address, so instead of master points to 10.10.10.10 it should point to 10.10.10.11.

There are replication scripts that rely on IP addresses, so if the master changes IP address, then I have to modify the IP in the scripts, so the data is still replicated from the master to the slave.

Question

It is quite an error prone task to switch IP adresses and edit scripts. Is there an common practice how this sort of manual failover is done? E.g. by adding an abstraction layer of some sort?

Sandra
  • 10,303
  • 38
  • 112
  • 165

2 Answers2

13

The common practice is to have a separate IP address and name for the service, one that is separate from the actual server's IP address and name.

In this case, you have

master 10.10.10.10
slave  10.10.10.11

A third name could be

storage 10.10.10.12

Your clients should use "storage" instead of "master" when they connect to the service.

As long as master is online, then 10.10.10.12 should be a virtual interface on master. If master is down, bring 10.10.10.12 up as a virtual interface on slave.

Avoid using IP addresses in scripts as far as possible. If DNS lookups aren't an option in a particular case, use a config file or the /etc/hosts files to map hostnames to IP addresses.

Jenny D
  • 27,780
  • 21
  • 75
  • 114
  • 1
    +100, if I could, for "*avoid using IP addresses in scripts as far as possible*". The troubles I've seen caused by that practice, over the years. – MadHatter Jan 16 '14 at 10:34
  • 2
    @MadHatter I see your script and raise you "hardcoded into binaries and lost the source code". I ended up editing the binaries in-place, replacing an IP address with a string that we resolved in /etc/hosts... That was a fun night. – Jenny D Jan 16 '14 at 10:38
  • 2
    I fold, mostly in admiration. – MadHatter Jan 16 '14 at 10:59
  • 1
    Admiration was not the feeling I was having... – Jenny D Jan 16 '14 at 11:01
0

If you would like a more automatic solution for failover then look at something like keepalived with uses the VRRP protocol.

More information can be found here

Virtual IP 10.10.10.10 (This is a virtual IP address and is configured on both hosts)

Master IP 10.10.10.11

Slave IP 10.10.10.12

This way you will not have to bring up the second interface on the slave and you have very little (maybe a second or so ) of downtime.

Leoric80
  • 49
  • 1
  • 5
  • This is automatic failover, which is not what I want. I use `ucarp` on other servers though. – Sandra Jan 16 '14 at 11:30