HAProxy advanced Redis health check---ref

http://blog.exceliance.fr/2014/01/02/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:

</td>
<td class="code">
<div class="container">
<div class="line number1 index0 alt2"><code class="plain plain">+----+ +----+ +----+ +----+


<div class="line number2 index1 alt1"><code class="plain plain">| W1 | | W2 | | W3 | | W4 |   Web application servers

<div class="line number3 index2 alt2"><code class="plain plain">+----+ +----+ +----+ +----+

<div class="line number4 index3 alt1">
<code class="plain spaces">     <code class="plain plain">\     |   |     /

</td>

</tr></table>

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

</td>
<td class="code">
<div class="container">
<div class="line number1 index0 alt2"><code class="plain plain">defaults REDIS


<div class="line number2 index1 alt1">
<code class="plain spaces"> <code class="plain plain">mode tcp

</td>

</tr></table>

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.

相关文章

文章浏览阅读1.3k次。在 Redis 中,键(Keys)是非常重要的概...
文章浏览阅读3.3k次,点赞44次,收藏88次。本篇是对单节点的...
文章浏览阅读8.4k次,点赞8次,收藏18次。Spring Boot 整合R...
文章浏览阅读978次,点赞25次,收藏21次。在Centos上安装Red...
文章浏览阅读1.2k次,点赞21次,收藏22次。Docker-Compose部...
文章浏览阅读2.2k次,点赞59次,收藏38次。合理的JedisPool资...