Keepailved Detailed Introduction

Source: Internet
Author: User
Tags failover reflector

I. Introduction of Keepalived

Keepalived is the next lightweight, high-availability solution for Linux, which is similar to heartbeat and Roseha implementations, and can be used for high availability of services or networks, and is differentiated, heartbeat is a professional, fully functional, highly available software. It provides the basic functions required by Ha software, such as heartbeat detection and resource takeover, monitoring of system services in the cluster, transfer of owners of shared IP addresses among cluster nodes, heartbeat powerful, but relatively cumbersome to deploy and use, compared to heartbeat Keepalived mainly through virtual routing redundancy to achieve high-availability features, although it is not heartbeat powerful, but keepalived deployment and use is very simple, all configurations need only one configuration file to complete.

Second, what is keepalived

Keepalived was originally designed for LVS, and is designed to monitor the status of each service node in the cluster. It detects the state of each service node based on the third, fourth, and fifth switching mechanisms of the TCP/IP reference Model, if a service node is abnormal, or if the work fails, keepalived detects and rejects the failed service node from the cluster system, and after the failed node returns to normal, Keepalived can also automatically rejoin this service node to the server cluster, which is fully automated and does not require manual intervention, but only repairs the failed service node manually.

Keepalived later joined the VRRP function, VRRP (virtualrouterredundancyprotocol, Virtual Routing Redundancy Protocol) appeared to solve the static route of the single point of failure problem, Through the VRRP can realize the network uninterrupted stable operation. Therefore, keepalived has the function of server state detection and fault isolation on the one hand, and HA cluster function on the other.

Iii. VRRP Protocol and working principle

1. Agreement

The VRRP protocol is designed to eliminate the network failure caused by the default router single point failure in the static default routing environment, which makes the device function switch without affecting the internal and external data communication in the event of failure, and does not need to modify the network parameters of the inner network. The VRRP protocol requires IP address backup, priority routing, and less unnecessary inter-router communication.

VRRP protocol to virtual two or more router devices into a device, the external provision of virtual router IP (one or more), and within the router group, if the actual router with the external IP if it is working properly is master, or by the algorithm elected, Master implements various network functions for virtual router IP, such as ARP requests, ICMP, and data forwarding, and so on; Other devices do not own the IP, and the status is backup, except to receive the VRRP status notification information of master, and does not perform external network functions. When the host fails, backup takes over the network functionality of the original master.

Configure the VRRP protocol to configure the virtual router ID (Vrid) and priority values for each router, use Vrid to group routers, routers with the same Vrid value for the same group, and Vrid to be a positive integer of 0~255 The routers in the same group elect master by using the priority value, the priority is master, and the priority is also a positive integer of 0~255.

The VRRP protocol uses multicast data to transmit VRRP data, VRRP data sends data using a special virtual source MAC address instead of the MAC address of its own network card, and the VRRP runtime only has the master router periodically sending VRRP notification messages. Indicates that master is working properly and the virtual router IP (group), backup receives only VRRP data, does not send data, and if no notification of master is received within a certain period of time, each backup will declare itself master, send notification information, Re-conduct the master election status.

2. Master Election

If the external virtual router IP is the router itself configured IP address, the router is always master; otherwise, if the virtual IP is not available, the master election will be made, each router declares itself master, sending VRRP notification information If the notification message received from other machines is higher priority than itself, it will revert back to backup state, and if the priority is equal, the higher priority of the actual IP,IP value of the router will be compared, but if the external virtual router IP is the IP of the router itself, The router will always be master, at which point the priority value is 255.

Iv. keepalived System Structure

Keepalived is also a modular design, different modules complex different functions, the following is the keepalived components

    • Core: It is the kernel of keepalived, the start and maintenance of complex main process, the load parsing of global configuration file, etc.

    • Check: Responsible for Healthchecker (health check), including a variety of health check methods, as well as the corresponding configuration analysis including LVS configuration analysis

    • VRRP:VRRPD Sub-process, VRRPD child process is to implement the VRRP protocol

    • Libipfwc:iptables (ipchains) library, configure LVS to use

    • libipvs*: Configuring LVS will be used

