HAProxy advanced Redis health checkref

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

HAProxy advanced Redis health check

Posted on  by Baptiste Assmann

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.

更多相关文章
一周排行
  • 刚开始把数据库的密码搞错了,硬是连不上... //数据库连接类 SqlConnection conn = new SqlConnection("server=.;database=test;user=sa; ...
  • Backup 进入安装文件目录cd anyconnect-3.1.00495/binary 安装sudo./vpnsetup.sh 查看安装情况ps aux    grep  cisco 在搜索中,输入vpn即可以找
  • 摘要:64位操作系统部署.NET 程序访问oracle时,无法连接问题.(注意:客户端是64位系统 ,服务端是否64位 还是32位无关.)   1.到oracle 官网搜索相关版本的 ODAC网址: http://w
  • iBatis(MyBatis)开启缓存后,通过外部程序修改或者删除数据库记录,如何让Cache清除?5 当其外部的数据库连接甚至是数据库管理系统,对数据库进行了更改,iBatis(MyBatis)的缓存如果没有过期, ...
  • .lt.或 < .le.或 <= .eq.或== .ne.或/= .gt.或> .ge.或>=   逻辑表达式 a.and.b  a.or.c     .not. a a.xor.b  异或 ...
  • 


    		    域狀態備份ntds 2089錯誤分析
    NTDS Replication: Warning: 2089:Backup :This ...
  • Codeforces 486E LIS of Sequence 樹狀數組求LIS
    题意: 一个序列可能有多个最长子序列,现在问每个元素是以下三个种类的哪一类: 1.不属于任
  • 極角排序、掃描線UVa 1606
    Shanghai Hypercomputers, the world's largest
  • 1. Block Change Tracking 启用块修改跟踪特性,0级的增量备份肯定还得扫描所有数据文件,不过其后依赖这一0级备份集创建的增量备份就可以通过块修改跟踪文件来获取修改过的块了. 修改跟踪文件是基于整
  • 


    		    CCNP學習之路之EtherChannel以太網通道、鏈路聚合
    什么是EtherChannel 交换机S1, S2之间有两条链路相连,如果捆綁在一起,成为