Principle of virtual IP

High Availability (HA) refers to improving the availability of systems and applications by minimizing downtime caused by routine maintenance operations (planned) and sudden system crashes (unplanned). The HA system is currently the most effective means for enterprises to prevent the core computer system from being shut down due to failure.

The way to achieve HA is generally to use two machines to complete a function at the same time, such as a database server, usually only one machine provides services to the outside world, and the other machine is used as a hot backup. When this machine fails, it automatically and dynamically switches to another machine. A hot standby machine.

How to achieve failure detection that?

      Heartbeat, using timing to send a data packet, if the machine does not respond for a long time, it is considered a failure and automatically switches to the hot standby machine.

How to achieve automatic switching that?

      Virtual IP. What is a virtual IP, that is, an IP that is not assigned to a real host, that is to say, the host that provides the database server to the outside world has a virtual IP in addition to a real IP, and any one of these two IPs can be used to connect to. This host, the database link in all projects is configured with this virtual IP. When the server fails and cannot provide services to the outside world, this virtual IP is dynamically switched to the standby host.



At first, I didn't understand how this was implemented. I thought it was software to dynamically change the IP address, but that's not the case. The implementation principle mainly relies on the ARP protocol of TCP/IP. Because the ip address is only a logical address, the MAC address is the real physical address used for data transmission in Ethernet. Each host has an ARP cache, which stores the correspondence between the IP address and the MAC address in the same network. When the host in the Ethernet sends data, it will first query the MAC address corresponding to the target IP from this cache, and will send data to this MAC address. The operating system automatically maintains this cache. That's the crux of the whole implementation.

Below is the content of the arp cache on my computer.

(192.168.1.219) at 00:21:5A:DB:68:E8 [ether] on bond0
(192.168.1.217) at 00:21:5A:DB:68:E8 [ether] on bond0
(192.168.1.218) at 00:21:5A:DB:7F:C2 [ether] on bond0



192.168.1.217, 192.168. 1.218 are two real computers, and

192.168.1.217 is the host that provides database services to the outside world.

192.168.1.218 is a hot standby machine.

192.168.1.219 is the virtual IP.

Look carefully, the MAC addresses of 219 and 217 are the same.

Let's look at the arp cache after 217 crashes

(192.168.1.219) at 00:21:5A:DB:7F:C2 [ether] on bond0
(192.168.1.217) at 00:21:5A:DB:68:E8 [ether] on bond0
(192.168.1.218) at 00:21:5A:DB:7F:C2 [ether] on bond0

This is the secret. When 218 finds that 217 is down, it will send an ARP packet to the network, telling all hosts that the MAC address corresponding to this IP 192.168.1.219 is 00:21:5A:DB:7F:C2, so that all packets sent to 219 will be Send to the machine whose mac address is 00:21:5A:DB:7F:C2, which is the machine of 218.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326217331&siteId=291194637