jedis连接seninels出现Can connect to sentinel, but mymaster seems to be not monitored...

明舞 发布于 2015/08/07 15:24
阅读 5K+
收藏 0

目前遇到个问题。jedis2.6.2+spring-data-redis准备做一个一主一备的redis主备线上部署。

但是在启动的时候总是出现Can connect to sentinel, but mymaster   seems to be not monitored...

首先看spring的配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
">
<context:annotation-config />


<!-- 引入配置文件 -->
<context:property-placeholder location="classpath:application.properties" />
<!-- 扫描文件(自动将servicec层注入) -->
<!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 -->
<context:component-scan base-package="com.netease" />
<!-- <bean id="RedisUtil " class="com.netease.mobile.common.RedisUtil " 
/> -->
<!-- 配置jedis -->


<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="${im.hs.server.redis.maxTotal}" />
<property name="minIdle" value="${im.hs.server.redis.minIdle}" />
<property name="maxWaitMillis" value="${im.hs.server.redis.maxWaitTime}" />
<property name="maxIdle" value="${im.hs.server.redis.maxIdle}" />
<property name="testOnBorrow" value="${im.hs.server.redis.testOnBorrow}" />
<property name="testOnReturn" value="true" />
<property name="testWhileIdle" value="true" />
</bean>
<bean id="sentinelConfiguration"
class="org.springframework.data.redis.connection.RedisSentinelConfiguration">
<property name="master">
<bean class="org.springframework.data.redis.connection.RedisNode">
<property name="name" value="${im.hs.server.redis.sentinel.masterName}"></property>

</bean>
</property>
<property name="sentinels">
<set>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host"
value="${im.hs.server.redis.sentinel1.host}"></constructor-arg>
<constructor-arg name="port"
value="${im.hs.server.redis.sentinel1.port}"></constructor-arg>
</bean>
<!-- <bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host"
value="${im.hs.server.redis.sentinel2.host}"></constructor-arg>
<constructor-arg name="port"
value="${im.hs.server.redis.sentinel2.port}"></constructor-arg>
</bean> -->
</set>
</property>
</bean>


<bean id="connectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<constructor-arg name="sentinelConfig" ref="sentinelConfiguration"></constructor-arg>
<constructor-arg name="poolConfig" ref="poolConfig"></constructor-arg>
<!-- <property name="hostName" value="${redis.master.host}" />
<property name="port" value="${redis.master.port}" /> 
<property name="usePool" value="true" />-->


</bean>
<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="connectionFactory" />
</bean>


<import resource="spring-mybatis.xml" />
</beans>


接着看redis上面seninel的配置:
dir "/tmp/slave1"
daemonize yes
sentinel monitor mymaster 10.165.124.19 6379 1
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 15000
sentinel config-epoch mymaster 76
sentinel leader-epoch mymaster 77
sentinel known-slave mymaster 10.165.124.19 6378

加载中
0
zheng_pat
zheng_pat
你得sentinel的端口为啥没有配置,是估计不暴露出来吗
明舞
明舞
其实我就用了默认的端口,没有改,内网服务暴露别人也上不去
0
jbone项目开发者
jbone项目开发者

这里有个对Redis sentinel很详细的介绍,进攻参考:

http://redis.majunwei.com/topics/sentinel.html

0
兔子有颗星
兔子有颗星

您好请问问题解决了吗 我也碰到了 想请教一下如何解决

0
-hardy-
-hardy-

同问!

0
-hardy-
-hardy-

知道问题的原因了。是程序中哨兵配置的名称,和服务器中redis哨兵配置的名称不一致导致的。

返回顶部
顶部