我在局域网一台服务器 192.168.6.33 启动了 configServer,端口 7091,同时 6 个 docker 容器的 Redis 集群也在这台服务器上,容器网络地址是 172.16.0.31-172.16.0.36 ,Redis 端口都是 7001,映射到外面分别是 7001-7006。 为了方便调试,我在自己电脑上启动微服务,微服务名称是 web, 在 configserver 的配置文件夹中 web 服务的配置文件是 web-local.properties,其中的 Redis 集群配置是:
spring.redis.cluster.nodes=192.168.6.33:7001,192.168.6.33:7002,192.168.6.33:7003,192.168.6.33:7004,192.168.6.33:7005,192.168.6.33:7006
启动微服务获取配置文件信息的日志如下:
2019-05-06 09:54:17.055 INFO 4076 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://192.168.6.33:7091/
2019-05-06 09:54:17.315 INFO 4076 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=web, profiles=[local], label=null, version=null, state=null
2019-05-06 09:54:17.315 INFO 4076 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='configService', propertySources=[MapPropertySource [name='classpath:properties/web-local.properties']]]
从启动日志来看,获取配置文件的路径信息是没有问题的,通过浏览器访问 http://192.168.6.33:7091/web-local.properties 获取的 redis 集群信息都是:
192.168.6.33:7001,192.168.6.33:7002,192.168.6.33:7003,192.168.6.33:7004,192.168.6.33:7005,192.168.6.33:7006
但是 web 服务后面的日志 redis 集群就报错,解析出来的地址是 docker 容器的内部地址:
Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource [org/springframework/boot/autoconfigure/session/RedisSessionConfiguration$SpringBootRedisHttpSessionConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.data.redis.ClusterStateFailureException: Could not retrieve cluster information. CLUSTER NODES returned with error.
- 172.16.0.32:7001 failed: Could not get a resource from the pool
- 172.16.0.34:7001 failed: Could not get a resource from the pool
- 172.16.0.33:7001 failed: Could not get a resource from the pool
- 172.16.0.36:7001 failed: Could not get a resource from the pool
- 172.16.0.35:7001 failed: Could not get a resource from the pool
- 172.16.0.31:7001 failed: Could not get a resource from the pool
哪位大神帮忙看下是什么问题,小弟万分感谢
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.