MySQL Replication – IP Failover

MySQLmysql-replication

So, I setup master-slave replication in MySQL on two virtual machines in two different physical servers. The problem that I am scratching my head at now, is, when the master goes down, how do the clients switch to the slave to do reads?

For example:

Master (192.168.1.1) mysql1.mydomain.com
Slave  (192.168.1.2) mysql2.mydomain.com

All clients currently connect to mysql1.mydomain.com, how in the world do I configure this? Seems like I need IP-Failover, or some DNS magic. A DNS magic record that was mysql-cluster.mydomain.com that always pointed to the MySQL server that is up or master, would be perfect.

Best Answer

You can use Heartbeat : It can manage a virtual IP address between your two nodes. Your clients will use this vip to connect to mysql - If the master fails, heartbeat detects it and ups the vip on the second node. Be careful not to set the auto-failover on the primary node when it comes back, because obviously his data will be outdated