Spring Redisson Sentinel Error - Требуются как минимум два стража - PullRequest
0 голосов
/ 07 декабря 2018

Я использую режим Sentinel для Redis.Я использую Redisson Client версии 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>

Конфигурация Sentinel с использованием Redisson:

@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: я также пробовал конфигурацию «ведущий-ведомый», один страж был подключен к хосту, а другой - к ведомому, но ошибка остается той же.Я пробовал дозорные, работающие на разных локальных машинах с разными частными IP-адресами, но ошибка остается той же.Пробовал с 3 часовыми серверами, никаких преимуществ.

Ответы [ 2 ]

0 голосов
/ 28 декабря 2018

Redisson отлично работает с локальными адресами.В вашем случае команда SENTINEL SENTINELS возвращает пустой результат.Это означает, что установка Redis не настроена должным образом.

0 голосов
/ 12 декабря 2018

Redisson не работает с локальными адресами.Когда я заменил адреса сторожевых узлов на адреса, размещенные на AWS, все заработало нормально.

Redisson, на мой взгляд, очень незрелый клиент.Подумайте об использовании салата или джедаев.

См. Ошибку, поданную по адресу https://github.com/redisson/redisson/issues/1736, которая не позволяет завершить работу.

Большинство проблем, с которыми я столкнулся, были, когда я использовалдозорный режим.Кластерный режим я еще не пробовал.Прекрасно работает в одиночном режиме.

Кроме того, они не обслуживают ошибки или проблемы, поданные на github в течение нескольких месяцев, что очевидно, поскольку у них есть профессиональная и платная версии, так что вы сами.

Я не буду рекомендовать использовать Redisson сейчас.

...