From posthttp://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 aboutbind To configure, Password authentication,ip Problem. And then I'll summarize it again.

redis Edition3.2.100

Separately3 individualSentinel node,1 Main node,2 Slave nodes make up oneRedis Sentinel.

roleip 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 hereip. Remote access for clients bind 192.168.30.249 port 6379 ## Open log level isdebug, Easy to see log debugging.
loglevel debug## Log location logfile "D:/myStuepss/redis-x64-3.2.100/redisserver.log"
## Configuredmaster Authentication password for, Although the current role ismaster, But once you hang up and recover, Will turn intosalve, This is the time to connect newmaster When, Ifmaster 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 realip. For remote access of clients, for example: I used it.spring data redis. If not configured hereip, False report. bind 192.168.30
.249 port 26379 dir "D:\\myStuepss\\Redis-x64-3.2.100\\temp" # Monitormaster sentinel
monitor mymaster192.168.30.249 6379 2 # To configuremaster Authentication password for, Otherwise, it will not be monitored sentinel
auth-pass mymaster [email protected] # Configure log on, Easy troubleshooting, View state. 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 hereip. Remote access for clients bind 192.168.30.254 port 6379 slaveof 192.168.30.249 6379
## Configuredmaster Authentication password for, Act assalve To synchronizemaster Data, You can't connect without configurationmaster masterauth "[email protected]"
## Password authentication is required when the client connects. requirepass "[email protected]"
sentinel To configure
# It's configured as realip. For remote access of clients, for example: I used it.spring data redis. If not configured hereip, False report. bind 192.168.30
.254 port 26379 dir "D:\\myStuepss\\Redis-x64-3.2.100\\temp" # Monitormaster sentinel
monitor mymaster192.168.30.249 6379 2 # To configuremaster Authentication password for, Otherwise, it will not be monitored sentinel
auth-pass mymaster [email protected] # Configure log on, Easy troubleshooting, View state. 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 hereip. Remote access for clients bind 192.168.30.123 port 6379 slaveof 192.168.30.249 6379
## Configuredmaster Authentication password for, Act assalve To synchronizemaster Data, You can't connect without configurationmaster masterauth "[email protected]"
## Password authentication is required when the client connects. requirepass "[email protected]"
sentinel To configure
# It's configured as realip. For remote access of clients, for example: I used it.spring data redis. If not configured hereip, False report. bind 192.168.30
.123 port 26379 dir "D:\\myStuepss\\Redis-x64-3.2.100\\temp" # Monitormaster sentinel
monitor mymaster192.168.30.249 6379 2 # To configuremaster Authentication password for, Otherwise, it will not be monitored sentinel
auth-pass mymaster [email protected] # Configure log on, Easy troubleshooting, View state. logfile
"D:/myStuepss/redis-x64-3.2.100/sentinellog.log" loglevel debug
spring data redis Sentinel configuration

* spring Edition4.3.5.RELEASE
* spring-data-redis Edition1.8.9.RELEASE
* jedis Edition2.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 # 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 than0: Blocking uncertainty time, default-1
redis.pool.maxWaitMillis=1500 # Check validity when getting links, defaultfalse redis.pool.testOnBorrow
=true# Check validity when idle, defaultfalse redis.pool.testWhileIdle=true
# Whether the connection is blocked when it is exhausted,false Newspaper anomaly,true Blocking timeout, defaulttrue redis.pool.blockWhenExhausted=false
#JedisConnectionFactory Parameters # Timeout time, default:2000 redis.timeout.cloudq=3000 # Password redis
[email protected] # Use connection pool or not, defaulttrue 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 than0: Blocking uncertainty time, default-1 --> <property name="maxWaitMillis" value=
"${redis.pool.maxWaitMillis}"/> <!-- Check validity when getting links, defaultfalse --> <property name=
"testOnBorrow" value="${redis.pool.testOnBorrow}"/> <!-- Check validity when idle, defaultfalse --> <
property name="testWhileIdle" value="${redis.pool.testWhileIdle}"/> <!--
Whether the connection is blocked when it is exhausted,false Newspaper anomaly,true Blocking timeout default:true--> <property name="blockWhenExhausted" value
="${redis.pool.blockWhenExhausted}"/> </bean> <!-- To configureredisSentinelConfiguration
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 configureRedisCacheManager Realizationspring 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); } } }