【Introduction to Keepalived】

Keepalived is a free and open source, similar to layer3, 4 & 7 switching mechanism software written in C, with the functions of layer 3, layer 4 and layer 7 switches that we usually say. It mainly provides loadbalancing (load balancing) and high-availability (high-availability) functions. The implementation of load balancing needs to rely on the Linux virtual service kernel module (ipvs), and high availability is to realize the failover service between multiple machines through the VRRP protocol. 

 

Keepalived is a routing software written in C. The main goal of this project is to provide simple and robust facilities for loadbalancing and high-availability toLinux system and Linux based infrastructures. Loadbalancing framework relies on well-known and widely used Linux Virtual Server (IPVS) kernel module providing Layer4 loadbalancing. Keepalived implements a set of checkers to dynamically and adaptively maintain and manage loadbalanced server pool according their health. On the other hand high-availability is achieved by VRRP protocol. VRRP is a fundamental brick for router failover. In addition, Keepalived implements a set of hooks to the VRRP finite state machine providing low-level and high-speed protocol interactions. Keepalived frameworks can be used independently or all together to provide resilient infrastructures.

 

Keepalived is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

 

The role of Keepalived is to detect the status of the server. If a web server is down, or the work fails, Keepalived will detect and remove the faulty server from the system, and use other servers to replace the work of the server. When the server After the work is normal, Keepalived automatically adds the server to the server group. All these tasks are completed automatically without manual intervention. All that needs to be done manually is to repair the faulty server.

 

 

The working principle of keepalived is VRRP (Virtual Router Redundancy Protocol) virtual routing redundancy protocol.

There are two important concepts in VRRP: VRRP routers and virtual routers, master routers and backup routers.

A VRRP router is a router that runs VRRP and is a physical entity. A virtual router is created by the VRRP protocol and is a logical concept. A group of VRRP routers work together to form a virtual router. There is an election mechanism in Vrrp, which is used to select the route that provides services, that is, the master route, and the others become backup routes. When the master route fails, a master route will be re-elected from the backup route to continue working to ensure uninterrupted service.

 

 

How keepalived works

Keepalived is based on the VRRP protocol. The full name of VRRP is Virtual Router Redundancy Protocol, that is, virtual routing redundancy protocol.

The virtual routing redundancy protocol can be considered as a protocol for realizing high availability of routers, that is, N routers that provide the same function form a router group. This group has a master and multiple backups, and the master has a vip that provides services to the outside world ( The default route of other machines in the local area network where the router is located is the vip), the master will send multicast, and when the backup cannot receive the vrrp packet, it is considered that the master is down, and then a backup needs to be elected according to the VRRP priority. master. In this way, the high availability of the router can be guaranteed.

keepalived mainly has three modules, namely core, check and vrrp. The core module is the core of keepalived, responsible for the startup and maintenance of the main process and the loading and parsing of global configuration files. check is responsible for health checks, including various common check methods. The vrrp module is used to implement the VRRP protocol.

 



 

 

 

How Keepalived Works

Layer3,4&7 work in the IP layer, TCP layer, and application layer of the IP/TCP protocol stack. The principles are as follows:

Layer3: When Keepalived works in Layer3 mode, Keepalived will periodically send an ICMP data packet (that is, the Ping program we usually use) to the server in the server group. If it finds that the IP address of a service is not activated, Keepalived will report This server fails, and it is removed from the server farm. A typical example of this situation is a server being shut down illegally. The Layer 3 method is based on whether the server's IP address is valid or not as the standard for whether the server works normally or not.

Layer4: Layer4 is easy if you understand the way of Layer3. Layer4 mainly determines whether the server is working normally or not based on the status of the TCP port. For example, the service port of the web server is generally 80. If Keepalived detects that port 80 is not activated, Keepalived will remove this server from the server group.

Layer7 : Layer7 works in a specific application layer, which is a little more complicated than Layer3 and Layer4, and occupies a larger bandwidth on the network. Keepalived will check whether the server program is running normally according to the user's settings. If it does not match the user's settings, Keepalived will remove the server from the server group.

 

 

Kernel space: mainly includes IPVS (IP virtual server, used to achieve load balancing of network services) and NETLINK (provides advanced routing and other related network functions) two parts. 

User space:

 

WatchDog: Load monitoring checkers and the status of VRRP processes

VRRP Stack: Failover between load balancers. If only one load balancer is used, VRRP is not necessary.

Checkers: Responsible for the health checking of the real server, which is the main function of keepalived. In other words, there is no VRRP Stack, but healthchecking is a must.

IPVS wrapper: the user sends the set rules to the kernel ipvs code

Netlink Reflector: used to set the vip address of vrrp, etc.

All functions of Keepalived are implemented by configuring the keepalived.conf file.

 

 

Keepalived effect

Mainly used for RealServer health status check and implementation of failover between LoadBalance host and BackUP host.

Highly available web architecture: LVS+keepalived+nginx+apache+php+eaccelerator (+nfs optional)

Guess you like

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