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:
Highlighter_785932" class="
SyntaxHighlighter plain">
</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">\ | | /
dis servers
</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
Highlighter_659405" class="
SyntaxHighlighter plain ">
</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
dis
dis
dis
</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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。