Note that keepalived and LVs are completely different, except that they accountability with each other.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/77/F4/wKiom1ZyIeWx_uEQAAJ9-ohqITI333.jpg "title=" 114758vj2ob2p2hxvpdxvb.png.thumb.jpg "alt=" Wkiom1zyiewx_ueqaaj9-ohqiti333.jpg "/>

The keepalived architecture is divided into two tiers, namely the user space layer and the kernel space layer (Kernel spaces).

The kernel space layer is at the lowest level, and it includes two modules of Ipvs and NetLink. Ipvs module is a third-party module introduced by Keepalived, which can realize IP-based load Balancing cluster by Ipvs, Ipvs is included in LVS cluster software by default. In the LVS cluster, the IPVS can be installed on a server called director server, while the Director server virtual an IP address to provide services, and the user must pass this virtual IP address to access the service. This virtual IP is generally called the LVS VIP, the access request first passes through the VIP to the director server, and then the Director server selects a service node from the server cluster node in response to the user's request.

NetLink module is mainly used to implement some advanced routing framework and some related network functions, complete the user space Layer NetLink Reflector module sent a variety of network requests.

In the user space layer, keepalived is divided into 4 parts, namely Scheduler I/O multiplexer, Memory Management, Control plane and core components.

Scheduler I/o multiplexer: is an I/O multiplexed distribution Scheduler, which is responsible for scheduling keepalived internal task requests.

Memory Management: This is a mechanism for the management of memories, a framework that provides some common methods of accessing memory.

Control Plane: is the keepalived dashboard, can be implemented to compile and parse the configuration file, keepalived configuration file resolution is special, it is not a parse so the configuration of the module, Instead, the corresponding configuration is resolved only when a module is used.

Core Components : This is part of the keepalived component, which includes a range of functional modules, including watchdog, Checkers, VRRP Stack, IPVS wrapper, and NetLink Reflector.

    • WatchDog

Watchdog is a very simple and very effective detection tool in the field of computer reliability, it works by setting a counter and a threshold value for the target being monitored, watchdog increments the secondary count value itself, and waits for the monitored target to reset the count periodically. Once an error is detected on the target, the value cannot be reset, watchdog will detect, and then take corresponding recovery measures, such as restarting or shutting down.

The watchdog feature was introduced early in Linux, and keepalived is monitoring checkers and VRRP processes through watchdog's operating mechanism.

    • Checkers

This is the most basic function of keepalived, and also the most important function, which can realize the server running state detection and fault isolation.

    • VRRP Stack

This is the VRRP feature that keepalived later introduced, which can implement the HA cluster failover (Failover) function. Keepalived can deploy a high-performance load-balancing cluster system with the VRRP function combined with the LVS load balancer software.

    • IPVS Wrapper

This is an implementation of the Ipvs feature. The IPVS wrapper module can send a set of IPVS rules to the kernel space and submit it to the IPVS module, which ultimately implements the load balancing function of the IPVS module.

    • NetLink Reflector

Used to set up and switch virtual IP (VIP) when failover in a highly available cluster. All requests to the NetLink reflector are finally sent to the NetLink module of the kernel space layer to complete.


Keepalived will have three processes after startup

    • Parent process: Memory management, child process management, etc.

    • Subprocess: VRRP Child process

    • Subprocess: Healthchecker Child process

It is shown that two sub-processes are supervised by the system watchdog, two sub-processes each complex their own things, healthchecker sub-process complex check the health of their respective servers, such as Http,lvs and so on, If the Healthchecker child process checks that the service is not available on master, it notifies the sibling VRRP child process on the machine, letting him delete the advertisement, and removing the virtual IP to the backup state.




This article is from the "Little Water Drop" blog, please make sure to keep this source http://wangzan18.blog.51cto.com/8021085/1725517

Keepailved Detailed Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.