Java 使用Redis Sentinel正确配置@EnableRedisHttpSession

Java 使用Redis Sentinel正确配置@EnableRedisHttpSession,java,redis,spring-session,redis-sentinel,Java,Redis,Spring Session,Redis Sentinel,我有一个基于Spring云的应用程序,它有多个后端Spring引导服务器。所有服务器都通过@enableRedistpSession与Redis服务器共享会话 我正在尝试使用主从配置和Redis Sentinel配置应用程序。我的设置是1个主站,2个从站和3个哨兵 我不断遇到环境问题。起初,我得到一个错误,说我的奴隶是只读的。所以我必须把所有的奴隶都设置为读写。然后,我还是犯了这个错误。结果表明,当从机升级为主机时,旧的主机将转换为从机,并具有默认的只读设置。因此,我必须将master设置为RE

我有一个基于Spring云的应用程序,它有多个后端Spring引导服务器。所有服务器都通过@enableRedistpSession与Redis服务器共享会话

我正在尝试使用主从配置和Redis Sentinel配置应用程序。我的设置是1个主站,2个从站和3个哨兵

我不断遇到环境问题。起初,我得到一个错误,说我的奴隶是只读的。所以我必须把所有的奴隶都设置为读写。然后,我还是犯了这个错误。结果表明,当从机升级为主机时,旧的主机将转换为从机,并具有默认的只读设置。因此,我必须将master设置为READWRITE。这些是我引导redis服务器的命令(我知道使用同一台机器是没有意义的,这是为了在这个阶段进行测试):

启动主机:

redis-server --slave-read-only no --port 6379
引导从机:

redis-server --slaveof 127.0.0.1 6379 --slave-read-only no --port 6380
redis-server --slaveof 127.0.0.1 6379 --slave-read-only no --port 6381
每个参与会话的spring引导服务器的application.properties/yml config:

#Redis config
spring.redis.sentinel.master: mymaster
spring.redis.sentinel.nodes: localhost:5000,localhost:5001,localhost:5002
Redis sentinel配置:

redis-sentinel sentinel-0.conf
redis-sentinel sentinel-1.conf
redis-sentinel sentinel-2.conf
conf文件包括:

port 5000
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
sentinel config-epoch mymaster 6
另外两个哨兵的端口是5001和5002

现在,只要一切正常,没有问题,一切正常

然而,一旦我杀死了主redis服务器,事情就停止了。 首先,我得到以下错误:

There was an unexpected error (type=Internal Server Error, status=500).
Cannot get Jedis connection; nested exception is     redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
更糟糕的是,当我重新启动我的应用程序时,事情也停止了工作。虽然没有真正的错误,但应用程序根本无法工作。例如,我没有提供内容,而是得到一个只包含一些文本的页面(没有javascript/css/Image)。这通常表示它找不到需要使用的会话id。甚至在注销后也会发生这种情况

我注意到当我杀死主服务器时,redis sentinel会重写我的配置文件。例如,在杀死主redis服务器后,sentinel.conf现在显示如下:

port 5000
sentinel monitor mymaster 127.0.0.1 6381 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
sentinel config-epoch mymaster 6
# Generated by CONFIG REWRITE
dir "/user/odedia/.jenkins/workspace/boot_redis_sentinel_0"
sentinel leader-epoch mymaster 6
sentinel known-slave mymaster 127.0.0.1 6380
sentinel known-slave mymaster 127.0.0.1 6379
sentinel known-sentinel mymaster 127.0.0.1 5002 28d5fdf14fcc023045f00b00fcdbd4d4f4554611
sentinel known-sentinel mymaster 127.0.0.1 5001 a492f1f0e270fa67c22e057fbd12e981811a79fe
sentinel current-epoch 6
现在,即使在重新启动所有服务器/redis节点后,这些设置仍保持原样。我只能通过手动修复配置文件来使应用程序重新工作

显然,我目前无法使用此解决方案。任何帮助都将不胜感激

以下是完整的堆栈跟踪:

