1、测试代码如下:

public static void main(String[] args) {
Set<String> sentinels = new HashSet<String>();
sentinels.add("118.25.7.111:26379");
sentinels.add("118.25.7.111:26380");
sentinels.add("118.25.7.111:26381");
String clusterName = "mymaster";
//此处添加密码
String password = "foo" ;
// 建立连接池配置参数
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxIdle(50);
//设置最小空闲数
config.setMinIdle(8);
config.setMaxWaitMillis(10000);
config.setTestOnBorrow(true);
config.setTestOnReturn(true);
//Idle时进行连接扫描
config.setTestWhileIdle(true);
//表示idle object evitor两次扫描之间要sleep的毫秒数
config.setTimeBetweenEvictionRunsMillis(30000);
//表示idle object evitor每次扫描的最多的对象数
config.setNumTestsPerEvictionRun(10);
//表示一个对象至少停留在idle状态的最短时间,然后才能被idle object evitor扫描并驱逐;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义
config.setMinEvictableIdleTimeMillis(60000);
JedisSentinelPool redisSentinelJedisPool = new JedisSentinelPool(clusterName,sentinels,config,password);
Jedis jedis = null;
try {
jedis = redisSentinelJedisPool.getResource();
jedis.set("key", "aaa");
System.out.println(jedis.get("key"));
System.out.println(jedis.get("bbb"));
} catch (Exception e) {
e.printStackTrace();
} finally {
//redisSentinelJedisPool.returnResource(jedis);
jedis.close();
}
redisSentinelJedisPool.close();
}

问题:

1、-DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

解决:此处是因为sentinel的保护模式开启(默认)导致的,在sentinel对应的配置文件中将其关闭即可,即

#关闭保护模式
protected-mode no

2、redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool

at redis.clients.util.Pool.getResource(Pool.java:53)
at redis.clients.jedis.JedisSentinelPool.getResource(JedisSentinelPool.java:209)
at com.ww.wwta.config.client.RedisClusterClient.main(RedisClusterClient.java:92)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect
at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:889)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:433)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:362)
at redis.clients.util.Pool.getResource(Pool.java:49)
... 2 more

解决:未将对应的主服务的端口加入防火墙,将设置端口加入防火墙即可,即

firewall-cmd --permanent --zone=public --add-port=/tcp
firewall-cmd --reload

查看是否已加入:

firewall-cmd --permanent --zone=public --list-ports

3、连接127.0.0.1:6780连接拒绝

需将sentinel配置sentinel monitor mymaster 127.0.0.1 6380 2 -> sentinel monitor mymaster 118.25.7.111 6380 2

最新文章

  1. [从产品角度学EXCEL 03]-单元格的秘密
  2. 【转】Xcode进阶快捷键
  3. 一种扩大View点击范围的方法
  4. MYSQL调优
  5. Head First 设计模式 --9 迭代器模式 组合模式
  6. JAVA 十六进制与字符串的转换
  7. 斯坦福iOS7公开课4-6笔记及演示Demo
  8. JS获取URL参数 方法
  9. Swift中编写单例的正确方式
  10. Editplus配置java运行环境
  11. Spring系列
  12. (转)js网址验证
  13. 微软 深度学习 cntk ,我目前见过 安装方式最简单的一个框架,2.0之后开始支持C# 咯
  14. xml是什么,为什么要用xml
  15. Android 开发笔记___Activity的生命周期
  16. notepad++代码输出电话号
  17. sqlplus 登录数据库
  18. 实现PHP内部的通知机制,如当一个类的属性发生变化时,另外一个类就可以收到通知
  19. CSS---文档流布局 | 脱标-postion-zindex | 脱标-浮动
  20. windows下用pycharm安装tensorflow简易教程

热门文章

  1. Java-手动搭建SSM(Maven)
  2. k近邻法的实现
  3. JavaScript label语句
  4. CFdiv2 165E. Compatible Numbers 子集枚举
  5. Aizu-2249 Road Construction(dijkstra求最短路)
  6. 牛客小白月赛4 I 合唱队形 思维 字符串
  7. yzoj P1126 塔 题解
  8. poj1037 [CEOI 2002]A decorative fence 题解
  9. 【Offer】[16] 【数值的整数次方】
  10. java路障CyclicBarrier