Redis Clusterクラスタリモートアクセス(SpringBoot 2.0)
6351 ワード
1.RedisDesktopManagerはクラスタアクセスをサポートしていません
2.FastoRedisはクラスタアクセス方式をサポートする
3.spirngboot2.0 redisクラスタの接続
テスト中に
クラスタに統一パスワードを設定し、パスワード付きでアクセスすることもできます.https://www.cnblogs.com/linjiqin/p/7462822.html
2.FastoRedisはクラスタアクセス方式をサポートする
3.spirngboot2.0 redisクラスタの接続
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-data-redisartifactId>
dependency>
<dependency>
<groupId>redis.clientsgroupId>
<artifactId>jedisartifactId>
dependency>
# yml
spring:
redis:
# jedis
jedis:
pool:
#
max-active: 8
#
max-idle: 8
#
min-idle: 0
# ,
max-wait: -1
password:
# ,
timeout: 50000
#
maxAttempts: 5
cluster:
nodes: 192.168.3.8:6380,192.168.3.8:6381,192.168.3.8:6382,192.168.3.8:6383,192.168.3.8:6384,192.168.3.8:6385
@Configuration
@ConditionalOnClass({JedisCluster.class})
public class RedisConfig {
@Value("${spring.redis.cluster.nodes}")
private String clusterNodes;
@Value("${spring.redis.timeout}")
private int timeout;
@Value("${spring.redis.jedis.pool.max-idle}")
private int maxIdle;
@Value("${spring.redis.jedis.pool.max-wait}")
private long maxWaitMillis;
@Value("${spring.redis.maxAttempts}")
private int maxAttempts;
@Value("${spring.redis.password}")
private String password;
@Bean
public JedisCluster getJedisCluster() {
String[] cNodes = clusterNodes.split(",");
Set nodes = new HashSet();
//
for (String node : cNodes) {
String[] hp = node.split(":");
nodes.add(new HostAndPort(hp[0], Integer.parseInt(hp[1])));
}
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxIdle(maxIdle);
jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);
//
JedisCluster jedisCluster = new JedisCluster(nodes, timeout, timeout, maxAttempts, jedisPoolConfig);
return jedisCluster;
}
}
テスト中に
Could not get a resource from the pool
が現れたのは、以前クラスタを作ったときに127.0.0.1アドレスを使用していたため、実際にipアドレスにアクセスできるように変更する必要があるからです. nodes.conf , , ip
./redis-trib.rb create --replicas 1 192.168.3.8:6380 192.168.3.8:6381 192.168.3.8:6382 192.168.3.8:6383 192.168.3.8:6384 192.168.3.8:6385
試験OK~クラスタに統一パスワードを設定し、パスワード付きでアクセスすることもできます.https://www.cnblogs.com/linjiqin/p/7462822.html