6379 6380 6381是一主两从的形式。
26379 26380 26381 是三个哨兵
6379配置:
protected-mode no
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "6379.log"
databases 16
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump-6379.rdb
dir /usr/local/share/softs/redisdata
masterauth 222222
requirepass 222222
6380配置:
protected-mode no
port 6380
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_6380.pid
loglevel notice
logfile "6380.log"
databases 16
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump-6380.rdb
dir /usr/local/share/softs/redisdata
slaveof 127.0.0.1 6379
masterauth 222222
requirepass 222222
我只贴了核心的配置,6381的跟6380的类似我就不贴了
哨兵配置:
port 26379
dir "/usr/local/share/softs/redisdata"
logfile "sen26379.log"
daemonize yes
protected-mode no
sentinel myid d03f8002b566af4ef4144dc8e9894b1670d715bb
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel auth-pass mymaster 222222
# Generated by CONFIG REWRITE
sentinel known-slave mymaster 127.0.0.1 6380
sentinel known-slave mymaster 127.0.0.1 6381
sentinel current-epoch 0
服务搭在阿里云上,端口已经开放,如下:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:8005 0.0.0.0:* LISTEN 1883/java
tcp 0 0 0.0.0.0:8009 0.0.0.0:* LISTEN 1883/java
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 8073/mysqld
tcp 0 0 0.0.0.0:26379 0.0.0.0:* LISTEN 17772/redis-sentine
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 17752/redis-server
tcp 0 0 0.0.0.0:26380 0.0.0.0:* LISTEN 17778/redis-sentine
tcp 0 0 0.0.0.0:6380 0.0.0.0:* LISTEN 17758/redis-server
tcp 0 0 0.0.0.0:26381 0.0.0.0:* LISTEN 17784/redis-sentine
tcp 0 0 0.0.0.0:6381 0.0.0.0:* LISTEN 17765/redis-server
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 1883/java
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1547/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1649/master
spring核心配置如下:
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="20480" />
<property name="maxIdle" value="200" />
<property name="numTestsPerEvictionRun" value="1024" />
<property name="timeBetweenEvictionRunsMillis" value="30000" />
<property name="minEvictableIdleTimeMillis" value="-1" />
<property name="softMinEvictableIdleTimeMillis" value="10000" />
<property name="maxWaitMillis" value="1500" />
<property name="testOnBorrow" value="true" />
<property name="testWhileIdle" value="true" />
<property name="testOnReturn" value="false" />
<property name="jmxEnabled" value="true" />
<property name="blockWhenExhausted" value="false" />
</bean>
<bean id="redisSentinelConfiguration"
class="org.springframework.data.redis.connection.RedisSentinelConfiguration">
<property name="master">
<bean class="org.springframework.data.redis.connection.RedisNode">
<property name="name" value="mymaster"/>
</bean>
</property>
<property name="sentinels">
<set>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="xxxxxxx" />
<constructor-arg name="port" value="26379" />
</bean>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="xxxxxx" />
<constructor-arg name="port" value="26380" />
</bean>
<bean class="org.springframework.data.redis.connection.RedisNode ">
<constructor-arg name="host" value="xxxxxx" />
<constructor-arg name="port" value="26381" />
</bean>
</set>
</property>
</bean>
<bean id="redisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:password="222222"
>
<constructor-arg name="sentinelConfig" ref="redisSentinelConfiguration"></constructor-arg>
<constructor-arg name="poolConfig" ref="jedisPoolConfig"></constructor-arg>
</bean>
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="redisConnectionFactory" />
</bean>
<bean id="redisDao" class="com.jason.petshome.dao.cache.RedisDao"/>
但是始终无法正常获取数据
严重: Servlet.service() for servlet [petshome-dispatcher] in context with path [] threw exception [Request processing failed; nested exception is 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] with root cause
java.net.ConnectException: Connection refused: connect
请问这是什么原因?谢谢