The construction and Jedis test of Sentinel cluster in Redis [i]

Source: Internet
Author: User
Tags failover redis server

First, the test environment
master:   127.0.0.1 6379slave1:    127.0.0.1 6479slave2:    127.0.0.1 6579master-sentinel: 127.0.0.1 26379slave1-sentinel: 127.0.0.1 26479slave2-sentinel: 127.0.0.1 26579
Ii. Download and install the Redis 2.8.3
wget http://download.redis.io/releases/redis-2.8.3.tar.gztar –zxvf redis-2.8.3.tar.gzcd redis-2.8.3make;make install(此处可用PREFIX参数将redis安装到其他目录)
Third, configure the test environment

--Create a directory:

cd /usr/localmkdir redis_clustermkdir redis_cluster/master_6379mkdir redis_cluster/slave_6479mkdir redis_cluster/slave_6579

--Configure Redis:
Master

cp –a –R –p ~/redis-2.8.3/redis.conf ./redis_cluster/master_6379/cp –a –R –p ~/redis-2.8.3/sentinel.conf ./redis_cluster/master_6379/6379-sentinel.confvi ./redis_cluster/master_6379/redis.conf(将对应配置修改成如下)
yes  6379  requirepass vhreal        masterauth  vhreal  no  ""  yes  
vi ./redis_cluster/master_6379/6379-sentinel.conf
26379  192.168.0.8663792  sentinel auth-pass mymaster vhreal  sentinel down-after-milliseconds30000  sentinel parallel-syncs1  sentinel failover-timeout900000  

Slave1

cp –a –R –p ~/redis-2.8.3/redis.conf ./redis_cluster/slave_6479/cp –a –R –p ~/redis-2.8.3/sentinel.conf ./redis_cluster/slave_6479/6479-sentinel.confvi ./redis_cluster/slave_6479/redis.conf(将对应配置修改成如下)
daemonizeyes  6479  requirepass vhreal         masterauth  vhreal  no  ""  yes  192.168.0.866379  
vi ./redis_cluster/slave_6479/6479-sentinel.conf
26479  192.168.0.8663792  sentinel auth-pass mymaster vhreal  sentinel down-after-milliseconds30000  sentinel parallel-syncs1  sentinel failover-timeout900000  

Slave2

cp –a –R –p ~/redis-2.8.3/redis.conf ./redis_cluster/slave_6579/cp –a –R –p ~/redis-2.8.3/sentinel.conf ./redis_cluster/slave_6579/6579-sentinel.confvi ./redis_cluster/slave_6579/redis.conf(将对应配置修改成如下)
daemonizeyes  6579  requirepass vhreal         masterauth  vhreal  no  ""  yes  192.168.0.866379  
vi ./redis_cluster/slave_6579/6579-sentinel.conf
26579  192.168.0.8663792  sentinel auth-pass mymaster vhreal  sentinel down-after-milliseconds30000  sentinel parallel-syncs1  sentinel failover-timeout900000  
Iv. starting the cluster

Note : When you first build your sentinel environment, you must first start master.

Start Master and Master-sentinel:
Redis-server/usr/local/redis_cluster/master-6379/redis.conf
Redis-sentinel/usr/local/redis_cluster/master-6379/6379-sentinel.conf

Cloning sessions, starting slave1 and Slave1-sentinel:
Redis-server/usr/local/redis_cluster/slave-6479/redis.conf
Redis-sentinel/usr/local/redis_cluster/slave-6479/6479-sentinel.conf

Cloning sessions, starting slave2 and Slave2-sentinel:
Redis-server/usr/local/redis_cluster/slave-6579/redis.conf
Redis-sentinel/usr/local/redis_cluster/slave-6579/6579-sentinel.conf

To view the status of master:
Redis-cli-h 192.168.0.86-p 6379

To view the status of slave:
Redis-cli–h 192.168.0.86–p 6479

--Scene 1:slave outage
Close slave1:
To view the Sentinel status and view the replication information for master, there is only one slave2 6579.

--Scene 2:slave recovery
Re-open slave1:
Redis-server/usr/local/redis_cluster/slave-6479/redis.conf
To view Sentinel Status:
Sentinel can quickly discover that slave is added to the cluster:

--Scene 3:master outage
Master-sentinel as the Master 1 leader, a Master 1 slave is selected as the new master. The selection of slave is based on the priority of a DNS case, the same priority is obtained by Runid sorting, but the priority setting is not implemented yet, so the direct acquisition of Runid sorted by slave 1.

Then send the command slaveof no one to cancel the slave state of slave 1 to convert to master. When other Sentinel observes that the slave becomes master, it knows that the error-handling routine is started. Sentinel A then sends to the other slave slaveof new-slave-ip-port command, and Sentinel a removes the failure master from the monitored Masters list when all slave are configured. Then notify the other Sentinels.
Close Master:

To view Sentinel Status:
6379-sentinel:
Automatically switches slave2 6579 to master, and the original master becomes slave.

6579-sentinel:
Shows the process of failover:

--Scene 4:master recovery
Restart the original master:
Redis-server/usr/local/redis_cluster/master-6379/redis.conf
To view Sentinel Status:
The original master automatically switches to slave and does not automatically revert to master:

The test is complete.

Note : If the old Master is restarted before Sentinel has selected a new master but has not yet completed the reconfigure of the other instances, the entire system will be unable to elect the new master exception.

V. References
    • Redis Sentinel Cluster Scenario – stand-alone test
    • Building and testing of redis:sentinel clusters
    • How to use Redis Server Setup/configuration/and Jedis client

The construction and Jedis test of Sentinel cluster in Redis [i]

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.