2016-02-29 12:11:12.640 ERROR 32389 --- [enerContainer-1] o.s.d.r.l.RedisMessageListenerContainer  : Connection failure occurred. Restarting subscription task after 5000 ms
2016-02-29 12:11:16.134 ERROR 32389 --- [nio-9090-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception

org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:162) ~[spring-data-redis-1.6.1.RELEASE.jar!/:1.6.1.RELEASE]
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:251) ~[spring-data-redis-1.6.1.RELEASE.jar!/:1.6.1.RELEASE]
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:58) ~[spring-data-redis-1.6.1.RELEASE.jar!/:1.6.1.RELEASE]
    at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:128) ~[spring-data-redis-1.6.1.RELEASE.jar!/:1.6.1.RELEASE]
    at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:91) ~[spring-data-redis-1.6.1.RELEASE.jar!/:1.6.1.RELEASE]
    at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:78) ~[spring-data-redis-1.6.1.RELEASE.jar!/:1.6.1.RELEASE]
    at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:178) ~[spring-data-redis-1.6.1.RELEASE.jar!/:1.6.1.RELEASE]
    at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:153) ~[spring-data-redis-1.6.1.RELEASE.jar!/:1.6.1.RELEASE]
    at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:86) ~[spring-data-redis-1.6.1.RELEASE.jar!/:1.6.1.RELEASE]
    at org.springframework.data.redis.core.DefaultHashOperations.entries(DefaultHashOperations.java:220) ~[spring-data-redis-1.6.1.RELEASE.jar!/:1.6.1.RELEASE]
    at org.springframework.data.redis.core.DefaultBoundHashOperations.entries(DefaultBoundHashOperations.java:101) ~[spring-data-redis-1.6.1.RELEASE.jar!/:1.6.1.RELEASE]
    at org.springframework.session.data.redis.RedisOperationsSessionRepository.getSession(RedisOperationsSessionRepository.java:233) ~[spring-session-1.0.2.RELEASE.jar!/:na]
    at org.springframework.session.data.redis.RedisOperationsSessionRepository.getSession(RedisOperationsSessionRepository.java:220) ~[spring-session-1.0.2.RELEASE.jar!/:na]
    at org.springframework.session.data.redis.RedisOperationsSessionRepository.getSession(RedisOperationsSessionRepository.java:141) ~[spring-session-1.0.2.RELEASE.jar!/:na]
    at org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryRequestWrapper.getSession(SessionRepositoryFilter.java:276) ~[spring-session-1.0.2.RELEASE.jar!/:na]
    at org.springframework.web.context.request.ServletRequestAttributes.updateAccessedSessionAttributes(ServletRequestAttributes.java:255) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.web.context.request.AbstractRequestAttributes.requestCompleted(AbstractRequestAttributes.java:48) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:106) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.springframework.session.web.http.SessionRepositoryFilter.doFilterInternal(SessionRepositoryFilter.java:125) ~[spring-session-1.0.2.RELEASE.jar!/:na]
    at org.springframework.session.web.http.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:65) ~[spring-session-1.0.2.RELEASE.jar!/:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:103) ~[spring-boot-actuator-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_65]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_65]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_65]
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
    at redis.clients.util.Pool.getResource(Pool.java:50) ~[jedis-2.7.3.jar!/:na]
    at redis.clients.jedis.JedisPool.getResource(JedisPool.java:99) ~[jedis-2.7.3.jar!/:na]
    at redis.clients.jedis.JedisPool.getResource(JedisPool.java:12) ~[jedis-2.7.3.jar!/:na]
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:155) ~[spring-data-redis-1.6.1.RELEASE.jar!/:1.6.1.RELEASE]
    ... 55 common frames omitted
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused
    at redis.clients.jedis.Connection.connect(Connection.java:164) ~[jedis-2.7.3.jar!/:na]
    at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:82) ~[jedis-2.7.3.jar!/:na]
    at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1641) ~[jedis-2.7.3.jar!/:na]
    at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:85) ~[jedis-2.7.3.jar!/:na]
    at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868) ~[commons-pool2-2.4.2.jar!/:2.4.2]
    at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435) ~[commons-pool2-2.4.2.jar!/:2.4.2]
    at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) ~[commons-pool2-2.4.2.jar!/:2.4.2]
    at redis.clients.util.Pool.getResource(Pool.java:48) ~[jedis-2.7.3.jar!/:na]
    ... 58 common frames omitted
Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_65]
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_65]
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_65]
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_65]
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_65]
    at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_65]
    at redis.clients.jedis.Connection.connect(Connection.java:158) ~[jedis-2.7.3.jar!/:na]
    ... 65 common frames omitted
此外,以下是一个Sentinel日志的输出:

           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.0.6 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in sentinel mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 5001
 |    `-._   `._    /     _.-'    |     PID: 30337
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

30337:X 29 Feb 12:43:42.898 # Sentinel runid is b2146318c65fb869a5933d6812b41de89cd0131a
30337:X 29 Feb 12:43:42.898 # +monitor master mymaster 127.0.0.1 6379 quorum 2
30337:X 29 Feb 12:43:45.015 * -dup-sentinel master mymaster 127.0.0.1 6379 #duplicate of 127.0.0.1:5000 or 719b5af91a18190a4d07059243bb664b95047f0f
30337:X 29 Feb 12:43:45.015 * +sentinel sentinel 127.0.0.1:5000 127.0.0.1 5000 @ mymaster 127.0.0.1 6379
30337:X 29 Feb 12:43:45.095 * -dup-sentinel master mymaster 127.0.0.1 6379 #duplicate of 127.0.0.1:5002 or b375d206c4833c1196911073f63a13f9ee19b5b1
30337:X 29 Feb 12:43:45.095 * +sentinel sentinel 127.0.0.1:5002 127.0.0.1 5002 @ mymaster 127.0.0.1 6379
30337:X 29 Feb 12:44:07.928 # +sdown master mymaster 127.0.0.1 6379
30337:X 29 Feb 12:44:08.502 # +new-epoch 66
30337:X 29 Feb 12:44:08.630 # +vote-for-leader 719b5af91a18190a4d07059243bb664b95047f0f 66
30337:X 29 Feb 12:44:09.094 # +odown master mymaster 127.0.0.1 6379 #quorum 3/2
30337:X 29 Feb 12:44:09.094 # Next failover delay: I will not start a failover before Mon Feb 29 12:46:08 2016
30337:X 29 Feb 12:46:08.143 # +new-epoch 67
30337:X 29 Feb 12:46:08.144 # +vote-for-leader b375d206c4833c1196911073f63a13f9ee19b5b1 67
30337:X 29 Feb 12:46:08.150 # Next failover delay: I will not start a failover before Mon Feb 29 12:48:08 2016
30337:X 29 Feb 12:48:08.309 # +new-epoch 68
30337:X 29 Feb 12:48:08.310 # +try-failover master mymaster 127.0.0.1 6379
30337:X 29 Feb 12:48:08.313 # +vote-for-leader b2146318c65fb869a5933d6812b41de89cd0131a 68
30337:X 29 Feb 12:48:08.318 # 127.0.0.1:5002 voted for b2146318c65fb869a5933d6812b41de89cd0131a 68
30337:X 29 Feb 12:48:08.318 # 127.0.0.1:5000 voted for b2146318c65fb869a5933d6812b41de89cd0131a 68
30337:X 29 Feb 12:48:08.403 # +elected-leader master mymaster 127.0.0.1 6379
30337:X 29 Feb 12:48:08.404 # +failover-state-select-slave master mymaster 127.0.0.1 6379
30337:X 29 Feb 12:48:08.466 # -failover-abort-no-good-slave master mymaster 127.0.0.1 6379
30337:X 29 Feb 12:48:08.525 # Next failover delay: I will not start a failover before Mon Feb 29 12:50:08 2016
以下是Redis主机的日志(带有sigterm通知):

第二:

                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.0.6 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6381
 |    `-._   `._    /     _.-'    |     PID: 30325
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

30325:S 29 Feb 12:43:42.889 # Server started, Redis version 3.0.6
30325:S 29 Feb 12:43:42.889 * DB loaded from disk: 0.000 seconds
30325:S 29 Feb 12:43:42.889 * The server is now ready to accept connections on port 6381
30325:S 29 Feb 12:43:42.889 * Connecting to MASTER 127.0.0.1:6380
30325:S 29 Feb 12:43:42.889 * MASTER <-> SLAVE sync started
30325:S 29 Feb 12:43:42.889 * Non blocking connect for SYNC fired the event.
30325:S 29 Feb 12:43:42.890 * Master replied to PING, replication can continue...
30325:S 29 Feb 12:43:42.891 * Partial resynchronization not possible (no cached master)
30325:S 29 Feb 12:43:42.892 * Full resync from master: 04f525038fe60c44a75fac73285485fa534bf24c:1
30325:S 29 Feb 12:43:42.984 * MASTER <-> SLAVE sync: receiving 18 bytes from master
30325:S 29 Feb 12:43:42.984 * MASTER <-> SLAVE sync: Flushing old data
30325:S 29 Feb 12:43:42.984 * MASTER <-> SLAVE sync: Loading DB in memory
30325:S 29 Feb 12:43:42.984 * MASTER <-> SLAVE sync: Finished with success
。\u
_.-``__ ''-._                                             
_.-``    `.  `_.  ''-._           Redis 3.0.6(00000000/0)64位
.-`` .-```.  ```\/    _.,_ ''-._                                   
以独立模式运行的(',.-` | `)
|`-.端口:6381
|`-.`.\/.-'| PID:30325
`-._    `-._  `-./  _.-'    _.-'                                   
|`-._`-._    `-.__.-'    _.-'_.-'|                                  
|    `-._`-._        _.-'_.-'    |           http://redis.io        
`-._    `-._`-.__.-'_.-'    _.-'                                   
|`-._`-._    `-.__.-'    _.-'_.-'|                                  
|    `-._`-._        _.-'_.-'    |                                  
`-._    `-._`-.__.-'_.-'    _.-'                                   
`-._    `-.__.-'    _.-'                                       
`-._        _.-'                                           
`-.__.-'                                               
30325:S 2月29日12:43:42.889#服务器已启动,Redis版本3.0.6
30325:S 29 Feb 12:43:42.889*DB从磁盘加载:0.000秒
30325:S 29 Feb 12:43:42.889*服务器现在已准备好接受端口6381上的连接
30325:S 29 Feb 12:43:42.889*连接到主机127.0.0.1:6380
30325:S 29 Feb 12:43:42.889*主从同步已开始
30325:S 29 Feb 12:43:42.889*同步的非阻塞连接触发了事件。
30325:S 29 Feb 12:43:42.890*主机已回复PING,复制可以继续。。。
30325:S 29 Feb 12:43:42.891*无法进行部分重新同步(无缓存主机)
30325:S 29 Feb 12:43:42.892*主机完全重新同步:04F52503FE60C44A75FAC73285485FA534BF24C:1
30325:S 29 Feb 12:43:42.984*主从同步:从主从接收18字节
30325:S 29 Feb 12:43:42.984*主从同步:刷新旧数据
30325:S 29 Feb 12:43:42.984*主从同步:在内存中加载数据库
30325:S 29 Feb 12:43:42.984*主从同步:成功完成

谢谢。

我终于找到了解决办法。是我作为一名开发人员,没有足够的前瞻性

在很久以前的某个时候,我在引导其中一台服务器(网关,在会话管理方面是很重要的一个)时遇到异常,告诉我它找不到JedisConnectionFactoryBean。所以我在主课上写了一篇硬编码的。。。指向端口6379处的本地主机:)。难怪哨兵配置被忽略了

删除了@Bean之后,一切都很正常

我发现它的方式对其他人来说可能是一个很好的参考点。起初,我注意到Spring忽略了application.properties中的条目

因此,我用自己的sentinelConfig@Bean和jedisConnectionFactory@Bean编写了自己的@Configuration类。Spring获取了我的sentinelConfig,但完全忽略了我的jedisConnectionFactory(简单的调试发现了这个问题)

因此,我将bean重命名为customJedisConnectionFactory之类的名称,然后收到一条关于让两个bean实现RedisConnectionFactory的错误消息。从那里很快就在我的源代码中找到了另一个@Bean


谢谢

是否添加完整堆栈跟踪?已添加。到目前为止,我已经为每台服务器(主服务器或从服务器)创建了完整的redis.conf文件,并跳过了内嵌的conf设置,我认为这会导致问题,主要是因为默认情况下,所有3台服务器可能都在写入同一个转储文件。我现在专注于
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.0.6 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6380
 |    `-._   `._    /     _.-'    |     PID: 30319
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

30319:M 29 Feb 12:43:42.884 # Server started, Redis version 3.0.6
30319:M 29 Feb 12:43:42.884 * DB loaded from disk: 0.000 seconds
30319:M 29 Feb 12:43:42.884 * The server is now ready to accept connections on port 6380
30319:M 29 Feb 12:43:42.891 * Slave 127.0.0.1:6381 asks for synchronization
30319:M 29 Feb 12:43:42.891 * Full resync requested by slave 127.0.0.1:6381
30319:M 29 Feb 12:43:42.891 * Starting BGSAVE for SYNC with target: disk
30319:M 29 Feb 12:43:42.891 * Background saving started by pid 30333
30333:C 29 Feb 12:43:42.901 * DB saved on disk
30333:C 29 Feb 12:43:42.901 * RDB: 0 MB of memory used by copy-on-write
30319:M 29 Feb 12:43:42.984 * Background saving terminated with success
30319:M 29 Feb 12:43:42.984 * Synchronization with slave 127.0.0.1:6381 succeeded
30319:M 29 Feb 12:43:43.896 * Slave 127.0.0.1:6379 asks for synchronization
30319:M 29 Feb 12:43:43.896 * Full resync requested by slave 127.0.0.1:6379
30319:M 29 Feb 12:43:43.896 * Starting BGSAVE for SYNC with target: disk
30319:M 29 Feb 12:43:43.897 * Background saving started by pid 30368
30368:C 29 Feb 12:43:43.903 * DB saved on disk
30368:C 29 Feb 12:43:43.903 * RDB: 0 MB of memory used by copy-on-write
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.0.6 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6381
 |    `-._   `._    /     _.-'    |     PID: 30325
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

30325:S 29 Feb 12:43:42.889 # Server started, Redis version 3.0.6
30325:S 29 Feb 12:43:42.889 * DB loaded from disk: 0.000 seconds
30325:S 29 Feb 12:43:42.889 * The server is now ready to accept connections on port 6381
30325:S 29 Feb 12:43:42.889 * Connecting to MASTER 127.0.0.1:6380
30325:S 29 Feb 12:43:42.889 * MASTER <-> SLAVE sync started
30325:S 29 Feb 12:43:42.889 * Non blocking connect for SYNC fired the event.
30325:S 29 Feb 12:43:42.890 * Master replied to PING, replication can continue...
30325:S 29 Feb 12:43:42.891 * Partial resynchronization not possible (no cached master)
30325:S 29 Feb 12:43:42.892 * Full resync from master: 04f525038fe60c44a75fac73285485fa534bf24c:1
30325:S 29 Feb 12:43:42.984 * MASTER <-> SLAVE sync: receiving 18 bytes from master
30325:S 29 Feb 12:43:42.984 * MASTER <-> SLAVE sync: Flushing old data
30325:S 29 Feb 12:43:42.984 * MASTER <-> SLAVE sync: Loading DB in memory
30325:S 29 Feb 12:43:42.984 * MASTER <-> SLAVE sync: Finished with success