Redis Sentinel mechanism []

I. Overview

What is the mechanism Sentinel

  • Redis sentinels (Sentinel) Redis system for managing a plurality of servers, the system performs the following three tasks:
    • Monitoring (Monitoring): Sentinel (sentinel) will continue to check if your Master and Slave functioning properly.
    • Remind (Notification): When monitoring a Redis problems, Sentinel (sentinel) can send notifications to the administrator or other applications via the API.
    • Automatic failover (Automatic failover): When a Master does not work, Sentinel (sentinel) will start an automatic failover operation, it will be one of the Slave Master failure upgraded to the new Master, and let the failure of other Slave Master copy to the new Master; when a client tries to connect Master failure, the cluster will return to the client terminal address of the new Master of such cluster may be used in place of Master Master failure.
  • Sentinel (sentinel) is a distributed system, you can run multiple Sentry (sentinel) in a process architecture, these processes use rumors protocol (gossipprotocols) to receive information about whether the Master off the assembly line, and use the voting agreement (agreement protocols ) to decide whether to perform automatic failover, as well as the new select which Slave Master.
  • Each sentinel (Sentinel) will, master, slave timing of transmission to other Sentry (Sentinel) message to confirm whether the other "living", if it is found not to respond to each other (configurable) at the specified time, the time being that the other side has been linked (so-called "subjective view down" subjective Down, referred sdown).
  • If the "sentinel group" in the most sentinel, reported a master did not respond, the system was considered the master "completely dead" (ie: real down machine on objective, Objective Down, referred odown), through a certain algorithm vote, from the rest of the slave node, selected from a lift to master, and then automatically modify the configuration.
  • Although Sentinel (sentinel) released by the given --sentinel option when a single executable file redis-sentinel, but it is actually just a Redis server in a special mode of operation, you can start a general Redis server start Sentinel (sentinel).
  • Sentinel (sentinel) of some of the design ideas and is very similar zookeeper

15560916690088
155609

Second, the environment configuration

2.1 Virtual Machine

  • Sentinel mechanism of action: management cluster redis, election monitoring strategy, heartbeat, (a stand-alone application)
  • Configure the environment to ensure that three different servers to achieve redis clusters (clone)
  • Install a direct, all behind two clones
192.168.212.145 主redis服务器
192.168.212.147 从redis
192.168.212.148 从redis

2.2 Installation Redis


#下载Redis安装包
wget http://download.redis.io/releases/redis-3.2.9.tar.gz
#解压Redis安装包
tar -zxvf redis-3.2.9.tar.gz
#安装
cd redis-3.2.9
make
cd src
make install PREFIX=/usr/local/redis
#移动配置文件到安装目录下
cd ../
mkdir /usr/local/redis/etc
mv redis.conf /usr/local/redis/etc

#配置redis为后台启动修改密码
vi /usr/local/redis/etc/redis.conf
# 将daemonize no 改成daemonize yes
# requirepass 123

#开启redis
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf 

#连接Redis客户端
./redis-cli -h 127.0.0.1 -p 6379 -a "123456" 
PING #结果表示成功

#关闭防火墙

#临时关闭
systemctl stop firewalld
#禁止开机启动防火墙
systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.


#停止Redis服务
./redis-cli -h 127.0.0.1 -p 6379 -a "123456"  shutdown

#修改redis.conf
#开启外网访问 ,注释掉下面的
#bind 127.0.0.1 

#注意事项:
#1.修改redis为后台启动进程
# 将daemonize no 改成daemonize yes
#2.允许IP地址访问
#注释掉#bind 127.0.0.1
#3.修改redis启动密码
# requirepass 12356

2.3 configure the master copy from

Configure the master-slave replication : slaveof from the server to the primary server, and set the access password

After connecting the client can enter info command to view the current information redis, 1 shows that 145-based servers, 148 server from the server:

  • The most important step in the cluster: Close all firewall

  • If the time in the cluster, before the main redis password synchronization must be directed. All server clusters must be open password

2.4 Configuring Sentinel

We configured sentry on the server:

#实现步骤:
#1.将redis根目录下的sentinel.conf 拷贝到etc目录
cp sentinel.conf  /usr/local/redis/etc
#2.修改sentinel.conf配置文件
sentinel monitor mymaster  192.168.110.133 6379 1  #主节点 名称 IP 端口号 选举次数
sentinel auth-pass mymaster 123456  
#3. 修改心跳检测 30毫秒
sentinel down-after-milliseconds mymaster 30
#4.
sentinel parallel-syncs mymaster 2 # 做多少合格节点

2.5 Test

  1. Start Sentinel
  2. Start redis, to start the main redis, after starting from redis (or else it means that the main sentry redis hung up)
#1. 进入到bin目录中,启动哨兵模式
./redis-server /usr/local/redis/etc/sentinel.conf --sentinel &
  • This time started three redis server if the primary server 145 and hung up, it will be transferred to the master server from the server if the primary server before it becomes from the server. (If in a cluster when the previous main redis synchronize passwords must point to all servers in the cluster must be open password)

2.6 doubt (to be resolved)

  Now I do not know, when configuring Sentinel is easily configured on servers that are, or configured on the server, and if there is a server configuration sentry hung up, then what will happen then?

Guess you like

Origin www.cnblogs.com/haoworld/p/redis-shao-bing-ji-zhi.html