Redis Cluster deployment sentinel--two implementations

Source: Internet
Author: User
Tags auth failover mkdir redis terminates redis cluster redis server
1.sentinel

The Redis Sentinel system is used to manage multiple Redis servers, performing three main tasks:
1) Monitoring: Sentinel constantly check whether the master-slave server is operating properly;
2) Reminder: When a Redis server problems, you can send notifications through the API;
3) Automatic failover: When a primary server fails, Sentinel starts an automatic failover operation that upgrades one of the failed primary servers from the server to the new primary server and the other slave servers from the failed master to replicate the new primary server When a client attempts to connect to a failed primary server, the cluster also returns the address of the new primary server to the client, allowing the cluster to use the new primary server instead of the failed server.
Redis Sentinel is a distributed system that allows you to run multiple Sentinel processes (progress) in one architecture that uses the gossip protocol (gossip protocols) to receive information about whether the primary server is offline, The Voting Protocol (agreement protocols) is used to determine whether automatic failover is performed and which slave server is selected as the new primary server. Although Redis Sentinel releases the Redis-sentinel as a separate executable file, it's actually just a Redis server running in a special mode, and you can start the Red with a given –sentinel option when you start a normal Redis server Is Sentinel. 2. Installation Environment

This installation uses two servers as the master-slave server, the server information is as follows:

Master:              10.133.6.120  6379
slave:               10.133.6.126  6379
master-sentinel:     10.133.6.120  26379
slave-sentinel:      10.133.6.126  26379

To create a new folder under the root directory data1:

[Root@redis-1 ~]# CD/
[root@redis-1/]# mkdir data1
[root@redis-1/]# CD data1/

To download the Redis installation package: (using redis-2.8.4)

[Root@redis-1 data1]# wget http://download.redis.io/releases/redis-2.8.4.tar.gz

Unzip the installation:

[Root@redis-2 data1]# tar-zxvf redis-2.8.4.tar.gz
[root@redis-1 data1]# cd redis-2.8.4
[root@redis-2 redis-2.8.4]# Make;make Install
3. Configure Redis
[Root@redis-1 redis-2.8.4]# cd/usr/local/
[root@redis-1 local]# mkdir redis
[root@redis-1 local]# CD redis/

Primary server Configuration Redis–master:

[root@redis-1 redis]# cp/data1/redis-2.8.4/redis.conf./redis.conf [root@redis-1 redis]# CP /data1/redis-2.8.4/sentinel.conf./master-sentenel.conf [root@redis-1 redis]# VI redis.conf------------------------
-------------------------------------------------------------------# # # #master redis.conf###### # # # #启动进程为后台进程 daemonize Yes # # # #端口 Port 6379 # # # #日志文件路径设置 logfile "/data1/log/redis/redis.log" # # # # #授权密码, in a safe environment can not set Requirepass 123456 Masterauth 123456 # # # #注释指令重命名, if configured you do not need to modify #rename-command # # # #开启AOF AppendOnly Yes save "" Slave-read-only y Es-------------------------------------------------------------------------------------------
[Root@redis-1 redis]# VI master-sentenel.conf-------------------------------------------------------------------- -----------------------# # # #master sentinel.conf # # # # #启动进程为后台进程 daemonize Yes # #sentinel实例之间的通讯端口 Port 26379 # # # #sentinel
Master information required for monitoring:<mastername> <masterIP> <masterPort> <quorum>.
The ####<quorum> should be smaller than the number of slave in the cluster, and the master is considered to be odwon ("objective" invalidation) only if at least <quorum> Sentinel instance submits "master invalidation". Sentinel Monitor MyMaster 10.133.6.120 6379 2 # # # #设置日志路径 logfile "/data1/log/redis/sentinel.log" # # # #授权密码, in a safe environment can not set S Entinel Auth-pass MyMaster 123456 # # # #master被当前sentinel实例认定为 "fail" (Sdown) interval Time Sentinel Down-after-milliseconds
MyMaster 30000 # # # #当新master产生时, at the same time "slaveof" to the new master and the number of simultaneous replication slave.
# #在salve执行salveof与同步时, the client request will be terminated.
# #此值较大, which means that the "cluster" terminates the sum and large amount of time the client requests.
# #此值较小 means that the "cluster" still uses the old data during failover, when multiple salve serve clients.
Sentinel Parallel-syncs MyMaster 1 # # # #failover过期时间, when failover starts, there is still no failover action triggered during this time, and the current Sentinel will consider this failoer to be unsuccessful. Sentinel Failover-timeout MyMaster 180000------------------------------------------------------------------------------------------- 

