当前位置: 首页 > news >正文

keepalived which time exec track script , notify script when vrrp transition

keepalived什么时候调用track script, track interface, notify_* script, notify; 搞清楚这些对设计HA很有必要.
以下这张图大概的画出了跟踪脚本, 跟踪接口, 状态转换, 以及notify脚本的先后关系 : 
当然实际的程序设计和这个没有关系, keepalived是3个进程组成的, 主进程, vrrp进程和health_check进程. 这里不作体现.


keepalived which time exec track script , notify script when vrrp transition - 德哥@Digoal - PostgreSQL research
 
keepalived.conf配置项 : 
跟踪脚本或跟踪接口配置 :
    track_interface {                   # Interfaces state we monitor
      <STRING>
      <STRING>
      <STRING> weight <INTEGER:-254..254>
      ...
    }
    track_script {                     # Scripts state we monitor
      <STRING>
      <STRING> weight <INTEGER:-254..254>
      ...
    }
    dont_track_primary                  # (default unset) ignore VRRP interface faults.
                                        #  useful for cross-connect VRRP config.

When a weight is specified in track_interface, instead of setting the vrrp
instance to the FAULT state in case of failure, its priority will be
increased by the weight when the interface is up (for positive weights),
or decreased by the weight's absolute value when the interface is down
(for negative weights). The weight must be comprised between -254 and +254
inclusive. 0 is the default behaviour which means that a failure implies a
FAULT state. The common practise is to use positive weights to count a
limited number of good services so that the server with the highest count
becomes master. Negative weights are better to count unexpected failures
among a high number of interfaces, as it will not saturate even with high
number of interfaces.

The same principle can be applied to track_script entries, except that an
unspecified weight means that the default weight declared in the script
will be used.


进入状态后的notify脚本配置 : 
vrrp_sync_group <STRING> {      # VRRP sync group declaration
    group {                     # group of instance to sync together
      <STRING>                  #   a
      <STRING>                  #       set
      ...                       #             of VRRP_Instance string
    }
    notify_master <STRING>|<QUOTED-STRING> # Script to run during MASTER transit
    notify_backup <STRING>|<QUOTED-STRING> # Script to run during BACKUP transit
    notify_fault <STRING>|<QUOTED-STRING>  # Script to run during FAULT transit
    notify <STRING>|<QUOTED-STRING>        # Script to run during ANY state transit (1)
    smtp_alert           # Send email notif during state transit
}

