Redis Sentinel High Availability Cluster

Source: Internet
Author: User

Redis is now a popular NoSQL open source software. Because of the rich data types and the speed of 80k+ per second, he is a good choice for scenarios with high concurrency and large traffic requirements. I use Redis primarily to do the data cache. And the centralized storage of the session in the distributed system. In order to solve the single point of failure of Redis and improve the reliability of Redis, the previous practice was to use keepalived to control the floating of virtual IP for hot standby. With the birth of the redis2.8 and the 3.0 release. The official website supports Sentinel mode hot standby, Sentinel is Sentinel, constantly monitoring the current Redis survival status. The overall use of a master multi-standby mode. Read/write separation. The master node is readable and writable, and the node is read-only.

Deployment: Three servers, IP 192.168.0.2 (master,sentinel),192.168.0.3 (Slave,sentinel),192.168.0.4 (Slave,sentinel)

1. The version of Redis selected is 3.0.4. A single-node deployment is no longer a repeat. Online Baidu/google a large area.

After the 2.master node is deployed, two spare nodes are added separately in the configuration file:

Slaveof 192.168.0.2 6379

As an alternate node for the master node.

3. View node Performance

Redis-cli-h 192.168.0.2-p 6379 Info replication

4. Deploy Sentinel

Open Sentinel configuration file sentinel.conf

Port 26379sentinel Monitor MyMaster 192.168.0.2 6379 2 #j监控主节点 and starts when 2 sentinel nodes think Master is down Failoversentinel Down-after-milliseconds mymaster #master多久不可达的时候转换状态为S_DOWNsentinel failover-timeout mymaster 900000 # Reserve a master-slave switchover time. If the master-slave switchover is not completed within this time, the switchover fails.

5. Launch Sentinel

./bin/redis-sentinel./conf/sentinel.conf--sentinel


Configure IP to 192.168.0.3,192.168.0.4 on Sentinel according to the configuration above.

4.spring integration.

The Spring-data-redis of spring is used in my development architecture. The relevant configuration files are as follows:

<bean id= "Jedispoolconfig"  class= "Redis.clients.jedis.JedisPoolConfig" >         <property name= "Maxtotal"  value= "${redis.maxtotal}"/>         <property name= "Maxidle"  value= "${redis.maxIdle}"/>         <property name= "Timebetweenevictionrunsmillis"   Value= "${redis.timebetweenevictionrunsmillis}"/>        < Property name= "Minevictableidletimemillis"  value= "${redis.minevictableidletimemillis}"/>         <property name= "Testonborrow"  value= "${ Redis.testonborrow} "/>    </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=" 192.168.0.2 "/>                     <constructor-arg name= "Port"  value= "26379"/>                 </bean>                 <bean class= " Org.springframework.data.redis.connection.RedisNode ">                     <constructor-arg name= "Host"   Value= "192.168.0.3"/>                     <constructor-arg name= "Port"  value= "26379"/>                 </bean>                  <bean class= " Org.springframework.data.redis.connection.RedisNode ">                     <constructor-arg name= "Host"   Value= "192.168.0.4"/>                     <constructor-arg name= "Port"  value= "26379"/>                 </bean>             </set>         </property>    </bean>    <bean id= " Jedisconnfactory "          class=" Org.springframework.data.redis.connection.jedis.JedisConnectionFactory ">        <constructor-arg ref= "Redissentinelconfiguration"/>         <constructor-arg ref= "Jedispoolconfig"/>    </ Bean>    <bean id= "Redistemplate"  class= " Org.springframework.data.redis.core.RedisTemplate ">        < Property name= "ConnectionFactory"  ref= "Jedisconnfactory"/>         <property name= "Keyserializer" >             <bean class= "Org.springframework.data.redis.serializer.StringRedisSerializer"/>         </property>         <property name= "ValueSerializer" >             <bean class= "Org.springframework.data. Redis.serializer.StringRedisSerializer "/>        </property>     </bean>

The above is a summary of the use of Redis please give us more advice thank you!





Redis Sentinel High Availability Cluster

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.