Redis Sentinel Failover

Source: Internet
Author: User
Tags failover join redis redis server
# Redis-sentinel's official website address: Http://redis.io/topics/sentinel # Note: Redis-sentinel website is not a stable version. Personally feel this is much better than Keepalived+redis to switch. Configuration environment: os:centos6.1 x86  *  4 software:redis-2.6.9 Memory: 16G cpu: e5606  @ 2.13GHz *----------------- -IP Distribution: Redis Sentinel  : 192.168.7.46 redis server Master  : 192.168.7.44 redis server from 1:  192.168.7.40 Redis Servers from 2:  192.168.7.142 are trailing IPs, such as 44, 46 .... The structure is as follows: In the------------------configuration process, if there are no 4 machines, it can be as long as 2 units, one running Sentinel and another Redis service running 3 different ports. The minimum cluster units are: 1 Sentinel, 2 Redis;------------------Start: 1.1 Start Redis-server services       #redis的安装配置就不介绍了, It is not clear that the configuration file that can be Google,redis first can be used directly.       #启动   Redis Server services   (ip  44, 40, 142)       Redis-server/usr/local/re dis-2.6.9/redis.conf   &       #配置40, 142 for from library, respectively       REDIS-CLI slaveof& nbsp 192.168.7.44 6379       #查看主上的主从状态        redis-cli-h 192.168.7.44-p 63info  Replication       #可以看到从状态        #随意查看一台从的主从状态       redis-cli-h 192.168.7.40-p 6379 info Replication------------------ 
1.2 Start Redis Sentinel (ip:46) # Sentinel's configuration file for sentinel.conf copy the following configuration, modify the IP address. Cat/usr/local/redis-2.6.9/sentinel.conf Sentinel Monitor Test1 192.168.7.40 6379 1 #修改IP地址, IP can be any IP address in the cluster. Sentinel Down-after-milliseconds Test1 #默认1s检测一次, where the configuration timed out 5000 milliseconds for downtime.
Sentinel Failover-timeout test1 900000
Sentinel Can-failover Test1 Yes
Sentinel Parallel-syncs test1 2        #启动 Redis sentinel       redis-server /usr/local/redis-2.6.9/sentinel.conf --sentinel  &       #  Sentinel default port is 26379, Sentinel Terminal Print:     * slave   from library info @ master-name Main Library information         # above information indicates Sentinel   has been started The current master-slave situation has been identified.       # But this will only show up on the terminal, and if you close the current terminal, you won't be able to display it.       # Use commands to display the current status more directly.       # query Master status        redis-cli-h 192.168.7.46-p 26379 info Sentinel   &NBSP ;     #通过这里可以获取到主IP地址        redis-cli  -h 192.168.7.46-p 26379  info sentinel| Awk-f ', '/status/{print $} ' | Awk-f ' = ' {print $} '       # query slave status       redis-cli -h 192.168.7.46 -p 26379 Sentinel Slaves test1        //test1 is the       #图中显示了几个从库 (name number) configured in sentinel.conf, from the library'sIP address and status, the IP address and status of the main library.       #还有 ' Runid ', Redis's parameters that are not prioritized by the master are configurable, by default using the Runid size to compete with the main library, so it is also possible to predict which of the next master is       # See here the next master for 142.   Priority the author should update it later. ------------------1.3 Demo faults       #目前状态:       # Redis Sentinel  : 192.168.7.46       Redis Server master  :  192.168.7.44       # Redis server from 1:  192.168.7.40       Redis server from 2:  192.168.7.142  
#关闭 Redis Server master: 192.168.7.44 redis-cli-h 192.168.7.44-p 6379 shutdown #查看 Sentinel status Redis-cli       -H 192.168.7.46-p 26379 info Sentinel #可以看到 The IP address of the Redis server master has become 192.168.7.142.       #查看192.168.7.40 status, if configured properly, its main 142 # OK auto-switch has been implemented.       # If it's not the main outage, but from the outage, then there will be no switching behavior, only the outage of the station from the cluster to remove.       # The machine is down, and if you join the cluster again, Sentinel will automatically discover and join the cluster members as long as it becomes the current master's slave. # You can do your own experiment.
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.