search
How does keepalived work?Jun 24, 2021 am 11:08 AM
keepalivedworking principle

The working principle of keepalived is to detect the status of each service node based on the third, fourth and fifth layer switching mechanisms of the TCP/IP reference model. If a server node is abnormal or fails, Keepalived will The failed server node is detected and removed from the cluster system.

How does keepalived work?

The operating environment of this tutorial: centos7 system, thinkpad t480 computer.

Keepalived introduction

Keepalived is the next lightweight level high-availability solution for Linux. High availability: In a broad sense, it refers to the high availability of the entire system; in a narrow sense, it refers to the redundancy and takeover of the host.

It implements similar functions to HeartBeat, both of which can achieve high availability of services or networks, but there are differences. HeartBeat is a professional, fully functional high-availability software that provides the basic requirements for HA software. Functions, such as: heartbeat detection, resource takeover, detection of services in the cluster, transfer of owners of shared IP addresses on cluster nodes, etc.

HeartBeat is powerful, but deployment and use are relatively troublesome. Compared with HeartBeat, Keepalived mainly implements high availability functions through virtual routing redundancy. Although it is not as powerful as HeartBeat, Keepalived is very easy to deploy and use. Extremely simple, all configurations only require one configuration file.

What is Keepalived?

Keepalived was originally designed for LVS and is specifically used to monitor the status of each service node in the cluster system. It is based on the third, fourth and fifth layer switching mechanisms of the TCP/IP reference model. Detect the status of each service node. If a server node is abnormal or the work fails, Keepalived will detect it and remove the failed server node from the cluster system. All these tasks are completed automatically and do not require Manual intervention requires manual work only to repair the failed service node.

Later Keepalived added the VRRP function. The purpose of VRRP (VritrualRouterRedundancyProtocol, virtual routing redundancy protocol) is to solve the single point of failure problem in static routing. VRRP can achieve uninterrupted and stable operation of the network, so On the one hand, Keepalvied has server status detection and fault isolation functions, and on the other hand, it also has the HAcluster function.

Health check and failover are the two core functions of keepalived. The so-called health check uses TCP three-way handshake, ICMP request, HTTP request, UDP echo request, etc. to keep alive the actual server behind the load balancer (usually the server that carries the real business); while failed switching is mainly the application For load balancers configured in active and standby mode, VRRP is used to maintain the heartbeat of the active and standby load balancers. When a problem occurs with the active load balancer, the standby load balancer carries the corresponding services, thereby minimizing traffic loss and Provide stability of services.

VRRP protocol and working principle

In a real network environment. Communication between hosts is completed by configuring static routing or (default gateway). Once the router between hosts fails, communication will fail. Therefore, in this communication mode, the router becomes a single point bottleneck. ,In order to solve this problem, the VRRP protocol was ,introduced.

The VRRP protocol is a fault-tolerant master-backup mode protocol, which ensures that when the host's next-hop route fails, another router will replace the failed router. VRRP can be used on the network When a failure occurs, device switching is performed transparently without affecting data communication between hosts.

How does keepalived work?

Virtual router: A virtual router is a collection of all routers in a VRRP backup group. It is a logical concept and does not really exist. Looking at the routers in the backup group from outside the backup group, it feels like all the routers in the group are the same, which can be understood as being in a group: main router all backup routers = virtual routers.

A virtual router has a virtual IP address and MAC address. The host uses the virtual router as the default gateway. The format of the virtual MAC address is 00-00-5E-00-01-{VRID}. Normally, the virtual router uses the virtual MAC address in response to the ARP request. Only when the virtual router is specially configured, will it respond to the real MAC address of the interface.

Main router (MASTER): The virtual router provides services to the outside world through the virtual IP, and within the virtual router, there is only one physical router that provides services to the outside world at the same time. This physical router that provides services is called the master router. Generally, the Master is generated by an election algorithm. It has a virtual IP for external services and provides various network functions, such as ARP requests, ICMP data forwarding, etc.

Backup router (BACKUP): Other physical routers in the virtual router do not have external virtual IPs, nor do they provide external network functions. They only accept the VRRP status advertisement information of the MASTER. These routers are called backup routers. When the main router fails, the backup router in the BACKUP role will be re-elected to generate a new main router to enter the MASTER role and continue to provide external services. The entire switch is completely transparent to users.

VRRP election mechanism

The VRRP router has three states during operation:

1. Initialize state: After the system starts, it enters Initialize. In this state, the router does not process VRRP packets;

2. Master state;

3. Backup state;

Generally, the main router is in the Master state and the backup router is in the Backup state. state.

VRRP uses an election mechanism to determine the status of the router. Priority election:

1. IP owner in the VRRP group. If the virtual IP address is the same as the IP address of a VRRP router in the VRRP group, then this router is the owner of the IP address and this router will be positioned as the master router.

2. Compare priorities. If there is no IP address owner, compare the priorities of the routers. The priority range is 0~255. The one with the higher priority will be used as the main router

3. Compare the IP addresses. In the case where there is no IP address owner and the priority is the same, the one with the larger IP address acts as the main router.

