首页 > 技术文章 > 高性能集群软件keepalived

songgj 2018-05-30 23:16 原文

 Keepalived介绍


     以下是keepalive官网上的介绍。官方站点为http://www.keepalived.org

        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 to Linux 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.

 

   Keepalived其实是Linux环境中一个轻量级的高可用解决方案,刚开始是专门为LVS负载均衡软件设计的,用来管理并监控LVS集群系统中各个服务节点的状态,后来又加入了可以实现高可用的VRRP功能。它与HeartBeat、功能类似,可以实现服务或者网络的高可用(High Availability),但是又有差别,HeartBeat是一个专业的、功能完善的高可用软件,它提供了HA软件所需的基本功能,比如心跳检测和资源接管,监测集群中的系统服务,在群集节点间转移共享IP地址的所有者等,HeartBeat 功能强大,但是部署和使用相对比较麻烦。与HearBeat相比,Keepalived 主要是通过虚拟路由冗余来实现高可用功能,Keepalived部署和使用非常简单,所有配置只需一个配置文件即可完成。

     Keepalived是通过VRRP(Virtual Router Redundancy Protocol:虚拟路由器冗余协议)协议来实现高可用功能,它可以解决静态路由出现的单点故障问题,实现网络不间断稳定运行,因此还可以作为其他服务(例如:Nginx、Haproxy、MySQL等)的高可用解决方案。

 

Keepalived的作用


     Keepalived的作用是定时检测服务器的状态,如果有一台服务器宕机或出现故障,Keepalived将检测到,并将有故障的服务器从系统中剔除,同时使用其他服务器代替该服务器的工作,当服务器工作正常后Keepalived自动将服务器加入到服务器群中,这些工作全部自动切换完成。所以keepalive不仅具有服务器状态检查功能和故障隔离功能,同时也具有高可靠性服务器集群(HA cluster)功能。

 

VRRP协议与工作原理

   VRRP(Virtual Router Redundancy Protocol),虚拟路由冗余协议。

     在现实的网络环境中,主机之间的通信都是通过配置静态路由(默认网关)完成的,有主机之间的路由器一旦出现故障, 通信就会失败,因此,在这种通信模式中,路由器就成了一个单点瓶预,为了解决这个问题,就引入了VRRP协议。

    VRRP协议是种主备模式的协议,通过VRRP可以在网络发生故障时透明地进行设备切换而不会影响主机间的数据通信,这其中涉及两个概念:物理路由器虚拟路由器

    VRRP可以将两台或多台物理路由器设备虚拟成一个虚拟路由器,这个虚拟路由器通过虚拟IP(-个或多个)对外提供服务,面在虚拟路由器内部是多个物理路由器协网工作,同一时间只有台物理路由器对外提供服务, 这台物理路由器被称为主路由器(处于MASTER角色)。般情况下MASTER由选举算法产生, 它拥有对外服务的虚拟IP,提供各种网络功能,如ARP请求、ICMP、数据转发等。而其他物理路由器不拥有对外的虚拟P,也不提供对外网络功能,仅仅接收MASTER的VRRP状态通告信息,这些路由器被统称为备份路由器(处F BACKUP角色)。当主路由器失效时,处于BACKUP角色的备份路由器将重新进行选举,产生一个新的主路由器进人MASTER角色继续提供对外服务,整个切换过程对用户来说完全透明

   VRRP协议是keepalived实现的基础。

推荐阅读