当前位置: 首页 > 知识库问答 >
问题:

使用SpringDataRedis的Redis Sentinel身份验证

鄢选
2023-03-14

我在本地配置了redis sentinel,在两个不同的端口10001和10002上运行。我有相同的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。发布

莴苣(io.莴苣.莴苣芯):5.0.5.RELEASE

在尝试连接到redisSentinelConfiguration时,我一直收到NOAUTH身份验证请求错误

使用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$0(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$1.call(DeploymentManagerImpl.java:200)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:171)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
10:38:37,981 INFO  [stdout] (ServerService Thread Pool -- 72)   at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.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$1.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$9(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$9(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$5.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 References并没有帮助解决这个问题。任何帮助解决这个问题的人都将不胜感激

共有1个答案

秦安宁
2023-03-14

我将Spring数据redis jar升级到2.2.2.RELEASE,将莴苣jar升级到5.2.1.RELEASE,这就解决了这个问题。

Spring data redis jars的较低版本存在问题,在lettuceConverters类中未正确设置sentinel密码,该类在2.2.2.RELEASE版本中已修复。

 类似资料:
  • 我正在使用SpringBoot开发具有微服务架构的Rest Backend。为了保护endpoint,我使用了JWT令牌机制。我正在使用Zuul API网关。 如果请求需要权限(来自JWT的角色),它将被转发到正确的微服务。Zuul api网关的“WebSecurityConfigrerAdapter”如下。 这样,我必须在这个类中编写每个请求授权部分。因此,我希望使用方法级安全性,即“Enabl

  • 我有一个asp。net(C#)设置为使用LDAP进行身份验证。一切正常,我可以和我们目录中的任何用户一起登录。问题是,我需要将某些页面限制为特定组中的人。我正在使用登录查看帐户文件夹的方法。 我的网站设计很简单,它有三个页面,一个供所有人查看(账户文件夹之外),另外两个需要身份验证。我希望一个组可以访问两个网页,另一个组只能访问其中一个网页。 我试过: 但不管我的用户不在该组中。我有一个LDAP浏

  • 我试图在一个反应式Spring Boot应用程序中配置一个Spring Security性,该应用程序具有一个Vuejs前端,在未经身份验证时将用户重定向到外部OpenID提供程序(用于身份验证)。在用户通过OpenID提供程序进行身份验证并重定向回应用程序(前端)后,将根据OpenID提供程序的响应创建用户名密码身份验证令牌(身份验证),并手动进行身份验证。 但是,在执行此操作时,应用程序似乎无

  • 问题内容: 我目前有一个Palm WebOS应用程序,该应用程序使用Ajax.Request通过基本身份验证连接到Web服务。要发送用户名和密码,我只需将其包含在url(即http:// username:password @ ip-address:port / )中即可,效果非常好,期望密码包含字母数字字符以外的任何字符(例如, ,最近有一个用户给我发送电子邮件,该用户的密码中包含“ @”和“&

  • 问题内容: 使用基本身份验证进行身份验证时遇到问题。我正在使用符合协议的标准枚举来构造我的请求。问题是,当我在枚举中手动设置授权标头时,如下所示: 我总是收到401未经授权的回复。 但是, 如果我像这样使用回调设置密码: 它正确认证。我希望能够在符合的枚举中手动进行设置,而不是在中传递凭据。 我知道它正在使用身份验证挑战的后台,但我希望能够手动设置它。 这是我的实现: 问题答案: 最终弄清楚了问题

  • 问题内容: 我有2个Spring Web应用程序,它们提供2套独立的服务。Web App 1具有使用基于用户的身份验证实现的Spring Security。 现在,Web App 2需要访问Web App 1的服务。通常,我们将使用RestTemplate类向其他Web服务发出请求。 我们如何将Web App 2的请求中的身份验证凭据传递给Web App 1 问题答案: 我当时处在同样的情况。这是