From post http://blog.csdn.net/men_wen/article/details/72724406
<http://blog.csdn.net/men_wen/article/details/72724406>
Learned the sentinel configuration , But in the process of practice, there are some problems , Mainly about bind to configure , Password authentication ,ip Problems of . And then I'll summarize it again .

redis edition 3.2.100

There are 3 individual Sentinel node ,1 Master nodes ,2 Slave nodes make up one Redis Sentinel.

role ip port
master192.168.30.2496379
slave1192.168.30.1236379
slave2192.168.30.2546379
Sentinel1192.168.30.24926379
Sentinel2192.168.30.12326379
Sentinel3192.168.30.25426379
192.168.30.249 to configure

redis.conf to configure

The main modified configuration is as follows , Other configuration defaults .
## Binding reality here ip. Remote access for clients bind 192.168.30.249 port 6379 ## Open log level is debug, Easy to see log debugging .
loglevel debug## Log location logfile "D:/myStuepss/redis-x64-3.2.100/redisserver.log"
## Configured master Authentication password for , Although the current role is master, But once you hang up and recover , Will become salve, This is the time to connect new master When , If master Password authentication required , You need to configure .
masterauth"[email protected]" ## Password authentication is required when the client connects . requirepass "[email protected]"
sentinel to configure
# It's configured as real ip. For remote access of clients , for example : I used it spring data redis. If not configured here ip, It's going to be wrong . bind 192.168.30
.249 port 26379 dir "D:\\myStuepss\\Redis-x64-3.2.100\\temp" # monitor master sentinel
monitor mymaster192.168.30.249 6379 2 # To configure the master Authentication password for , Otherwise, it will not be monitored sentinel
auth-pass mymaster [email protected] # Configure log on , Easy troubleshooting , View status . logfile
"D:/myStuepss/redis-x64-3.2.100/sentinellog.log" loglevel debug
192.168.30.254 to configure

redis.conf to configure

The main modified configuration is as follows , Other configuration defaults .
## Binding reality here ip. Remote access for clients bind 192.168.30.254 port 6379 slaveof 192.168.30.249 6379
## Configured master Authentication password for , As salve To synchronize master Data for , You can't connect without configuration master masterauth "[email protected]"
## Password authentication is required when the client connects . requirepass "[email protected]"
sentinel to configure
# It's configured as real ip. For remote access of clients , for example : I used it spring data redis. If not configured here ip, It's going to be wrong . bind 192.168.30
.254 port 26379 dir "D:\\myStuepss\\Redis-x64-3.2.100\\temp" # monitor master sentinel
monitor mymaster192.168.30.249 6379 2 # To configure the master Authentication password for , Otherwise, it will not be monitored sentinel
auth-pass mymaster [email protected] # Configure log on , Easy troubleshooting , View status . logfile
"D:/myStuepss/redis-x64-3.2.100/sentinellog.log" loglevel debug
192.168.30.123 to configure

redis.conf to configure

The main modified configuration is as follows , Other configuration defaults .
## Binding reality here ip. Remote access for clients bind 192.168.30.123 port 6379 slaveof 192.168.30.249 6379
## Configured master Authentication password for , As salve To synchronize master Data for , You can't connect without configuration master masterauth "[email protected]"
## Password authentication is required when the client connects . requirepass "[email protected]"
sentinel to configure
# It's configured as real ip. For remote access of clients , for example : I used it spring data redis. If not configured here ip, It's going to be wrong . bind 192.168.30
.123 port 26379 dir "D:\\myStuepss\\Redis-x64-3.2.100\\temp" # monitor master sentinel
monitor mymaster192.168.30.249 6379 2 # To configure the master Authentication password for , Otherwise, it will not be monitored sentinel
auth-pass mymaster [email protected] # Configure log on , Easy troubleshooting , View status . logfile
"D:/myStuepss/redis-x64-3.2.100/sentinellog.log" loglevel debug
spring data redis Sentinel configuration

