Redis down how to do? Sentinel mechanism?

Downtime: Downtime is computer terminology, we simply spoken inside the stopped machine is called a down machine, converted to a Chinese character is "down", but a lot of people are called "crash" / "crash." It is simply a server out of service.

redis generally do distributed cache in the enterprise, can greatly reduce the cost of high concurrency. If the enterprise is only one redis, will definitely lead to data loss, can not save

redis cluster: two for a group, a host, a backup server, the host usually work, preparing machine does not work, the preparation machine every few seconds to send a ping to the host, the host sends a normal operation when peng to the standby machine, if you do not return pang, might ping three times in a row, do not return then the machine will be on standby, prepared machine, there are whole host of content, this is called the heartbeat detection mechanism (the role of high-availability), master-slave hot standby

slot slot redis worth in the range 0-16383, a total of 16,384 slot values ​​that can be assigned to each group of slot machines (currently in the country has not reached such a large cluster)

When we deposit redis data using key, value key-value pairs stored value, then the key will be stored before use crc16 algorithm to calculate, will come to value a pure numbers, and divide that number by taking the remainder 16384, the remainder falls within the scope of the slot will be worth the groove key, value stored to the corresponding machine, acquiring data when the same is true. Load balancing played a role, the more uniform the more the number of clusters, the overall capacity than the stand-alone version of the larger capacity, that is expansion.

Now is that multiple reids or Redis cluster, server downtime to how to solve?

You need to be divided into downtime mode in the main distinction from the point of view:
1, redis down from the how to solve?
  Configure the master was from redis configuration from the time replication, reads from the Lord redis redis from the Lord the operation logs from the master copy to achieve.
    1. As soon as the restart from the redis, and then connecting the master can
    2. If the data is done from top redis persistent, can be directly connected to the top of the main, long achieve incremental backups

2, Lord redis down how to solve?
  First make sure to do persistence, persistence if not done, restart the Lord redis will result in data loss.
    1. From the first upgrade based redis redis. Slave of one execution command
    2. The original master can be restarted, as from the redis, connected to the main shots from above redis replication

Is not the above operation looks very complicated, in fact, you can use Redis Sentinel provides mechanisms to simplify the above operation.

Sentinel Redis is monitoring the operation of the system, it is an independent process, has two functions:

  • Monitoring the primary database and whether the database is running from normal;
  • Automatic master database after the failure data from the main database conversion;

Single sentinel architecture:
Here Insert Picture Description
a plurality of sentinel architecture:
Here Insert Picture Description
high availability framework
Here Insert Picture Description
Here Insert Picture Description
Sentinel configuration:

Redis replication in sentinel.conf, configured according to the situation

#当前Sentinel服务运行的端口
port 26379

#Sentinel服务运行时使用的临时文件夹
dir /tmp

#sentinel连接的主redis, 此redis连接端IP端口是172.17.0.1 6379
#将此redis判断为失效至少需要1个 Sentinel进程的同意, 只要同意Sentinel的数量不达标,自动failover就不会执行
sentinel monitor master 172.17.0.1 6379 1

#指定了在执行故障转移时,最多可以由多少个从Redis实例在同步新的主实例,在从Redis实例较多的情况下这个数字越小,同步的时间越长
#完成故障转移所需的时间就越长
sentinel parallel-syncs master 1

#如果未在18000ms内完成故障迁移,就默认未失败
sentinel failover-timeout master 180000

#redis的sentinel的日志
logfile "/var/log/sentinel_log.log"

Sentinel can be used to build highly available server, Sentinel mode also provides other functions, such as monitoring, notification, provided configured as a client and so on.

Why Redis time online deployment generally do not set your password?

Here Insert Picture Description

The figure can be seen when customers visit the Web site is to enter the domain name resolver, the domain name resolver will resolve URLs to static ip, this is actually a static ip load balancer (Note: That is a load balancer can access the network You can also access the external network), the load balancer will come to find the corresponding server module according to project needs, and then find the corresponding server program module mysql cluster or redis clusters, tomcat, including network and cluster are generally among so do not be redis password.

Reference article:
https://www.cnblogs.com/Infernal/p/11140633.html
https://blog.csdn.net/qq_42234033/article/details/82998653
https://blog.csdn.net/py_tamir/article / details / 82555338

Published 134 original articles · won praise 88 · views 70000 +

Guess you like

Origin blog.csdn.net/belongtocode/article/details/104325782