我正在尝试使用ioredis连接到docker下的我的哨兵服务,这需要在我的配置中输入密码。 这是我的代码:
sentinels: [
{ host: "192.168.0.35", port: 26379 }
],
name: "redismaster",
sentinelPassword: "sentinelPassword",
sentinelRetryStrategy: function(times) {
// reconnect after
return Math.max(times * 100, 3000);
}
});
但是它不会成功。这是激活DEBUG = ioredis时的日志:
2020-02-07T18:06:10.091Z ioredis:redis status[192.168.0.35:26379]: [empty] -> connecting
2020-02-07T18:06:10.093Z ioredis:redis queue command[192.168.0.35:26379]: 0 -> sentinel([ 'get-master-addr-by-name', 'redismaster' ])
2020-02-07T18:06:10.096Z ioredis:redis status[192.168.0.35:26379]: connecting -> connect
2020-02-07T18:06:10.097Z ioredis:redis write command[192.168.0.35:26379]: 0 -> auth([ 'thisis1SentinElP@sSwOrd' ])
2020-02-07T18:06:10.097Z ioredis:redis status[192.168.0.35:26379]: connect -> ready
2020-02-07T18:06:10.097Z ioredis:connection send 1 commands in offline queue
2020-02-07T18:06:10.098Z ioredis:redis write command[192.168.0.35:26379]: 0 -> sentinel([ 'get-master-addr-by-name', 'redismaster' ])
2020-02-07T18:06:10.100Z ioredis:redis write command[192.168.0.35:26379]: 0 -> sentinel([ 'sentinels', 'redismaster' ])
2020-02-07T18:06:10.101Z ioredis:SentinelConnector Updated internal sentinels: [{"host":"192.168.0.35","port":26379}] @1
2020-02-07T18:06:10.102Z ioredis:SentinelConnector resolved: 192.168.0.23:6379
2020-02-07T18:06:10.105Z ioredis:redis status[192.168.0.23:6379]: connecting -> connect
2020-02-07T18:06:10.106Z ioredis:redis write command[192.168.0.23:6379]: 0 -> info([])
Redis connected
2020-02-07T18:06:10.106Z ioredis:redis status[192.168.0.35:26379]: ready -> close
2020-02-07T18:06:10.106Z ioredis:connection skip reconnecting since the connection is manually closed.
2020-02-07T18:06:10.106Z ioredis:redis status[192.168.0.35:26379]: close -> end
Redis error in (/config/redis.js) ReplyError: NOAUTH Authentication required.
根据日志,我看到我的redis客户端可以连接到哨兵,它也可以在哨兵模式下找到真正的redis服务器并选择数据库。我得到了redis已连接的日志,但是此后,连接已关闭。 我在哪里想念?
PS:我确实也添加了snetinel-annouce-ip配置,以防我的Redis客户端无法识别哨兵的IP,但是在日志中,它具有良好的专用IP:192.168.0.35。
感谢您的帮助。
答案 0 :(得分:1)
尝试将密码设置为password
和sentinelPassword
{
sentinels: [
{ host: "192.168.0.35", port: 26379 }
],
name: "redismaster",
password: "yourpassword",
sentinelPassword: "yourpassword"
}