Deploying Redis–slave from the server

[Root@redis-2 redis]# cp/data1/redis-2.8.4/redis.conf./redis.conf
[root@redis-2 redis]# cp/data1/redis-2.8.4/ sentinel.conf./slave-sentenel.conf

root@redis-2 redis]# vi redis.conf
----------------------------------- --------------------------------------------------------
# # # #slave  redis.conf######
# # # #启动进程为后台进程
daemonize Yes
# # # #端口
Port 6379
# # # #日志文件路径设置
logfile "/data1/log/redis/redis.log"
# # # # Authorization password, in a secure environment can not set
requirepass 123456        
masterauth 123456
# # # # # IP and port to master IP and port
slaveof 10.133.6.120 6379
# # # #注释指令重命名, if configured you do not need to modify
#rename-command
# # # #开启AOF
appendonly Yes
save " "
slave-read-only Yes
------------------------------------------------------------------------------- ------------
[Root@redis-2 redis]# VI slave-sentenel.conf--------------------------------------------------------------------- ----------------------# # # #slave sentinel.conf # # #启动进程为后台进程 daemonize Yes # #sentinel实例之间的通讯端口 Port 26379 # # # #
Sentinel needs to monitor the master information:<mastername> <masterIP> <masterPort> <quorum>.
The ####<quorum> should be smaller than the number of slave in the cluster, and the master is considered to be odwon ("objective" invalidation) only if at least <quorum> Sentinel instance submits "master invalidation". Sentinel Monitor MyMaster 10.133.6.120 6379 2 # # # #设置日志路径 logfile "/data1/log/redis/sentinel.log" # # # #授权密码, in a safe environment can not set S Entinel Auth-pass MyMaster 123456 # # # #master被当前sentinel实例认定为 "fail" (Sdown) interval Time Sentinel Down-after-milliseconds
MyMaster 30000 # # # #当新master产生时, at the same time "slaveof" to the new master and the number of simultaneous replication slave.
# #在salve执行salveof与同步时, the client request will be terminated.
# #此值较大, which means that the "cluster" terminates the sum and large amount of time the client requests.
# #此值较小 means that the "cluster" still uses the old data during failover, when multiple salve serve clients.
Sentinel Parallel-syncs MyMaster 1 # # # #failover过期时间, when failover starts, there is still no failover action triggered during this time, and the current Sentinel will consider this failoer to be unsuccessful. Sentinel Failover-timeout MyMaster 180000------------------------------------------------------------------------------------------- 
4. Start

The first build must start Redis for master.

Start Master and Master-sentinel:

[Root@redis-1 redis]# redis-server--include/usr/local/redis/redis.conf
[root@redis-2 redis]#/data1/ Redis-2.8.4/src/redis-sentinel/usr/local/redis/master-sentinel.conf

Start slave and Slave-sentinel:

[Root@redis-1 redis]# redis-server--include/usr/local/redis/redis.conf
[root@redis-2 redis]#/data1/ Redis-2.8.4/src/redis-sentinel/usr/local/redis/slave-sentinel.conf
5. Testing

View Master Status

[Root@redis-1 redis]# redis-cli-h 10.133.6.120-p 6379


View slaver Status

[Root@redis-2 redis]# redis-cli-h 127.0.0.1-p 6379


1) Close Master

10.133.6.120:6379> shutdown


At this point, the slave status (migration will take 1-2 minutes to wait)

Reboot Master, status

[Root@redis-1 redis]# Redis-server--include/usr/local/redis/redis.conf

Implements the migration

2) Turn off slave (the Redis status is master at this point slave)
The status information is as follows:

Close slave

127.0.0.1:6379> shutdown


At this point the master status

Restart Slaver, status

[Root@redis-2 redis]# Redis-server--include/usr/local/redis/redis.conf

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.