(1) The "notify" script is called AFTER the corresponding notify_* script has
    been called, and is given exactly 4 arguments (the whole string is interpreted
    as a litteral filename so don't add parameters!):

    $1 = A string indicating whether it's a "GROUP" or an "INSTANCE"
    $2 = The name of said group or instance
    $3 = The state it's transitioning to ("MASTER", "BACKUP" or "FAULT")
    $4 = The priority value

    $1 and $3 are ALWAYS sent in uppercase, and the possible strings sent are the
    same ones listed above ("GROUP"/"INSTANCE", "MASTER"/"BACKUP"/"FAULT").

Important: for a SYNC group to run reliably, it is vital that all instances in
           the group are MASTER or that they are all either BACKUP or FAULT. A
           situation with half instances having higher priority on machine A
           half others with higher priority on machine B will lead to constant
           re-elections. For this reason, when instances are grouped, their
           tracking weights are automatically set to zero, in order to avoid
           inconsistent priorities across instances.

notify也可以直接配置在instance下.
    notify_master <STRING>|<QUOTED-STRING>      # Same as vrrp_sync_group
    notify_backup <STRING>|<QUOTED-STRING>      # Same as vrrp_sync_group
    notify_fault <STRING>|<QUOTED-STRING>       # Same as vrrp_sync_group
    notify_stop <STRING>|<QUOTED-STRING>        # Script to launch when stopping vrrp
    notify <STRING>|<QUOTED-STRING>             # Same as vrrp_sync_group


notify是在进入状态后调用的, 也就是Entering后. 截取几段代码 : 
vrrp_scheduler.c

                        log_message(LOG_INFO, "VRRP_Instance(%s) Entering BACKUP STATE",
                               vrrp->iname);

                        /* Set BACKUP state */
                        vrrp_restore_interface(vrrp, 0);
                        vrrp->state = VRRP_STATE_BACK;
                        vrrp_smtp_notifier(vrrp);
                        notify_instance_exec(vrrp, VRRP_STATE_BACK);
............
                                log_message(LOG_INFO, "VRRP_Instance(%s) Entering BACKUP STATE",
                                       vrrp->iname);
                                vrrp->state = VRRP_STATE_BACK;
                                vrrp_smtp_notifier(vrrp);
                                notify_instance_exec(vrrp, VRRP_STATE_BACK);
................
        if (!VRRP_ISUP(vrrp)) {
                vrrp_log_int_down(vrrp);
                log_message(LOG_INFO, "VRRP_Instance(%s) Now in FAULT state",
                       vrrp->iname);
                if (vrrp->state != VRRP_STATE_FAULT)
                        notify_instance_exec(vrrp, VRRP_STATE_FAULT);
                vrrp->state = VRRP_STATE_FAULT;
                vrrp->ms_down_timer = 3 * vrrp->adver_int + VRRP_TIMER_SKEW(vrrp);
                notify_instance_exec(vrrp, VRRP_STATE_FAULT);


[参考]
1. keepalived/vrrp/vrrp_scheduler.c
2.  keepalived/vrrp/ vrrp_notify.c
3.  http://blog.163.com/digoal@126/blog/static/163877040201472531649584/
4.  http://blog.163.com/digoal@126/blog/static/163877040201472511507986/

相关文章:

  • 代理模式
  • java aopalliance-1.0.jar这个包是做什么用的?
  • Android客户端采用Http 协议Post方式请求与服务端进行数据交互(转)
  • Distributed3:SQL Server 创建分布式数据库
  • C#-属性
  • 2的幂的合并运算实例
  • 【curl】cookie的分隔符
  • 从零开始学数据库(一)——安装、启动、进入、创建表、检查表结构、类型说明、更改表项名、插入值...
  • Ruby之基本数据类型(三)
  • 机器学习:eclipse中调用weka的Classifier分类器代码Demo
  • 线程同步工具(一)控制并发访问资源
  • Solr schema编写指导
  • Azkaban的Web Server源码探究系列14:创建Project
  • 成都Uber优步司机奖励政策(4月11日)
  • Tomcat6.0数据源配置
  • 《Java8实战》-第四章读书笔记(引入流Stream)
  • 30秒的PHP代码片段(1)数组 - Array
  • CSS 提示工具(Tooltip)
  • Golang-长连接-状态推送
  • JavaScript 基础知识 - 入门篇(一)
  • JavaScript函数式编程(一)
  • Joomla 2.x, 3.x useful code cheatsheet
  • jQuery(一)
  • Laravel5.4 Queues队列学习
  • Leetcode 27 Remove Element
  • Material Design
  • Puppeteer:浏览器控制器
  • Quartz实现数据同步 | 从0开始构建SpringCloud微服务(3)
  • Vue UI框架库开发介绍
  • vue--为什么data属性必须是一个函数
  • 干货 | 以太坊Mist负责人教你建立无服务器应用
  • 猴子数据域名防封接口降低小说被封的风险
  • 技术:超级实用的电脑小技巧
  • 看图轻松理解数据结构与算法系列(基于数组的栈)
  • 利用阿里云 OSS 搭建私有 Docker 仓库
  • 每个JavaScript开发人员应阅读的书【1】 - JavaScript: The Good Parts
  • 区块链分支循环
  • 使用 Xcode 的 Target 区分开发和生产环境
  • 一加3T解锁OEM、刷入TWRP、第三方ROM以及ROOT
  • 直播平台建设千万不要忘记流媒体服务器的存在 ...
  • ​​​​​​​Installing ROS on the Raspberry Pi
  • ​【C语言】长篇详解,字符系列篇3-----strstr,strtok,strerror字符串函数的使用【图文详解​】
  • #Lua:Lua调用C++生成的DLL库
  • #pragma multi_compile #pragma shader_feature
  • $(selector).each()和$.each()的区别
  • (007)XHTML文档之标题——h1~h6
  • (HAL库版)freeRTOS移植STMF103
  • (pytorch进阶之路)扩散概率模型
  • (Redis使用系列) Springboot 在redis中使用BloomFilter布隆过滤器机制 六
  • (第61天)多租户架构(CDB/PDB)
  • (续)使用Django搭建一个完整的项目(Centos7+Nginx)
  • (学习日记)2024.03.25:UCOSIII第二十二节:系统启动流程详解
  • (一)Linux+Windows下安装ffmpeg
  • (一)pytest自动化测试框架之生成测试报告(mac系统)
  • (一)为什么要选择C++