Keepalived software mainly implements high-availability functions through the VRRP protocol. VRRP is the abbreviation of Virtual Router Redundancy Protocol, VRRP is designed to solve the problem of single point of failure of static routes, which can ensure that when individual nodes go down, the entire network can run uninterruptedly. Therefore, Keepalived has the function of configuring and managing LVS, and also has the function of checking the health of nodes under LVS, and on the other hand, it can also realize the high availability function of system network services.
Keepalived High Availability Failover Principle
Keepalived failover between high-availability service pairs is implemented through VRRP (Virtual Router Redundancy Protocol).
When the Keepalived service is working normally, the master node will continuously send heartbeat messages to the standby node (multicast) to tell the backup node that it is still alive, and when the master node fails, it cannot send heartbeat messages, so the standby node can no longer detect the heartbeat from the master node, so it calls its own takeover program to take over the IP resources and services of the master node. When the primary master node is restored, the backup node releases the IP resources and services taken over by the master node and restores it to its original standby role.
Keepalived high-availability pairs communicate between each other via VRRP
1) VRRP, the full name of Virtual Router Redundancy Protocol, the Chinese name is Virtual Route Redundancy Protocol, VRRP emerged to solve the single point of failure of static routes. 2) VRRP is a campaign protocol mechanism that gives routing tasks to a VRRP router. 3) VRRP uses IP multicast (Default Multicast Address (224.0.0.18)) enables communication between highly available pairs. 4) When the master node sends packets and the standby node receives packets, when the standby node cannot receive the data packets sent by the master node, the takeover program is started to take over the resources of the master node. There can be multiple standby nodes, which are selected through priority competition, but generally there is a pair in the operation and maintenance of the Keepaled system. 5) VRRP uses an encryption protocol to encrypt data, but Keepalived officials still recommend using plaintext to configure the authentication type and password.
How the Keepalived service works
1) Keepalived high-availability pairs communicate through VRRP, VRRP is determined through the campaign mechanism, the priority of the master is higher than the standby, therefore, when working, the master will give priority to obtain all resources, the standby node is in a waiting state, when the master hangs, the standby node will take over the resources of the master node, and then replace the master node to provide services to the outside world.
2) between Keepalived service pairs,Only the server that is the master will send all the timeVRRPBroadcast packageWhen the master is unavailable, that is, when the host cannot listen to the broadcast package sent by the master, the relevant service will be started to take over the resources to ensure business continuity. The fastest takeover speed can be less than 1 second.
Test environment
System: CentOS 8
| IP address | illustrate | | 192.168.50.222 | VIP address | | 192.168.50.227 | MASTER master node | | 192.168.50.131 | BACKUP standby nodes |
Let's take a look at the completed renderings as follows:
Install the Nginx service
Use yum directly inMasternodeandAlternate nodesThe server installs nginx with the following command:
Edit the nginx configuration files of the primary and standby nodes separately, path:/etc/nginx/nginx.confThe configuration is as follows:
Started via nginx command, test access to port 8055 via browser, as shown in the following image:
Install Keepalived To install on both the primary node and the standby node, the command is as follows:
Profile address:/etc/keepalived/keepalived.conf
Here you need to configure a health check script and create a new onechk_nginx.shfile, the code is as follows:
Upload the script to the /etc/keepalived directory. and grant execution permissions as follows:
192.168.50.227 primary node keepalived.conf configurationAs follows:
192.168.50.133 Alternate node keepalived.conf configurationAs follows:
Set up boot and boot on both servers separately
So farThe configuration is completed (see the top of the article for the rendering), can be tested via the nginx service with the following command:
(End)
|