那些年踩过的坑之Redis报错:All sentinels down, cannot determine where is mymaster master is running...

1. 异常信息: All sentinels down, cannot determine where is mymaster master is running...

经过测试:html

   @Test public void testSentinel(){ HashSet<String> sentinels = new HashSet<>(); sentinels.add("192.168.72.129:26379"); JedisSentinelPool pool = new JedisSentinelPool("mymaster", sentinels); Jedis jedis = pool.getResource(); jedis.set("hello", "world"); System.out.println(jedis.get("hello")); }

报出错误:linux

警告: Cannot get master address from sentinel running @ 192.168.72.129:26379. 
Reason: redis.clients.jedis.exceptions.JedisConnectionException:
Failed connecting to host 192.168.72.129:26379. Trying next one. redis.clients.jedis.exceptions.JedisConnectionException:
All sentinels down, cannot determine where is mymaster master is running...
(哨兵宕机, 不能肯定主机位置)

还原报错现场:redis

  学习搭配redis过程当中, 在linux虚拟机上配置完redis-sentinel( 即启用redis哨兵配置搭建1主2从的redis服务器 )服务器

  开启了redis-sentinel服务, ip和port号为: 192.168.72.129:26379学习

  首先, 能肯定的是, linux防火墙已然关闭, sentinel.conf 的配置中, (注释掉bind)开放了不一样主机的访问, 同时, redis的保护模式也已经关闭!!!测试

可是jedis链接仍是出现了问题, 那么既然不是redis服务器方配置或者防御的问题, 那么问题只能出在了个人操做系统win7中!!!spa

  在此基础上猜想, 是不是ip 链接 或者 是端口未开放呢?操作系统

  因而经过如下操做:3d

  cmd ->code

  telnet 192.168.72.129:26379 

  显示错误: 正在链接192.168.72.129:26379...没法打开到主机的链接。 在端口 23: 链接失败

 ------- 附win7中开启telnet的方法: 站内他人博文连接:https://www.cnblogs.com/ylcms/p/7250129.html, 博主:云龙笔记

  看样子应该是linux的端口未开放致使没法链接.

  继续, 查看linux服务端:

  经过 netstat 查看与26379相关的端口信息, 查询到:

  怎么回事? 端口好好地, 已经被redis服务监听了!!!

  哎, 这时脑壳升起一丝不详的感受, 难道是个人主从redis都没有启动, 而我直接加载了哨兵的配置吗?

 

  哇的一声哭了出来, 忙活了这么久, 竟然是我并无启动主从机. 致使了这一系列bug!!!!

  开启, 而后跑一下测试类, 再看看结果, 以下

  

  链接正常...

  虽然致使bug的问题如此"脑残", 不过从这过程之中, 我也对redis的分片, 乃至哨兵有了一个全面的认识, 算是祸福相依啦. 若是你也有链接redis的错误, 不妨跟个人思路来思考, 相信不难解决!

---记录2019年7月29日12:31:11 

相关文章
相关标签/搜索