Redis Automatic fault Transfer Sentinel

Source: Internet
Author: User
Tags failover redis

Recently saw the Redis automatic Failover Sentinel (Sentinel), so take notes at the second place
Note that in the real world, multiple machines, this article is just testing, so configure multiple Redis instances on a single machine to achieve the purpose of the experiment

Redis Sentinel (Sentinel)

7000 Configuration Files


Port 7000
Daemonize Yes
Pidfile/var/run/redis-7000.pid
LogFile "7000.log"
Dbfilename "Dump-7000.rdb"
AppendOnly Yes
Appendfilename "Appendonly-7000.aof"
Dir "/data/redis"

Configuration file Authoring


Sed ' s/7000/7001/g ' redis-7000.conf >>redis-7001.conf
Sed ' s/7000/7002/g ' redis-7000.conf >>redis-7002.conf
Cat redis-7001.conf
Cat redis-7002.conf
Cat redis-7000.conf

Set up master-slave relationships


echo "slaveof 192.168.1.108 7000" >>redis-7001.conf
echo "slaveof 192.168.1.108 7000" >>redis-7002.conf

Launch three Redis servers


Redis-server/etc/redis/redis-7000.conf
Redis-server/etc/redis/redis-7002.conf
Redis-server/etc/redis/redis-7001.conf
Ps-ef | grep Redis

View replication information for Redis 7000 ports

Php


127.0.0.1:7000> Info Replication
# Replication
Role:master
Connected_slaves:2
Slave0:ip=192.168.1.108,port=7001,state=online,offset=43,lag=1
Slave1:ip=192.168.1.108,port=7002,state=online,offset=43,lag=1
master_repl_offset:43
Repl_backlog_active:1
repl_backlog_size:1048576
Repl_backlog_first_byte_offset:2
Repl_backlog_histlen:42

Configure Sentinel

Vim redis-sentinel-26379.conf

Port 26379
Daemonize Yes
Pidfile/var/run/redis-26379.pid
LogFile "26379.log"
Dir/data/redis
Sentinel Monitor MyMaster 192.168.1.108 7000 2
Sentinel Down-after-milliseconds MyMaster 30000
Sentinel Parallel-syncs MyMaster 1
Sentinel Failover-timeout MyMaster 180000

Build configuration file

Sed ' s/26379/26380/g ' redis-sentinel-26379.conf >> redis-sentinel-26380.conf
Sed ' s/26379/26381/g ' redis-sentinel-26379.conf >> redis-sentinel-26381.conf

Start the Sentry.

Php


[Root@centos redis]# redis-sentinel redis-sentinel-26379.conf
[Root@centos redis]# Redis-sentinel redis-sentinel-26380.conf
[Root@centos redis]# redis-sentinel redis-sentinel-26381.conf
 
[ Root@centos redis]# Ps-ef | grep redis-sentinel| Grep-v ' grep '
root      2677     1  0 02:36?         00:00:00 redis-sentinel *:26379 [Sentinel]
root      2681      1  0 02:36?        00:00:00 redis-sentinel *:26380 [ Sentinel]
root      2685     1  0 02:36?         00:00:00 redis-sentinel *:26381 [Sentinel]
 
You can then test the function of the sentry, too much code will not be pasted up, This Redis automatic failover simple model has completed

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.