Redis哨兵认证使用Lettuce+SpringDataRedis

Redis Sentinel Authentication using Lettuce+SpringDataRedis

我在本地 运行 的 2 个不同端口 10001 和 10002 上配置了 redis sentinel。我有相同的 sentinel 身份验证设置。

Redis 哨兵配置

port 10001
bind 127.0.0.1
requirepass password
sentinel myid qwqsffhdhjyutsfgsfg4656767ifdfgtw4tgerhj
sentinel deny-scripts-reconfig yes
sentinel monitor mymaster 127.0.0.1 7777 2
sentinel auth-pass mymaster password

使用的 jar 版本

Spring-data-redis : 2.0.10.RELEASE

生菜(io.lettuce.lettuce-核心):5.0.5.RELEASE

尝试连接到 redisSentinelConfiguration 时,我不断收到 NOAUTH Authentication REquired 错误

RedisSentinelConfiguration 使用 Spring DI

<bean id="redisSentinelConfiguration" class="org.springframework.data.redis.connection.RedisSentinelConfiguration" p:password="#{T(org.springframework.data.redis.connection.RedisPassword).of('password')}"> 
        <constructor-arg type="java.lang.String" value="mymaster"></constructor-arg> 
        <constructor-arg type="java.util.Set"> <set value-type="java.lang.String"> 
        <value>127.0.0.1:10001</value> <value>127.0.0.1:10002</value> 
        </set> </constructor-arg> </bean>

错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource [org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisException: java.util.concurrent.ExecutionException: io.lettuce.core.RedisCommandExecutionException: NOAUTH Authentication required.
10:38:37,980 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1699)
10:38:37,980 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573)
10:38:37,980 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
10:38:37,980 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=12=](AbstractBeanFactory.java:317)
10:38:37,980 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
10:38:37,980 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
10:38:37,980 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
10:38:37,980 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759)
10:38:37,980 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
10:38:37,980 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:409)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:187)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.core.DeploymentManagerImpl.call(DeploymentManagerImpl.java:200)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.core.DeploymentManagerImpl.call(DeploymentManagerImpl.java:171)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.core.ServletRequestContextThreadSetupAction.call(ServletRequestContextThreadSetupAction.java:42)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.core.ContextClassLoaderSetupAction.call(ContextClassLoaderSetupAction.java:43)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.api.LegacyThreadSetupActionWrapper.call(LegacyThreadSetupActionWrapper.java:44)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.api.LegacyThreadSetupActionWrapper.call(LegacyThreadSetupActionWrapper.java:44)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.api.LegacyThreadSetupActionWrapper.call(LegacyThreadSetupActionWrapper.java:44)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.api.LegacyThreadSetupActionWrapper.call(LegacyThreadSetupActionWrapper.java:44)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.api.LegacyThreadSetupActionWrapper.call(LegacyThreadSetupActionWrapper.java:44)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:234)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.run(UndertowDeploymentService.java:82)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at java.util.concurrent.FutureTask.run(FutureTask.java:266)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at java.lang.Thread.run(Thread.java:748)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.jboss.threads.JBossThread.run(JBossThread.java:320)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72) Caused by: org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisException: java.util.concurrent.ExecutionException: io.lettuce.core.RedisCommandExecutionException: NOAUTH Authentication required.
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:966)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getConnection(LettuceConnectionFactory.java:934)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getSharedConnection(LettuceConnectionFactory.java:786)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getConnection(LettuceConnectionFactory.java:300)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration$EnableRedisKeyspaceNotificationsInitializer.afterPropertiesSet(RedisHttpSessionConfiguration.java:284)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1758)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1695)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   ... 31 more
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72) Caused by: io.lettuce.core.RedisException: java.util.concurrent.ExecutionException: io.lettuce.core.RedisCommandExecutionException: NOAUTH Authentication required.
10:38:37,982 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.lettuce.core.RedisClient.lambda$getSocketAddressSupplier(RedisClient.java:720)
10:38:37,982 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.lettuce.core.ConnectionBuilder.socketAddress(ConnectionBuilder.java:132)
10:38:37,982 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.lettuce.core.AbstractRedisClient.initializeChannelAsync(AbstractRedisClient.java:251)
10:38:37,982 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.lettuce.core.RedisClient.connectStatefulAsync(RedisClient.java:318)
10:38:37,982 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.lettuce.core.RedisClient.connectStandaloneAsync(RedisClient.java:276)
10:38:37,982 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.lettuce.core.RedisClient.connectStandalone(RedisClient.java:252)
10:38:37,982 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.lettuce.core.RedisClient.connect(RedisClient.java:202)
10:38:37,982 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:56)
10:38:37,982 INFO  [stdout] (ServerService Thread Pool -- 72)   at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:959)
10:38:37,982 INFO  [stdout] (ServerService Thread Pool -- 72)   ... 37 more
10:38:37,982 INFO  [stdout] (ServerService Thread Pool -- 72) Caused by: java.util.concurrent.ExecutionException: io.lettuce.core.RedisCommandExecutionException: NOAUTH Authentication required.
10:38:37,982 INFO  [stdout] (ServerService Thread Pool -- 72)   at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
10:38:37,982 INFO  [stdout] (ServerService Thread Pool -- 72)   at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1915)
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.lettuce.core.RedisClient.lookupRedis(RedisClient.java:728)
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.lettuce.core.RedisClient.getSocketAddress(RedisClient.java:670)
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.lettuce.core.RedisClient.lambda$getSocketAddressSupplier(RedisClient.java:713)
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   ... 45 more
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72) Caused by: io.lettuce.core.RedisCommandExecutionException: NOAUTH Authentication required.
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.lettuce.core.protocol.AsyncCommand.completeResult(AsyncCommand.java:118)
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.lettuce.core.protocol.AsyncCommand.complete(AsyncCommand.java:109)
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.lettuce.core.protocol.CommandHandler.complete(CommandHandler.java:598)
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:556)
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:508)
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
10:38:37,984 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
10:38:37,985 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
10:38:37,985 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434)
10:38:37,985 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
10:38:37,985 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
10:38:37,985 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965)
10:38:37,985 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
10:38:37,985 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645)
10:38:37,985 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580)
10:38:37,985 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497)
10:38:37,985 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459)
10:38:37,985 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.util.concurrent.SingleThreadEventExecutor.run(SingleThreadEventExecutor.java:884)
10:38:37,985 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
10:38:37,985 INFO  [stdout] (ServerService Thread Pool -- 72)   at java.lang.Thread.run(Thread.java:748)

google 参考没有帮助解决这个问题。任何帮助解决问题的人将不胜感激

我将 Spring-data-redis jar 升级到 2.2.2.RELEASE 并将 Lettuce jar 升级到 5.2.1.RELEASE 并解决了问题。

较低版本的 Spring-data-redis jar 存在问题,其中 lettuceConverters class 中的哨兵密码设置不正确,已在 2.2 中修复。2.RELEASE版本。