无法使用jedis连接redis哨兵

Man*_*ena 2 redis redis-sentinel

我正在尝试使用 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;
}
Run Code Online (Sandbox Code Playgroud)

这给了我以下错误:

导致:redis.clients.jedis.exceptions.JedisConnectionException:所有哨兵都已关闭,无法确定 mymaster master 正在哪里运行...

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

./redis-cli -h redis-1 -p 26379
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

无法连接到位于 redis-1:26379 的 Redis:提供了节点名或服务名,或未知

这里有什么问题呢?

sof*_*amp 5

使用 localhost 而不是 127.0.0.1 对我有用。

默认情况下,无法从 localhost 以外的接口访问 Sentinel,可以使用“bind”指令绑定到网络接口列表,或者通过将“protected-mode no”添加到此配置文件来禁用保护模式。