Redis + sentinel + java dual-machine Hot Standby tutorial (available for test), redis dual-machine hot standby

Source: Internet
Author: User

Redis + sentinel + java dual-machine Hot Standby tutorial (available for test), redis dual-machine hot standby
1. Two linux systems: 192.11.3.1 (master); 192.11.3.2 (slave); 2. Two linux systems are installed with redis

tar xzvf redis-4.0.6.tar.gzcd redis-4.0.6make
3. Modify redis. conf of redis.
1. in redis. conf, 2. comment out bind 127.0.0.1 (only local access is allowed. find protected-mode yes and change yes to no (disable protection mode). 4. locate daemonize no and change it to yes (enable the protection process)
4. Master-slave Replication
192.11.3.1 (master); 192.11.3.2 (slave) add slaveof 192.11.3.1 6379 at the bottom of redis. conf in 192.11.3.2 to make it the slave of 192.11.3.1 and automatically keep consistent with the master data
5. Hot Standby
1. find the sentinel of two redis instances. conf (and redis. conf directory), modify as follows: 2. locate sentinel monitor mymaster 127.0.0.1 6379 2, replace with sentinel monitor mymaster 192.11.3.1 6379 1 (both conf need to be replaced) (configuration content description refer to http://blog.csdn.net/a1282379904/article/details/52335051) 3. find # protected-mode no to remove comments
6. Start
Start the redis and sentinel services on two servers in sequence.
7. Connect to redis using java
   Set
 
   sentinels = new HashSet
  
   ();        String hostAndPort1 = "192.11.3.1:26379";        String hostAndPort2 = "192.11.3.2:26379";        sentinels.add(hostAndPort1);        sentinels.add(hostAndPort2);        String clusterName = "mymaster";        JedisSentinelPool redisSentinelJedisPool = new JedisSentinelPool(clusterName, sentinels);        Jedis jedis = null;        try {            jedis = redisSentinelJedisPool.getResource();            jedis.set("RNG", "niubi");            System.out.println(jedis.get("RNG"));        } catch (Exception e) {            e.printStackTrace();        } finally {            redisSentinelJedisPool.returnBrokenResource(jedis);        }
  
 

When kill redis service 192.11.3.1, redis of 192.11.3.2 will become the main service and the program will still be available

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.