redis哨兵整合springboot问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yueloveme/article/details/87949602

大家推荐个靠谱的公众号程序员探索之路,大家一起加油 https://img-blog.csdnimg.cn/20181129224604602.png

整合redis哨兵模式时会遇到几个问题

1.不能连接192.168.199.171:26379地址

2.DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified

也就是不能连接受保护的redis

解决:

1.明明配置的时127.0.0.1:26379怎么会变成192.168.199.171:26379       192.168.199.171貌似时本机ip

那只能说明代码处理了

public static HostAndPort parseString(String from){
  // NOTE: redis answers with
  // '99aa9999aa9a99aa099aaa990aa99a09aa9a9999 9a09:9a9:a090:9a::99a slave 8c88888888cc08088cc8c8c888c88c8888c88cc8 0 1468251272993 37 connected'
  // for CLUSTER NODES, ASK and MOVED scenarios. That's why there is no possibility to parse address in 'correct' way.
  // Redis should switch to 'bracketized' (RFC 3986) IPv6 address.
  try {
    String[] parts = extractParts(from);
    String host = parts[0];
    int port = Integer.valueOf(parts[1]);
    return new HostAndPort(convertHost(host), port);
  } catch (NumberFormatException ex) {
    throw new IllegalArgumentException(ex);
  }
}
public static String convertHost(String host) {
  if (host.equals("127.0.0.1") || host.startsWith("localhost") || host.equals("0.0.0.0") ||
      host.startsWith("169.254") ||
      host.startsWith("::1") || host.startsWith("0:0:0:0:0:0:0:1")) {
    return LOCALHOST_STR;
  } else {
    return host;
  }
}

上面两个方法明显的显示改掉了127.0.0.1  LOCALHOST_STR = 192.168.199.171

2.不能连接受保护的redis 这个问题是由于redis3.2以后的新特性

protected-mode yes  如果这样配置只允许 127.0.0.1 和 localhost访问

测试项目:https://github.com/ZhZGod/redis-study.git

猜你喜欢

转载自blog.csdn.net/yueloveme/article/details/87949602
今日推荐