〇、背景

  已在虚拟机(CentOS 7,在本文也称其为宿主机——即docker容器的宿主机)的docker中搭建好了6个节点的redis (host网络模式)集群:Docker Redis 5.0集群搭建

  现在在本机(Windows 7)以Spring Boot环境连接集群

 

一、异常1:无法连接集群

1.配置:

1 #rediss
2 spring.redis.cluster.nodes=192.168.22.130:7001,192.168.22.130:7002,192.168.22.130:7003,192.168.22.130:7004,192.168.22.130:7005,192.168.22.130:7006
3 spring.redis.timeout=60000
4 spring.redis.jedis.pool.max-wait=-1
5 spring.redis.jedis.pool.max-active=300
6 spring.redis.jedis.pool.max-idle=100
7 spring.redis.jedis.pool.min-idle=20

2.报错:

org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisException: 
Cannot retrieve initial cluster partitions from initial URIs [RedisURI [host='192.168.22.130', port=7001], RedisURI [host='192.168.22.130', port=7002], RedisURI [host='192.168.22.130', port=7003],
RedisURI [host
='192.168.22.130', port=7004], RedisURI [host='192.168.22.130', port=7005], RedisURI [host='192.168.22.130', port=7006]] at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1199)

3.报错具体信息:

2020-02-29 23:30:11.809  WARN 24336 --- [ioEventLoop-4-3] 

i.l.c.c.topology.ClusterTopologyRefresh  : Unable to connect to 

[192.168.22.130:7003]: connection timed out: /192.168.22.130:7003
2020-02-29 23:30:11.809  WARN 24336 --- [ioEventLoop-4-4] 

i.l.c.c.topology.ClusterTopologyRefresh  : Unable to connect to 

[192.168.22.130:7004]: connection timed out: /192.168.22.130:7004
2020-02-29 23:30:11.810  WARN 24336 --- [ioEventLoop-4-2] 

i.l.c.c.topology.ClusterTopologyRefresh  : Unable to connect to 

[192.168.22.130:7002]: connection timed out: /192.168.22.130:7002
2020-02-29 23:30:11.809  WARN 24336 --- [ioEventLoop-4-1] 

i.l.c.c.topology.ClusterTopologyRefresh  : Unable to connect to 

[192.168.22.130:7001]: connection timed out: /192.168.22.130:7001
2020-02-29 23:30:11.824  WARN 24336 --- [ioEventLoop-4-1] 

i.l.c.c.topology.ClusterTopologyRefresh  : Unable to connect to 

[192.168.22.130:7005]: connection timed out: /192.168.22.130:7005
2020-02-29 23:30:11.824  WARN 24336 --- [ioEventLoop-4-2] 

i.l.c.c.topology.ClusterTopologyRefresh  : Unable to connect to 

[192.168.22.130:7006]: connection timed out: /192.168.22.130:7006

org.springframework.data.redis.RedisConnectionFailureException: Unable to 

connect to Redis; nested exception is io.lettuce.core.RedisException: 

Cannot retrieve initial cluster partitions from initial URIs [RedisURI 

[host='192.168.22.130', port=7001], RedisURI [host='192.168.22.130', 

port=7002], RedisURI [host='192.168.22.130', port=7003], RedisURI 

[host='192.168.22.130', port=7004], RedisURI [host='192.168.22.130', 

port=7005], RedisURI [host='192.168.22.130', port=7006]]

    at 

org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory

$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1199)
    at 

org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory

$SharedConnection.getConnection(LettuceConnectionFactory.java:1178)
    at 

org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory

.getClusterConnection(LettuceConnectionFactory.java:372)
    at 

org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory

.getConnection(LettuceConnectionFactory.java:349)
    at 

org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection

(RedisConnectionUtils.java:134)
    at 

org.springframework.data.redis.core.RedisConnectionUtils.getConnection

(RedisConnectionUtils.java:97)
    at 

org.springframework.data.redis.core.RedisConnectionUtils.getConnection

(RedisConnectionUtils.java:84)
    at org.springframework.data.redis.core.RedisTemplate.execute

(RedisTemplate.java:215)
    at org.springframework.data.redis.core.RedisTemplate.execute

(RedisTemplate.java:188)
    at org.springframework.data.redis.core.RedisTemplate.randomKey

(RedisTemplate.java:921)
    at 

com.drajun.rushbuying.RushBuyingApplicationTests.getRedisKeyTest

