Tianyi cloud virtual IP address and its application in high availability cluster

Time:2022-5-8

In many application scenarios, it is necessary to build a highly available cluster in the cloud platform, which requires the virtual IP address function. Today, let’s talk about virtual IP address and its application scenarios.

1、 High availability cluster
Before talking about virtual IP addresses, let’s first understand what high availability clusters are.
High availability cluster, or failover cluster, refers to the combination of several servers into a cluster system to provide services through the cluster software. Generally, only one of these servers is providing services at the same time (called the primary node or master node), and other servers are on standby (called the standby node or slave node), When the primary node has a server failure or an application problem, the cluster software automatically switches the service to the standby node, realizes the automatic transfer of the failure, restores the service to normal and shortens the service unavailability time.

2、 Difference between high availability cluster and load balancing cluster
Tianyi cloud platform has provided elastic load balancing services, which can also achieve high availability of business. Why do we need high availability clusters instead of using load balancers directly?
This is because the usage scenarios of load balancing cluster and high availability cluster are different.
The function of the load balancer is to distribute the received application requests to the back-end real server according to the configured algorithm. At the same time, the load balancer is responsible for fault detection. If the back-end real server fails, the load balancer will remove the failed real server from the distribution list, and the application requests will not be distributed to the failed server to realize fault isolation. This scenario is generally applied to the scenario where the status of the back-end server is equal, just like going to the telecom business hall to handle business. There is no difference between going to counter 1 or counter 2, and you can handle business normally. Therefore, load balancer is generally used in web server and application server scenarios.
Think about it. The load balancer helps us achieve high availability of web server or application server. What if there is something wrong with the load balancer itself? Is the whole business system pawned? Although load balancing can also be deployed hierarchically. One load balancer redistributes services to multiple load balancers at the back end, the first level load balancer may still have a single point of failure. This requires high availability clusters.
The high availability cluster is mainly used for the scenario where the service interface can only be a single interface. For example, there will only be one general manager in a company, and there may be several deputy general managers. The division of labor of several deputy general managers will be different, but there will always be only one general manager. If the general manager cannot continue to perform his duties for some reasons, he may be promoted from several vice presidents or airborne as the general manager. These vice presidents are like the back-end real servers under the load balancing architecture. If the general manager cannot perform his duties, it is like the load balancer itself has failed, and a new general manager must be arranged to take over.

3、 Virtual IP address in high availability cluster
A highly available cluster needs a unified access portal, which is the IP address. If the master node crashes, the standby node should also take over the application access portal after taking over the application, otherwise the client will continue to access the crashed master node.
For example, in the drawing, the IP address of the primary node of the cluster is 192.168.1.10 and the IP address of the standby node is 192.168.1.11. Under normal circumstances, the client accesses the IP address of the primary node 192.168.1.10. If the primary node crashes, two steps need to be done to realize fault switching: 1. Start the application on the standby node; 2. Modify the IP address of the standby node to 192.168.1.10. This requires manual intervention, because the IP address cannot be changed at will, and the purpose of automatic failover cannot be achieved. This kind of cluster is generally called cold standby. The standby node can even be shut down at ordinary times. After the primary node fails, it will intervene manually to restore business.
Tianyi cloud virtual IP address and its application in high availability cluster

In order to realize the automatic switching of client access portal IP address, virtual IP address is introduced into high availability cluster. The virtual IP address is also called VIP or floating IP. In the figure, we add a virtual IP address 192.168.1.20 , and configure it on the primary node. After the primary node fails, the cluster software will automatically add this virtual IP address on the standby node. In this way, there are actually three IP addresses in the cluster. 192.168.1.10 and 192.168.1.11 are generally referred to as private IP addresses or fixed IP addresses. They will not change with the master-slave handover of the application, while 192.168.1.20 will switch between the two nodes according to the situation.
When the master node is normal, the virtual IP address is on the master node and the master node provides services:
Tianyi cloud virtual IP address and its application in high availability cluster

After the master node crashes, the service is taken over by the standby node, and the virtual IP address is automatically switched to the standby node:
4、 Tianyi cloud virtual IP address
In the traditional IT system, the virtual IP address can be used normally after being configured by the cluster software.
On the public cloud platform, you need to apply for a virtual IP address on the cloud platform, bind it to the virtual machine in the highly available cluster, and then configure this virtual IP address in the cluster software to work normally.
The virtual IP address can be bound to an elastic public network IP address at the same time to access the high availability cluster from the public network.
The application method of virtual IP is to enter the virtual private cloud menu on the Tianyi cloud console, enter the subnet where the virtual IP needs to be created, click the “virtual IP” page, and apply for a virtual IP address.
Tianyi cloud virtual IP address and its application in high availability cluster

After the virtual IP address application is completed, you need to bind the virtual IP address to the virtual machine in the highly available cluster, and you can bind the virtual IP address to an elastic public network IP address.
After binding, the architecture of the platform is as follows:
Tianyi cloud virtual IP address and its application in high availability cluster

5、 Common high availability cluster software and its application
At present, the most commonly used high availability cluster software on the public cloud platform is the open source keepalived software. Keepalived only supports the Linux operating system. It maintains a virtual IP address in the cluster, monitors the status of applications, switches virtual IP addresses and starts and stops applications.
Examples of common application scenarios:
1. Keep alive + LVS / haproxy to realize high availability load balancing cluster
2. Keep alive + nginx / Tomcat and other middleware to realize high availability application cluster
3. Keep alive + Mysql to realize MySQL high availability cluster
4. Kept + kubernetes # to realize container high availability cluster