How to handle IP's with manual failover?
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?
Solution 1:
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.