gpt4 book ai didi

java - Spring Redisson哨兵错误-至少需要两个哨兵

转载 作者:可可西里 更新时间:2023-11-01 11:46:28 27 4
gpt4 key购买 nike

我正在为 Redis 使用哨兵模式。我使用的是 Redisson 客户端 3.9.1 版

<dependencies>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-data-20</artifactId>
<version>${redisson-version}</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>${redisson-version}</version>
</dependency>
</dependencies>

使用Redisson配置Sentinel:

@EnableCaching
public class RedisCache {

@Autowired
private ObjectMapper objectMapper;

@Bean
public RedissonClient redissonClient() {
Config config = new Config();
config.setCodec(new JsonJacksonCodec(objectMapper));

config.useSentinelServers()
.setMasterName("redis-master")
.addSentinelAddress("redis://localhost:26378")
.addSentinelAddress("redis://localhost:26379");

return Redisson.create(config);
}

@Bean
public RedissonConnectionFactory redissonConnectionFactory(RedissonClient redisson) {
return new RedissonConnectionFactory(redisson);
}
}

我正在运行两台哨兵服务器和一台没有从服务器的 Redis 主服务器。这只是我本地环境的设置。
一些命令的输出:

redis-cli -p 26379
127.0.0.1:26379> SENTINEL get-master-addr-by-name redis-master
1) "127.0.0.1"
2) "6379"
redis-cli -p 26378
127.0.0.1:26378> SENTINEL get-master-addr-by-name redis-master
1) "127.0.0.1"
2) "6379"

每当我运行我的 Spring Boot 应用程序时,我都会收到以下错误:

       Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redissonClient' defined in class path resource [xxxx/cache/impl/redis/config/RedisCache.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.redisson.api.RedissonClient]: Factory method 'redissonClient' threw exception; nested exception is org.redisson.client.RedisConnectionException: At least two sentinels should be defined in Redis configuration!

......

at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0 (AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:204)
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType (ServletContextInitializerBeans.java:226)
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType (ServletContextInitializerBeans.java:214)
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addServletContextInitializerBeans (ServletContextInitializerBeans.java:91)
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.<init> (ServletContextInitializerBeans.java:80)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans (ServletWebServerApplicationContext.java:250)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize (ServletWebServerApplicationContext.java:237)
at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup (TomcatStarter.java:54)
at org.apache.catalina.core.StandardContext.startInternal (StandardContext.java:5245)
at org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call (ContainerBase.java:1420)
at org.apache.catalina.core.ContainerBase$StartChild.call (ContainerBase.java:1410)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
at java.lang.Thread.run (Thread.java:748)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.566 s
[INFO] Finished at: 2018-12-07T13:44:14+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.1.RELEASE:run (default-cli) on project xxx: An exception occurred while running. null: InvocationTargetException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthEndpoint]: Factory method 'healthEndpoint' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.redis.RedisHealthIndicatorConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redissonConnectionFactory' defined in class path resource [xxxxxxx/cache/impl/redis/config/RedisCache.class]: Unsatisfied dependency expressed through method 'redissonConnectionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redissonClient' defined in class path resource [xxxxxx/cache/impl/redis/config/RedisCache.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.redisson.api.RedissonClient]: Factory method 'redissonClient' threw exception; nested exception is org.redisson.client.RedisConnectionException: At least two sentinels should be defined in Redis configuration!

如何解决此错误?

PS:我也试过主从配置,一个哨兵连接到主机,另一个连接到从机,但错误仍然存​​在。我尝试过在具有不同私有(private) IP 的不同本地机器上运行哨兵,但错误仍然存​​在。尝试使用 3 个哨兵服务器,没有任何好处。

最佳答案

Redisson 似乎无法使用本地主机地址。当我用 AWS 上托管的地址替换前哨节点地址时,它工作正常。

在我看来,Redisson 是一个非常不成熟的客户端。考虑使用生菜或 jedis。

查看在 https://github.com/redisson/redisson/issues/1736 提交的错误这不允许它关闭。

我遇到的大部分问题都是在使用哨兵模式时出现的。集群模式我没试过。在单一模式下工作正常。

此外,他们几个月来都没有解决在 github 上提交的错误或问题,这很明显,因为他们有专业版和付费版,所以你只能靠自己了。

目前我不推荐使用 Redisson。

关于java - Spring Redisson哨兵错误-至少需要两个哨兵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53665923/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com