* spring edition 4.3.5.RELEASE
* spring-data-redis edition 1.8.9.RELEASE
* jedis edition 2.9.0
redis.properties to configure
# Host and port number redis.host1.cloudq=192.168.30.254 redis.port1.cloudq=26379 redis.host2
.cloudq=192.168.30.249 redis.port2.cloudq=26379 redis.host3.cloudq=192.168.30
.123 redis.port3.cloudq=26379 #JedisPoolConfig Parameters of # maximum connection redis.pool.maxTotal=30
# Maximum idle time redis.pool.maxIdle=10 # Maximum connections per time redis.pool.numTestsPerEvictionRun=1024
# Scan interval for release scan redis.pool.timeBetweenEvictionRunsMillis=30000 # Minimum idle time of the connection redis.pool
.minEvictableIdleTimeMillis=1800000 # How long does the connection control release after , When idle > This value and idle connection > Direct release when the maximum number of idle connections
redis.pool.softMinEvictableIdleTimeMillis=10000 # Maximum number of milliseconds to wait for a link , less than 0: Blocking uncertainty time , default -1
redis.pool.maxWaitMillis=1500 # Check validity when getting links , default false redis.pool.testOnBorrow
=true# Check validity when idle , default false redis.pool.testWhileIdle=true
# Whether the connection is blocked when it is exhausted ,false Report abnormality ,true Blocking timeout , default true redis.pool.blockWhenExhausted=false
#JedisConnectionFactory Parameters of # Timeout , default :2000 redis.timeout.cloudq=3000 # password redis
[email protected] # Use connection pool or not , default true redis.usePool=true
# Use index of database ,0-15 Number between , default :0 redis.dbIndex=0 # Use conversion of data type , default :true
#redis.convertPipelineAndTxResults # Sentinel configuration #redis.sentinelConfig redis.expiration=
3000
spring-redis.xml to configure
<?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" xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd "> <!-- Import profile --> <
bean id="placeholderConfigurer" class=
"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <
property name="order" value="1"/> <property name=
"ignoreUnresolvablePlaceholders" value="true"/> <property name="locations"> <
list> <value>classpath:redis.properties</value> </list> </property> </bean>
<!-- to configure jedis pool--> <bean id="jedisPoolConfig" class=
"redis.clients.jedis.JedisPoolConfig"> <!-- maximum connection --> <property name="maxTotal"
value="${redis.pool.maxTotal}"/> <!-- Maximum idle time --> <property name="maxIdle" value=
"${redis.pool.maxIdle}"/> <!-- Maximum connections per time --> <property name=
"numTestsPerEvictionRun" value="${redis.pool.numTestsPerEvictionRun}"/> <!--
Scan interval for release scan --> <property name="timeBetweenEvictionRunsMillis" value=
"${redis.pool.timeBetweenEvictionRunsMillis}"/> <!-- Minimum idle time of the connection --> <property
name="minEvictableIdleTimeMillis" value=
"${redis.pool.minEvictableIdleTimeMillis}"/> <!--
How long does the connection control release after , When idle > This value and idle connection > Direct release when the maximum number of idle connections --> <property name=
"softMinEvictableIdleTimeMillis" value=
"${redis.pool.softMinEvictableIdleTimeMillis}"/> <!--
Maximum number of milliseconds to wait for a link , less than 0: Blocking uncertainty time , default -1 --> <property name="maxWaitMillis" value=
"${redis.pool.maxWaitMillis}"/> <!-- Check validity when getting links , default false --> <property name=
"testOnBorrow" value="${redis.pool.testOnBorrow}"/> <!-- Check validity when idle , default false --> <
property name="testWhileIdle" value="${redis.pool.testWhileIdle}"/> <!--
Whether the connection is blocked when it is exhausted ,false Report abnormality ,true Blocking timeout default :true--> <property name="blockWhenExhausted" value
="${redis.pool.blockWhenExhausted}"/> </bean> <!-- to configure redisSentinelConfiguration
Sentinel mode --> <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"> </property> </bean> </property> <property name="sentinels"> <
set> <bean class="org.springframework.data.redis.connection.RedisNode"> <
constructor-arg name="host" value="${redis.host1.cloudq}"/> <constructor-arg
name="port" value="${redis.port1.cloudq}"/> </bean> <bean class=
"org.springframework.data.redis.connection.RedisNode"> <constructor-arg name=
"host" value="${redis.host2.cloudq}"/> <constructor-arg name="port" value=
"${redis.port2.cloudq}"/> </bean> <bean class=
"org.springframework.data.redis.connection.RedisNode"> <constructor-arg name=
"host" value="${redis.host3.cloudq}"/> <constructor-arg name="port" value=
"${redis.port3.cloudq}"/> </bean> </set> </property> </bean> <bean id=
"redisConnectionFactorySentinel" class=
"org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:password="${redis.password.cloudq}"> <constructor-arg name="sentinelConfig"
ref="redisSentinelConfiguration"></constructor-arg> <constructor-arg name=
"poolConfig" ref="jedisPoolConfig"></constructor-arg> </bean> <!-- redis
template definition --> <bean id="redisTemplate" class=
"org.springframework.data.redis.core.RedisTemplate" p:connection-factory-ref=
"redisConnectionFactorySentinel" p:keySerializer-ref=
"genericJackson2JsonRedisSerializer" p:valueSerializer-ref=
"genericJackson2JsonRedisSerializer" p:hashKeySerializer-ref=
"genericJackson2JsonRedisSerializer" p:hashValueSerializer-ref=
"genericJackson2JsonRedisSerializer" p:enableTransactionSupport="false"/> <bean
id="genericJackson2JsonRedisSerializer" class=
"org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
<!-- to configure RedisCacheManager realization spring Caching provided by framework --> <!-- <bean id="redisCacheManager"
class="org.springframework.data.redis.cache.RedisCacheManager">
<constructor-arg name="redisOperations" ref="redisTemplate"/> <property
name="defaultExpiration" value="${redis.expiration}"/> </bean>--> </beans>
junit test
import org.junit.runner.RunWith; import org.springframework.beans.factory
.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations; import org
.springframework.test.context.ContextConfiguration; import org.springframework
.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner
.class) @ContextConfiguration(locations = {"classpath:/spring-redis.xml"} )
public class LockTest { @Autowired private RedisTemplate redisTemplate; @org
.junit.Test public void test() throws Exception{ ValueOperations
valueOperations = redisTemplate.opsForValue(); for(int i =0;i<10000;i++){ try{
valueOperations.set("test:"+i,i); }catch (Exception e){ e.printStackTrace(); }
Thread.sleep(1000); } } }