简体   繁体   English

用于Redis奴隶的HAproxy

[英]HAproxy for redis slaves

We are using node_redis client to access the redis at present. 目前,我们正在使用node_redis客户端访问redis。 I need to use HAProxy in front of redis slaves which in my case is 3 nos. 我需要在redis奴隶前面使用HAProxy,在我的情况下是3个。 I installed the HAProxy and configured it to load balance the redis slaves. 我安装了HAProxy并将其配置为平衡Redis从站的负载。 But when I tried to create connection from the node_redis client to the HAProxy I was not able to create the connection and was getting a error 但是,当我尝试创建从node_redis客户端到HAProxy的连接时,我无法创建连接,并且出现错误

   Error: Redis reply parser error: Error: Protocol error, got "H" as reply type byte
at HiredisReplyParser.execute (/home/user1/doosra/node-exp/node_modules/redis/lib/parser/hiredis.js:32:31)
at RedisClient.on_data (/home/user1/doosra/node-exp/node_modules/redis/index.js:440:27)
at Socket.<anonymous> (/home/user1/doosra/node-exp/node_modules/redis/index.js:70:14)
at Socket.emit (events.js:67:17)
at TCP.onread (net.js:347:14)

Posting the haproxy configuration would have helped ... 发布haproxy配置会有所帮助...

The most likely explanation is haproxy is not configured to process generic TCP traffic but HTTP traffic. 最可能的解释是haproxy未配置为处理通用TCP通信,而是HTTP通信。

Example: 例:

With the following configuration: 使用以下配置:

global
    daemon
    maxconn 256

defaults
    mode http
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms

frontend redis
    bind *:1521
    default_backend servers

backend servers
    server R1 127.0.0.1:6379 maxconn 1000

and the following node.js script: 以及以下node.js脚本:

var redis = require('redis')
var redis_client = redis.createClient(1521, 'localhost');
redis_client.get( 'key', function(e,o) {
    console.log("return "+e+o);
});

... we get the same exact error: ...我们得到相同的确切错误:

Error: Redis reply parser error: Error: Protocol error, got "H" as reply type byte

It is expected, because the Redis protocol parser does not understand HTTP. 可以预期,因为Redis协议解析器不理解HTTP。 To fix it, just alter the haproxy configuration to enforce a generic TCP mode: 要解决此问题,只需更改haproxy配置以强制使用通用TCP模式:

    mode http

to be changed into:

    mode tcp

... and now it works fine. ...现在工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM