前提:
- redis-Sentinel模式集群部署,通过sentinel哨兵来监控。
redis、sentinel共三台服务
redis1 192.168.0.222 6379
redis2 192.168.0.223 6379
redis3 192.168.0.224 6379
哨兵1 192.168.0.222 26379
哨兵2 192.168.0.223 26379
哨兵3 192.168.0.224 26379
- tx-manager-4.1.0管理事务。
过程:
在配置tx的application.properties时,导致tx服务启动不了。
1、每一次配置失败
##redis 集群环境配置
##redis cluster
spring.redis.password=123456
spring.redis.sentinel.master=mymaster
spring.redis.sentinel.nodes=192.168.0.222:26379,192.168.0.223:26379,192.168.0.224:26379
启动时无异常,访问时异常
线程“pool-1-thread-91”org.springframework.data.redis.RedisConnectionFailureException 中的异常:无法获得 Jedis 连接;嵌套异常是 redis.clients.jedis.exceptions.JedisConnectionException:无法从
org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:204)的池中获取资源
org.springframework.data .redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:348)
在 org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:129)
在 org.springframework.data.redis.core.RedisConnectionUtils .getConnection(RedisConnectionUtils.java:92)
在 org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:79)
在 org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:194)
在 org.springframework.data.redis .core.RedisTemplate.execute(RedisTemplate.java:169)
在 org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:91)
在 org.springframework.data.redis.core.DefaultHashOperations.get(DefaultHashOperations) .java:49)
在 com.codingapi.tm.redis.service.impl.RedisServerServiceImpl.getLoadBalance(RedisServerServiceImpl.java:113)
在 com.codingapi.tm.manager.service.impl.LoadBalanceServiceImpl.get(LoadBalanceServiceImpl.java:32) )
在 com.codingapi.tm.netty.service.impl.ActionGLBServiceImpl.execute(ActionGLBServiceImpl.java:29)
在 com.codingapi.tm.netty.handler.TxCoreServerHandler.service(TxCoreServerHandler.java:67)
在 com.codingapi.tm .netty.handler.TxCoreServerHandler.access$000(TxCoreServerHandler.java:29)
在 com.codingapi.tm.netty.handler.TxCoreServerHandler$1.run(TxCoreServerHandler.java:52)
在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor) .java:1149)
在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
在 java.lang.Thread.run(Thread.java:748)
引起:redis.clients.jedis.exceptions。 JedisConnectionException:无法从池中获取资源
在 redis.clients.util.Pool.getResource(Pool.java:53)
在 redis.clients.jedis.JedisSentinelPool.getResource(JedisSentinelPool.java:209)
在 redis.clients.jedis.JedisSentinelPool.getResource(JedisSentinelPool.java:17 )
在 org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:194)
... 17 更多
1、每二次配置失败
##redis 集群环境配置
##redis clusterspring.redis.password=123456
#spring.redis.cluster.nodes=192.168.0.222:6379,192.168.0.223:6379,192.168.0.224:6379
# spring.redis.cluster.commandTimeout =5000
启动时异常,log不截取太多,有重点就行。
在 org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
在 org.springframework.beans.factory。 support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
在 org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java :835) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
在 org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ~[spring-beans- 4.3.9.RELEASE.jar:4.3.9.RELEASE]
...省略了58个常用帧
引起:redis.clients.jedis.exceptions.JedisDataException: ERR 此实例
在 redis.clients.jedis.Protocol.processError(Protocol.java:127) ~[jedis-2.9.0.jar:na]
处禁用了集群支持redis.clients.jedis.Protocol.process(Protocol.java:161) ~[jedis-2.9.0.jar:na]
在 redis.clients.jedis.Protocol.read(Protocol.java:215) ~[jedis-2.9 .0.jar:na]
在 redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340) ~[jedis-2.9.0.jar:na]
在 redis.clients.jedis.Connection.getRawObjectMultiBulkReply(Connection.java) :285) ~[jedis-2.9.0.jar:na]
在 redis.clients.jedis.Connection.getObjectMultiBulkReply(Connection.java:291) ~[jedis-2.9.0.jar:na]
在 redis.clients.jedis.Jedis.clusterSlots(Jedis.java:3376) ~[jedis-2.9.0.jar:na]
在 redis.clients.jedis.JedisClusterInfoCache.discoverClusterNodesAndSlots(JedisClusterInfoCache.java:54) ~[jedis- 2.9.0.jar:na]
在 redis.clients.jedis.JedisClusterConnectionHandler.initializeSlotsCache(JedisClusterConnectionHandler.java:39) ~[jedis-2.9.0.jar:na]
在 redis.clients.jedis.JedisClusterConnectionHandler.<init>( JedisClusterConnectionHandler.java:17) ~[jedis-2.9.0.jar:na]
在 redis.clients.jedis.JedisSlotBasedConnectionHandler.<init>(JedisSlotBasedConnectionHandler.java:24) ~[jedis-2.9.0.jar:na]
在redis.clients.jedis.BinaryJedisCluster.<init>(BinaryJedisCluster.java:54) ~[jedis-2.9.0.jar:na]
在 redis.clients.jedis.JedisCluster.<init>(JedisCluster.java:93) ~[jedis-2.9.0.jar:na]
在 org.springframework.data.redis.connection.jedis.JedisConnectionFactory.createCluster(JedisConnectionFactory. java:306) ~[spring-data-redis-1.8.4.RELEASE.jar:na]
在 org.springframework.data.redis.connection.jedis.JedisConnectionFactory.createCluster(JedisConnectionFactory.java:280) ~[spring-data -redis-1.8.4.RELEASE.jar:na]
在 org.springframework.data.redis.connection.jedis.JedisConnectionFactory.afterPropertiesSet(JedisConnectionFactory.java:241) ~[spring-data-redis-1.8.4.RELEASE。 jar:na]
在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
...省略了69个常用框架
从报错误的信息ERR This instance has cluster support disabled
很明显看得出来,是没有启动redis集群功能,可是我项目配置的集群的配置方式,要么修改代码为单机配置,要么修改redis为集群方式。
那么去在安装redis的目录找到redis配置文件redis.conf
,里面会找到配置:# cluster-enabled yes。
可是我们用的sentinel,是不允许开启redis集群,开启时会提示错误。
解决方案:
最后我只能去修改TX的redis连接源码,其实很简单,如下:
结论:
Tx-manager本身是支持单机模式或者cluster集群,但配置路径需要指定与redis连接池管理一致。也就是说下面的配置路径不能修改,源码会指定读取spring.redis.cluster.nodes的值。
#######################################redis-start#################################################
#redis 配置文件,根据情况选择集群或者单机模式##redis 集群环境配置
##redis cluster
#spring.redis.cluster.nodes=127.0.0.1:7001,127.0.0.1:7002,127.0.0.1:7003
#spring.redis.cluster.commandTimeout=5000##redis 单点环境配置
#redis
#redis主机地址
spring.redis.host=127.0.0.1
#redis主机端口
spring.redis.port=6379
#redis链接密码
spring.redis.password=
spring.redis.pool.maxActive=10
spring.redis.pool.maxWait=-1
spring.redis.pool.maxIdle=5
spring.redis.pool.minIdle=0
spring.redis.timeout=0
#####################################redis-end###################################################