As shown in the figure below, the virtual IP is 10.1.1.254. There is no IP address owner in the VRRP group. Then compare the priorities. Obviously the priorities of RB and RA are greater than RC. Then compare RA and RB. The IP address of RB is larger. So RB is the main router in the group.

How does keepalived work?

Working process

After the router uses the VRRP function, it will determine its role in the backup group based on priority. The router with higher priority becomes the Master router, and the router with lower priority becomes the Backup router. The Master has a virtual IP for external services, provides various network functions, and regularly sends VRRP messages to notify other devices in the backup group that it is working normally; the Backup router only receives message information sent by the Master to monitor the operation of the Master. state. When the Master fails, the Backup router will elect, and the Backup with higher priority will become the new Master.

In preemption mode, when the Backup router receives the VRRP message, it will compare its own priority with the priority in the message. If it is greater than the priority in the advertisement message, it will become the Master router; otherwise it will remain in the Backup state;

In non-preemption mode, as long as the Master router does not fail, the routers in the backup group will always remain Master or Backup. status, the Backup router will not become the Master router even if it is subsequently configured with a higher priority;

If the Backup router does not receive the VRRP message sent by the Master router after its timer expires, it is considered The Master router is no longer working properly. At this time, the Backup router will think that it is the Master router and send VRRP packets to the outside world. The routers in the backup group elect a master router based on priority to assume the packet forwarding function.

Keepalvied’s working principle

Keepalived’s working principle for server running status and fault isolation:

Keepalived works in the third phase of the TCP/IP reference model Layer, four, and five (physical layer, link layer):

Network layer (3): Keepalived sends an ICMP packet to each node in the server cluster through the ICMP protocol (somewhat similar to Ping function), if a node does not return a response packet, it is considered that the node has failed. Keepalived will report the node failure and remove the failed node from the server cluster.

Transport layer (4): Keepalived uses the port connection and scanning technology of the TCP protocol in the transport layer to determine whether the port of the cluster node is normal, such as port 80 of the common WEB server. Or SSH service port 22. Once Keepalived detects that these port numbers have no data response or data return at the transport layer, it will consider these ports to be abnormal, and then forcibly remove the nodes corresponding to these ports from the server cluster.

Application layer (5): The operation mode of Keepalived is also more comprehensive and complex. Users can customize the working mode of Keepalived. For example, you can run Keepalived by writing a program or script, and Keepalived will be run according to the The user's set parameters detect whether various programs or services are allowed to function normally. If Keepalived's detection results are inconsistent with the user's settings, Keepalived will remove the corresponding server from the server cluster.

Keepalived Architecture

Keepalived was originally designed for LVS. Since Keepalived can detect the status of cluster nodes, and IPVS can realize the load balancing function, Keepalived relies on The third-party module IPVS can easily build a load balancing system. The IPVS module in Keepalived is configurable. If you need the load balancing function, you can turn on the load balancing function when compiling Keepalived, or turn it off through compilation parameters.

How does keepalived work?

SchedulerI/OMultiplexer is an I/O multiplexing distribution scheduler, which loads all internal task requests of Keepalived;

Memory Mngt is a memory Management mechanism, this framework provides some common methods of accessing memory;

Control Plane is the control plane of keepalived, which can compile and parse configuration files;

Core componets This part mainly includes 5 parts;

  • Watchdog: It is an extremely simple and very effective detection tool in the field of computer reliability. Keepalived monitors Checkers and VRRP processes through it.

  • Checkers: This is the most basic function of Keepalived and the most important function. It can detect the running status of the server and isolate faults.

  • VRRP Stack: This is the VRRP function that keepalived later quoted, which can realize the failover function in the HA cluster. Responsible for failover switching between load balancers FailOver;

  • IPVS wrapper: This is an implementation of the IPVS function. The IPVSwarrper module sends the kernel space that can be set up and provides IPVS rules to IPVS module finally realizes the load function of IPVS module.

  • Netlink Reflector: Used to implement the setting and switching of virtual IP (VIP) during high-availability cluster Failover.

When keepalived is running, it will Start 3 processes, namely: core (core process), check and vrrp

- core: responsible for the startup, maintenance and loading of the global configuration file of the main process;

- check: responsible for Health check

- vrrp: Used to implement the vrrp protocol

Compare with heartbeat/corosync

The three cluster components of Heartbeat, Corosync, and Keepalived Which one should we choose? Heartbeat and Corosync belong to the same type. Keepalived, Heartbeat and Corosync are not the same type at all.

Keepalived uses the vrrp virtual routing redundancy protocol method; Heartbeat or Corosync is a high-availability method based on host or network services; simply put, the purpose of Keepalived is to simulate the high availability of the router, Heartbeat or Corosync The purpose is to achieve high availability of Service.

So generally Keepalived is used to achieve front-end high availability. Commonly used combinations of front-end high availability include our common LVS Keepalived, Nginx Keepalived, and HAproxy Keepalived. Heartbeat or Corosync is used to achieve high availability of services. Common combinations include Heartbeat v3 (Corosync) Pacemaker NFS Httpd to achieve high availability of Web servers, and Heartbeat v3 (Corosync) Pacemaker NFS MySQL to achieve high availability of MySQL servers.

