无法使用jedis连接redis sentinel

Unable to connect redis sentinel using jedis

我正在尝试使用 JedisSentinelPool 连接到 redis sentinel

private static final JedisSentinelPool pool = new JedisSentinelPool("mymaster", getSentinels());

private static Set<String> getSentinels(){

    Set<String> mysentinels = new HashSet<>();
    mysentinels.add(new HostAndPort("localhost", 26379).toString());
    return mysentinels;
}

这给了我以下错误:

Caused by: redis.clients.jedis.exceptions.JedisConnectionException: All sentinels down, cannot determine where is mymaster master is running...

不过,我可以看到我的哨兵是运行。所以参考这个post: https://github.com/luin/ioredis/issues/64 我在我的 redis 主服务器上尝试了以下命令

./redis-cli -h redis-1 -p 26379

我收到以下错误:

Could not connect to Redis at redis-1:26379: nodename nor servname provided, or not known

这里有什么问题?

确保 protected-modesentinel.conf 文件中设置为 no。这为我解决了问题。

使用 localhost 而不是 127.0.0.1 适合我。

By default Sentinel will not be reachable from interfaces different than localhost, either use the 'bind' directive to bind to a list of network interfaces, or disable protected mode with "protected-mode no" by adding it to this configuration file.