http://blog.exceliance.fr/2014/01/02/haproxy-advanced-redis-health-check/

HAProxy advanced Redis health check

Introduction

Redis is an opensource nosql database working on a key/value model.
One interesting feature in Redis is that it is able to write data to disk as well as a master can synchronize many slaves.

HAProxy can load-balance Redis servers with no issues at all.
There is even a built-in health check for redis in HAProxy.
Unfortunately, there was no easy way for HAProxy to detect the status of a redis server: master or slave node. Hence people usually hacks this part of the architecture.

As written in the title of this post, we’ll learn today how to make a simple Redisinfrastructure thanks to newest HAProxy advanced send/expect health checks.
This feature is available in HAProxy 1.5-dev20 and above.

Purpose is to make the redis infrastructure as simple as possible and ease fail over for the web servers. HAProxy will have to detect which node is MASTER and route all the connection to it.

Redis high availability diagram with HAProxy

Below, an ascii art diagram of HAProxy load-balancing Redis servers:

1
2
3
4
5
6
7
8
9
10
11
12
13
+----+ +----+ +----+ +----+
| W1 | | W2 | | W3 | | W4 |   Web application servers
+----+ +----+ +----+ +----+
     \     |   |     /
      \    |   |    /
       \   |   |   /
        +---------+
        | HAProxy |
        +---------+
           /   \
       +----+ +----+
       | R1 | | R2 |           Redis servers
       +----+ +----+

The scenario is simple:
  * 4 web application servers need to store and retrieve data to/from a Redis database
  * one (better using 2) HAProxy servers which load-balance redis connections
  * 2 (at least) redis servers in an active/standby mode with replication

Configuration

Below, is the HAProxy configuration for the

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
defaults REDIS
 mode tcp
 timeout connect  4s
 timeout server  30s
 timeout client  30s
 
frontend ft_redis
 bind 10.0.0.1:6379 name redis
 default_backend bk_redis
 
backend bk_redis
 option tcp-check
 tcp-check send PING\r\n
 tcp-check expect string +PONG
 tcp-check send info\ replication\r\n
 tcp-check expect string role:master
 tcp-check send QUIT\r\n
 tcp-check expect string +OK
 server R1 10.0.0.11:6379 check inter 1s
 server R2 10.0.0.12:6379 check inter 1s

The HAProxy health check sequence above allows to consider the Redis master server as UP in the farm and redirect connections to it.
When the Redis master server fails, the remaining nodes elect a new one. HAProxy will detect it thanks to its health check sequence.

It does not require third party tools and make fail over transparent.

HAProxy advanced Redis health check---ref的更多相关文章

  1. 项目启动报错:Redis health check failed

    最近是重新开发整个项目,在上线测试的时候发现这个问题. 项目环境:SpringBoot2.x+Consul+Redission+Maven 报错的信息如下: o.s.b.a.redis.RedisHe ...

  2. 转 安装EBS前期检查工具 - RDA - Health Check / Validation Engine Guide

    http://blog.itpub.net/35489/viewspace-1295028/ 参考文档        RDA - Health Check / Validation Engine Gu ...

  3. Docker容器和K8s添加Health Check

    docker容器启动后,怎么确认容器运行正常,怎么确认可以对外提供服务了,这就需要health check功能了. 之前对health check的功能不在意,因为只要镜像跑起来了就是健康的,如果有问 ...

  4. Health Check in eShop -- 解析微软微服务架构Demo(五)

    引言 What is the Health Check Health Check(健康状态检查)不仅是对自己应用程序内部检测各个项目之间的健康状态(各项目的运行情况.项目之间的连接情况等),还包括了应 ...

  5. 如何配置 Health Check?- 每天5分钟玩转 Docker 容器技术(107)

    容器状态是 UP 的,应用就是健康的吗? 还真不一定!Docker 只能从容器启动进程的返回代码判断其状态,而对于容器内部应用的运行情况基本没有了解. 执行 docker run 命令时,通常会根据 ...

  6. Health Check - 每天5分钟玩转 Docker 容器技术(142)

    强大的自愈能力是 Kubernetes 这类容器编排引擎的一个重要特性.自愈的默认实现方式是自动重启发生故障的容器.除此之外,用户还可以利用 Liveness 和 Readiness 探测机制设置更精 ...

  7. 在 Scale Up 中使用 Health Check - 每天5分钟玩转 Docker 容器技术(145)

    对于多副本应用,当执行 Scale Up 操作时,新副本会作为 backend 被添加到 Service 的负责均衡中,与已有副本一起处理客户的请求.考虑到应用启动通常都需要一个准备阶段,比如加载缓存 ...

  8. 在 Rolling Update 中使用 Health Check - 每天5分钟玩转 Docker 容器技术(146)

    上一节讨论了 Health Check 在 Scale Up 中的应用,Health Check 另一个重要的应用场景是 Rolling Update.试想一下下面的情况: 现有一个正常运行的多副本应 ...

  9. centos7下安装docker(26如何配置Health Check)

    Docker只能从容器启动进程的返回代码判断其状态,而对于容器内部应用的运行状况基本没有了解 执行docker run命令时,通常根据dockerfile中的CMD或ENTRYPOINT启动一个进程, ...

随机推荐

  1. WinForm中DataGridView的使用(六) - 特殊处理的小地方

    列标题不能居中的解决方法 一般列标题的居中我们都使用this.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignmen ...

  2. 第十二篇 os模块

    Python的os模块提供了系统相关,目录,文件操作,执行命令等操作. 1.文件和目录操作相关的方法: 方法 说明 os.mkdir 创建目录 os.rmdir 删除目录 os.rename 重命名 ...

  3. 题解 P1876 【开灯】

    题目链接 编者说得对 一道很明显的数学题,相信大家小学都做过. 通俗一点,就是找因数为奇数个的数.而这一类的数.明显的是平方数. 所以就是找n以内的平方数. 废话少说,直接上题解. #include& ...

  4. vmware vSphere虚拟网络之标准交换机(二)

    一.标准交换机的特点: 1)只能用于物理主机 2)其他主机不能共享同一个虚拟交换机 3)不具备任何灵活性 4)每台ESXi主机都要配置一遍 二.网络图: 三.创建标准交换机: 登录web vCente ...

  5. Jenkins持续集成企业实战系列之两种网站部署的流程-----01

    注:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.    最初接触Jenkins也是由于公司需求,根据公司需求Java代码项目升级的.(公司是 ...

  6. 通用动态树(Link-Cut Tree)模板

    一个没有维护任何东西的动态树模板 忘了怎么写可以直接来粘 int ch[300010][2], fa[300010], st[300010]; bool lazy[300010]; bool nroo ...

  7. JS 节点的属性 与 元素

    节点的属性{     nodeType 是节点的类型:     nodeNam 是节点的名字     nodeValue 节点的值 }可以用节点.属性 取得三个属性的值 节点.nodeType 出来的 ...

  8. 洛谷P2800 又上锁妖塔

    放题解 题目传送门 放代码

  9. PHP 备份还原 MySql 数据库

    原生 PHP 备份还原 MySql 数据库 支持 MySql,PDO 两种方式备份还原 php5.5 以上的版本建议开启pdo扩展,使用 pdo 备份还原数据 备份文件夹 db_backup.impo ...

  10. mfix mpi并行死锁问题探究

    目前还没找到具体原因,只能先记录一下.(问题原因找到了) 分别用ubuntu14.04和ubuntu16.04测试,用的是笔记本,笔记本为双核四线程,用2线程并行计算:发现ubuntu16.04会在0 ...