To summarize, Keepalived implements lightweight high availability, which is generally used for front-end high availability and does not require shared storage. It is generally used for high availability of two nodes. Heartbeat (or Corosync) is generally used for high availability of services and requires shared storage, and is generally used for high availability of multiple nodes.

(Recommended learning: linux tutorial)

The above is the detailed content of How does keepalived work?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
什么是 Microsoft Teams 中的对讲机及其工作原理?什么是 Microsoft Teams 中的对讲机及其工作原理?Apr 14, 2023 pm 12:31 PM

Microsoft Teams 上的对讲机是什么?顾名思义,新的 Walkie Talkie 功能让 Microsoft Teams 上的用户可以通过使用他们的声音与他们的团队成员进行实时交流,从而与他们联系。在频道中连接到 Walkie Talkie 的用户可以一次听一个即按即说格式的对方讲话。这样一来,只有一个人在说话的时候才能引起注意,而不会被其他人打断。微软将这一功能定

听诊器的工作原理是什么听诊器的工作原理是什么Aug 31, 2023 pm 02:37 PM

听诊器的工作原理是通过声学传感器将人体内部的声音转化成电信号,然后通过耳机或扩音器放大和传输这些信号给医生,它的工作原理基于声学原理,能够帮助医生听到内部声音并进行疾病诊断。听诊器的核心部件是声学传感器,通常由一个共振膜和一个接收器组成,共振膜是一个薄膜,通常由金属或塑料制成,它能够感受到人体内部的声音振动,当共振膜受到声波的作用时,它会产生微小的振动。

vue中keep-alive的工作原理及使用方法详解vue中keep-alive的工作原理及使用方法详解Jul 21, 2023 am 11:58 AM

Vue.js是一个流行的前端框架,提供了一些方便的功能来优化性能和提升开发效率。其中一个功能是keep-alive,它可以帮助我们在组件之间保留状态,从而减少不必要的渲染和请求。本文将详细介绍keep-alive的工作原理以及使用方法,并提供一些代码示例。一、keep-alive的工作原理在Vue.js中,每当我们切换组件时,组件都会被重新创建

如何用Keepalived+Nginx+Tomcat实现高可用Web集群如何用Keepalived+Nginx+Tomcat实现高可用Web集群May 19, 2023 am 10:01 AM

keepalived+nginx+tomcat实现高可用web集群一、nginx的安装过程1.下载nginx安装包,安装依赖环境包(1)安装c++编译环境yum-yinstallgcc#c++(2)安装pcreyum-yinstallpcre-devel(3)安装zlibyum-yinstallzlib-devel(4)安装nginx定位到nginx解压文件位置,执行编译安装命令[root@localhostnginx-1.12.2]#pwd/usr/local/nginx/nginx-1.12

深入了解Spring框架的架构与工作原理深入了解Spring框架的架构与工作原理Jan 24, 2024 am 09:41 AM

深入剖析Spring框架的架构与工作原理引言:Spring是Java生态系统中最受欢迎的开源框架之一,它不仅提供了一套强大的容器管理和依赖注入功能,还提供了许多其他功能,如事务管理、AOP、数据访问等。本文将深入剖析Spring框架的架构与工作原理,并通过具体的代码示例来解释相关概念。一、Spring框架的核心概念1.1IoC(控制反转)Spring的核心

计算机按工作原理可分为什么计算机按工作原理可分为什么Dec 07, 2020 am 10:24 AM

计算机按工作原理可分为数字计算机和模拟计算机。数字式电子计算机是当今世界电子计算机行业中的主流,其内部处理的是一种称为符号信号或数字信号的电信号,它有着运算速度快、运算精度高、通用性强等特点。模拟计算机是根据相似原理,用一种连续变化的模拟量作为被运算的对象的计算机;模拟计算机以电子线路构成基本运算部件。

交换机的工作原理是什么交换机的工作原理是什么Dec 26, 2023 am 11:56 AM

交换机的工作原理包括:1、数据帧接收和解析;2、转发表的更新;3、数据帧的转发;4、泛洪处理;5、维护连接。详细介绍:1、数据帧接收和解析,当交换机接收到一个数据帧时,它会首先对数据帧进行解析,提取出其中的源MAC地址和目的MAC地址等信息;2、转发表的更新,交换机内部维护着一个转发表,这个表记录了MAC地址与接口的对应关系;3、数据帧的转发等等。

nginx+keepalived高可用主从配置的方法nginx+keepalived高可用主从配置的方法May 29, 2023 pm 02:16 PM

一、系统环境及软件版本centos6.6x64keepalived-1.2.18.tar.gznginx-1.6.2.tar.gz主服务器:192.168.38.64从服务器:192.168.38.66vip:192.168.38.100二、nginx安装(主从安装一致)1.安装依赖环境复制代码代码如下:yuminstallgccgcc-c++makeautomakeautoconflibtoolpcrepcre-develzlibzlib-developensslopenssl-devel2.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.