(RushBuyingApplicationTests.java:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke

(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke

(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod

(ReflectionUtils.java:675)
    at org.junit.jupiter.engine.execution.MethodInvocation.proceed

(MethodInvocation.java:60)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain

$ValidatingInvocation.proceed(InvocationInterceptorChain.java:125)
    at org.junit.jupiter.engine.extension.TimeoutExtension.intercept

(TimeoutExtension.java:132)
    at 

org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMetho

d(TimeoutExtension.java:124)
    at 

org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod

(TimeoutExtension.java:74)
    at org.junit.jupiter.engine.execution.ExecutableInvoker

$ReflectiveInterceptorCall.lambda$ofVoidMethod$0

(ExecutableInvoker.java:115)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda

$invoke$0(ExecutableInvoker.java:105)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain

$InterceptedInvocation.proceed(InvocationInterceptorChain.java:104)
    at 

org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed

(InvocationInterceptorChain.java:62)
    at 

org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvo

ke(InvocationInterceptorChain.java:43)
    at 

org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke

(InvocationInterceptorChain.java:35)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke

(ExecutableInvoker.java:104)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke

(ExecutableInvoker.java:98)
    at 

org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda

$invokeTestMethod$6(TestMethodTestDescriptor.java:202)
    at 

org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute

(ThrowableCollector.java:73)
    at 

org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMet

hod(TestMethodTestDescriptor.java:198)
    at 

org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute

(TestMethodTestDescriptor.java:135)
    at 

org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute

(TestMethodTestDescriptor.java:69)
    at 

org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda

$executeRecursively$5(NodeTestTask.java:135)
    at 

org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute

(ThrowableCollector.java:73)
    at 

org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda

$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around

(Node.java:135)
    at 

org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda

$executeRecursively$8(NodeTestTask.java:123)
    at 

org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute

(ThrowableCollector.java:73)
    at 

org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursi

vely(NodeTestTask.java:122)
    at 

org.junit.platform.engine.support.hierarchical.NodeTestTask.execute

(NodeTestTask.java:80)
    at java.util.ArrayList.forEach(ArrayList.java:1249)
    at 

org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestE

xecutorService.invokeAll

(SameThreadHierarchicalTestExecutorService.java:38)
    at 

org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda

$executeRecursively$5(NodeTestTask.java:139)
    at 

org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute

(ThrowableCollector.java:73)
    at 

org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda

$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around

(Node.java:135)
    at 

org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda

$executeRecursively$8(NodeTestTask.java:123)
    at 

org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute

(ThrowableCollector.java:73)
    at 

org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursi

vely(NodeTestTask.java:122)
    at 

org.junit.platform.engine.support.hierarchical.NodeTestTask.execute

(NodeTestTask.java:80)
    at java.util.ArrayList.forEach(ArrayList.java:1249)
    at 

org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestE

xecutorService.invokeAll

(SameThreadHierarchicalTestExecutorService.java:38)
    at 

org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda

$executeRecursively$5(NodeTestTask.java:139)
    at 

org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute

(ThrowableCollector.java:73)
    at 

org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda

$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around

(Node.java:135)
    at 

org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda

$executeRecursively$8(NodeTestTask.java:123)
    at 

org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute

(ThrowableCollector.java:73)
    at 

org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursi

vely(NodeTestTask.java:122)
    at 

org.junit.platform.engine.support.hierarchical.NodeTestTask.execute

(NodeTestTask.java:80)
    at 

org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestE

xecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
    at 

org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.ex

ecute(HierarchicalTestExecutor.java:57)
    at 

org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.exec

ute(HierarchicalTestEngine.java:51)
    at org.junit.platform.launcher.core.DefaultLauncher.execute

(DefaultLauncher.java:229)
    at org.junit.platform.launcher.core.DefaultLauncher.lambda

$execute$6(DefaultLauncher.java:197)
    at 

org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams

(DefaultLauncher.java:211)
    at org.junit.platform.launcher.core.DefaultLauncher.execute

(DefaultLauncher.java:191)
    at org.junit.platform.launcher.core.DefaultLauncher.execute

(DefaultLauncher.java:128)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs

(JUnit5IdeaTestRunner.java:74)
    at com.intellij.rt.execution.junit.IdeaTestRunner

$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at 

com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart

(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main

(JUnitStarter.java:70)
Caused by: io.lettuce.core.RedisException: Cannot retrieve initial cluster 

partitions from initial URIs [RedisURI [host='192.168.22.130', port=7001], 

RedisURI [host='192.168.22.130', port=7002], RedisURI 

[host='192.168.22.130', port=7003], RedisURI [host='192.168.22.130', 

port=7004], RedisURI [host='192.168.22.130', port=7005], RedisURI 

[host='192.168.22.130', port=7006]]
    at io.lettuce.core.cluster.RedisClusterClient.loadPartitions

(RedisClusterClient.java:859)
    at 

io.lettuce.core.cluster.RedisClusterClient.initializePartitions

(RedisClusterClient.java:813)
    at io.lettuce.core.cluster.RedisClusterClient.getPartitions

(RedisClusterClient.java:823)
    at 

org.springframework.data.redis.connection.lettuce.ClusterConnectionProvide

r.getConnectionAsync(ClusterConnectionProvider.java:92)
    at 

org.springframework.data.redis.connection.lettuce.ClusterConnectionProvide

r.getConnectionAsync(ClusterConnectionProvider.java:40)
    at 

org.springframework.data.redis.connection.lettuce.LettuceConnectionProvide

r.getConnection(LettuceConnectionProvider.java:53)
    at 

org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory

$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1197)
    ... 73 more
Caused by: io.lettuce.core.RedisConnectionException: Unable to establish a 

connection to Redis Cluster at [RedisURI [host='192.168.22.130', 

port=7001], RedisURI [host='192.168.22.130', port=7002], RedisURI 

[host='192.168.22.130', port=7003], RedisURI [host='192.168.22.130', 

port=7004], RedisURI [host='192.168.22.130', port=7005], RedisURI 

[host='192.168.22.130', port=7006]]
    at io.lettuce.core.cluster.topology.AsyncConnections.get

(AsyncConnections.java:89)
    at 

io.lettuce.core.cluster.topology.ClusterTopologyRefresh.loadViews

(ClusterTopologyRefresh.java:76)
    at io.lettuce.core.cluster.RedisClusterClient.doLoadPartitions

(RedisClusterClient.java:865)
    at io.lettuce.core.cluster.RedisClusterClient.loadPartitions

(RedisClusterClient.java:838)
    ... 79 more
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2021-08-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-28
  • 2022-01-01
  • 2022-12-23
  • 2021-07-12
  • 2021-06-10
  • 2022-12-23
相关资源
相似解决方案