WO2022036901A1 - Implementation method and apparatus for redis replica set - Google Patents

Implementation method and apparatus for redis replica set Download PDF

Info

Publication number
WO2022036901A1
WO2022036901A1 PCT/CN2020/130220 CN2020130220W WO2022036901A1 WO 2022036901 A1 WO2022036901 A1 WO 2022036901A1 CN 2020130220 W CN2020130220 W CN 2020130220W WO 2022036901 A1 WO2022036901 A1 WO 2022036901A1
Authority
WO
WIPO (PCT)
Prior art keywords
sentinel
agent
redis
master
server
Prior art date
Application number
PCT/CN2020/130220
Other languages
French (fr)
Chinese (zh)
Inventor
于占水
Original Assignee
紫光云(南京)数字技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 紫光云(南京)数字技术有限公司 filed Critical 紫光云(南京)数字技术有限公司
Publication of WO2022036901A1 publication Critical patent/WO2022036901A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/16Error detection or correction of the data by redundancy in hardware
    • G06F11/20Error detection or correction of the data by redundancy in hardware using active fault-masking, e.g. by switching out faulty elements or by switching in spare elements
    • G06F11/202Error detection or correction of the data by redundancy in hardware using active fault-masking, e.g. by switching out faulty elements or by switching in spare elements where processing functionality is redundant
    • G06F11/2023Failover techniques
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3003Monitoring arrangements specially adapted to the computing system or computing system component being monitored
    • G06F11/3006Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system is distributed, e.g. networked systems, clusters, multiprocessor systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3055Monitoring arrangements for monitoring the status of the computing system or of the computing system component, e.g. monitoring if the computing system is on, off, available, not available

Definitions

  • the present invention relates to the technical field of databases, and in particular, to a method and device for implementing a Redis replica set.
  • Scheme 1 (as shown in Figure 1) is one master, one slave and two sentinels, M1 and R1 are the master and slave Redis respectively, and S1 and S2 are high-availability sentinels;
  • Scheme 2 (as shown in Figure 2) is one Master-slave three sentinels, if deployed separately, three sentinels will take up more resources; if deployed together with Redis, it will also encounter the problem of failover;
  • solution 3 (as shown in Figure 3) is one master, two slaves, and three sentinels , is still not the minimum configuration, and consumes more resources; in addition, without an agent, users need to perceive all node information such as IP, PORT, etc., and all administrator operations such as FLUSH can be performed through the client, which brings security risks.
  • the present invention proposes a method and device for implementing a Redis replica set, so as to overcome the above-mentioned technical problems existing in the related art.
  • a method for implementing a Redis replica set comprising the following steps:
  • the agent obtains the latest structure information of the Redis database by using a preset rule, and routes the request correctly.
  • a preset method is used to detect the activity of the agent, and the realization of the high availability of the agent specifically includes the following steps: using the preset software KeepAlived to control the VIP offset by detecting the agent activity, so as to realize the high availability of the agent.
  • the agent in the S1 is the open source agent Predixy
  • the open source agent Predixy can shield some password reset and parameter modification commands, and the user does not need to perceive the underlying architecture deployment information, and connecting the agent is like connecting to a single database. Redis, which can implement subsequent replica set expansion.
  • implementing automatic failover, manual master-slave node switching, sentinel automatic switching, faulty node self-rescue and split-brain multi-master detection through preset rules in S2 specifically includes the following steps:
  • the sentinel runs on the slave node, and periodically obtains the status of the database Redis and is responsible for the automatic failover of the database Redis and manual master-slave server switching;
  • the server is the main node server and there is a sentinel
  • the sentinel process is stopped, the agent process configuration file soft connection points to the local, the modified soft connection points to the remote agent configuration file, and the agent is restarted;
  • the agent process configuration file soft connection points to the remote end, modify the soft connection to point to the local agent configuration file, and restart the agent;
  • the PING command returns an error, it is regarded as a slave node server, and it is accumulated once every cycle. If it still fails 5 times, the soft connection of the proxy configuration file is modified to point to the local configuration file.
  • the preset rule for the agent to obtain the latest structure information of the database Redis in the S3 refers to that the agent periodically obtains from the sentinel.
  • an electronic device includes a memory and a processor, the memory stores an implementation program of a Redis replica set that can run on the processor, the When the implementation program of the Redis replica set is executed by the processor, the following steps are implemented:
  • the agent obtains the latest structure information of the Redis database by using a preset rule, and routes the request correctly.
  • a preset method is used to detect the activity of the agent, and the realization of the high availability of the agent specifically includes the following steps: using the preset software KeepAlived to control the VIP offset by detecting the agent activity, so as to realize the high availability of the agent.
  • implementing automatic failover, manual master-slave node switching, sentinel automatic switching, faulty node self-rescue and split-brain multi-master detection through preset rules in S2 specifically includes the following steps:
  • the sentinel runs on the slave node, and periodically obtains the status of the database Redis and is responsible for the automatic failover of the database Redis and manual master-slave server switching;
  • the server is the main node server and there is a sentinel
  • the sentinel process is stopped, the agent process configuration file soft connection points to the local, the modified soft connection points to the remote agent configuration file, and the agent is restarted;
  • the agent process configuration file soft connection points to the remote end, modify the soft connection to point to the local agent configuration file, and restart the agent;
  • the PING command returns an error, it is regarded as a slave node server, and it is accumulated once every cycle. If it still fails 5 times, the soft connection of the proxy configuration file is modified to point to the local configuration file.
  • the beneficial effects of the present invention are as follows: through the coordinated use of the components Proxy, KeepAlived, Redis-server, Redis-sentinel and Check-sentinel scripts, the present invention can use the lowest-configured Redis to realize the high-availability scheme, which not only effectively solves the problem of brain It also effectively solves the multi-master problem after the virtual machine is started.
  • the addition of the proxy can provide a kind of protection for Redis, such as the shielding of performance loss commands and the client connection full of Redis. Cause Redis to exit abnormally, etc.
  • Fig. 1 is the schematic diagram of the construction method of Redis replica set scheme 1 in the prior art
  • Fig. 2 is a schematic diagram of the construction method of Redis replica set solution 2 in the prior art
  • FIG. 3 is a schematic diagram of the construction method of Redis replica set solution 3 in the prior art
  • FIG. 4 is a schematic flowchart of a method for implementing a Redis replica set according to an embodiment of the present invention
  • Fig. 5 is a schematic diagram of a principle framework in a method for implementing a Redis replica set according to an embodiment of the present invention.
  • a method and apparatus for implementing a Redis replica set are provided.
  • the S1 specifically includes the following steps: using the preset software KeepAlived to control the VIP offset by detecting the activity of the proxy (Proxy), so as to realize the high availability of the proxy.
  • the agent in the S1 is the open source agent Predixy, which can shield some password reset, parameter modification and loss performance commands such as SCAN, KEYS and other commands, and the user does not need to perceive the underlying architecture deployment information, connect
  • the agent is like connecting to a single database Redis, which can realize subsequent replica set expansion.
  • the S2 specifically includes the following steps:
  • the sentinel runs on the slave node, and periodically obtains the status of the database Redis and is responsible for the automatic failover of the database Redis and manual master-slave server switching;
  • the failover in S21 includes the following steps:
  • the election principle for converting the slave node server to the master node server is as follows: first, delete the nodes in the list.
  • the slave node server in offline or disconnected state ensures that all servers are online; then delete the server that has not responded to the leading sentinel in the last 5 seconds to ensure that all servers can communicate normally; finally delete the offline server.
  • the master node server disconnects the slave node server that exceeds the preset time, and is used to filter out the slave database of newer data. After deletion, the slave node server with the highest priority and the largest replication offset will be set first. If it cannot be selected, the slave node server with the smallest running ID will be selected;
  • the sentinel When a new master node server is elected, the sentinel will send the INFO command at a frequency of once per second.
  • the upgraded role attribute is upgraded from slave to master, it is considered to have been upgraded to the master node server.
  • the old master node server has been offline, so the settings are configured in the old master node server object of the leading sentinel.
  • the sentinel will reissue the SLAVEOF command.
  • the Check-sentinel script in S22 is triggered periodically, such as every 3 seconds, as follows:
  • the server is the main node server and there is a sentinel
  • the sentinel process is stopped, the agent process configuration file soft connection points to the local, the modified soft connection points to the remote agent configuration file, and the agent is restarted;
  • the agent process configuration file soft connection points to the remote end, modify the soft connection to point to the local agent configuration file, and restart the agent;
  • the S22 also includes the implementation of automatic switching of sentinels (because the faulty sentinel will be responsible for switching, after the switch, the Redis role and the sentinel only run on the slave node, which is inconsistent, so the sentinel needs to be switched; the sentinel runs on the slave node, because the master node. If the service fails to start after 3 attempts for self-rescue of the faulty node, an alarm email will be sent, and if a split-brain multi-master appears, the Redis process with a long running time will be killed accordingly.
  • the agent obtains the latest structure information of the Redis database by using a preset rule, and routes the request correctly.
  • the preset rule for the agent to obtain the latest structure information of the database Redis in S3 refers to the agent periodically obtains from the sentinel, and the information includes information such as status/role.
  • an electronic device is also provided.
  • the electronic device may be a computer or a server.
  • the electronic device includes at least a memory, a processor, a communication bus, and a network interface.
  • the memory includes at least one type of readable storage medium
  • the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (eg, SD or DX memory, etc.), magnetic memory, magnetic disk, optical disk, and the like.
  • the memory may in some embodiments be an internal storage unit of an electronic device, such as a hard disk of the electronic device.
  • the memory can also be an external storage device of the electronic device, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, and a flash memory equipped on the electronic device.
  • Card Flash Card
  • the memory may also include both an internal storage unit of the electronic device and an external storage device.
  • the memory can not only be used to store application software installed in the electronic device and various types of data, such as the code of the implementation program of the Redis replica set, etc., but also can be used to temporarily store the data that has been output or will be output.
  • the processor may be a central processing unit (CPU), controller, microcontroller, microprocessor or other data processing chip for executing program codes or processing data stored in the memory.
  • CPU central processing unit
  • controller microcontroller
  • microprocessor microprocessor or other data processing chip for executing program codes or processing data stored in the memory.
  • the communication bus is used to realize the connection communication between these components.
  • the network interface may include a standard wired interface and a wireless interface (such as a WI-FI interface), which is generally used to establish a communication connection between the electronic device and other electronic devices.
  • a standard wired interface such as a WI-FI interface
  • WI-FI interface wireless interface
  • the electronic device may further include a user interface
  • the user interface may include a display (Display), an input unit such as a keyboard (Keyboard), and an optional user interface may further include a standard wired interface and a wireless interface.
  • the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode, organic light-emitting diode) touch device, and the like.
  • the display may also be appropriately called a display screen or a display unit, which is used for displaying information processed in the electronic device and for displaying a visual user interface.
  • the electronic device includes a memory and a processor, the memory stores an implementation program of a Redis replica set that can run on the processor, and the implementation program of the Redis replica set is executed by the processor. The following steps are implemented :
  • the S1 using a preset method to detect the activity of the agent to achieve high availability of the agent; wherein, the S1 specifically includes the following steps: using the preset software KeepAlived to detect the agent activity to control the VIP offset to achieve the high availability of the agent.
  • the S2 specifically includes the following steps: S21. After the replica set is initialized, Sentinel runs on the slave node, and periodically obtains the status of database Redis and is responsible for automatic failover of database Redis and manual master-slave server switching; S22. When master-slave switching is completed, the periodic triggering of the Check-sentinel script will detect the sentinel running The node does not match the database Redis role, and the sentinel will be correspondingly switched to the current slave node server by the Check-sentinel script.
  • periodically triggering the Check-sentinel script in S22 specifically includes the following steps:
  • the server is the main node server and there is a sentinel
  • the sentinel process is stopped, the agent process configuration file soft connection points to the local, the modified soft connection points to the remote agent configuration file, and the agent is restarted;
  • the agent process configuration file soft connection points to the remote end, modify the soft connection to point to the local agent configuration file, and restart the agent;
  • the PING command returns an error, it is regarded as a slave node server, and it is accumulated once every cycle. If it still fails 5 times, the soft connection of the proxy configuration file is modified to point to the local configuration file.
  • the agent obtains the latest structure information of the Redis database by using a preset rule, and routes the request correctly.
  • Proxy proxy
  • KeepAlived highly available and reliable software
  • Redis-server node
  • Redis-sentinel sentinel
  • Check-sentinel scripts The combined use of Redis enables the present invention to use the lowest configuration of Redis to implement a high-availability solution, which not only effectively solves the problem of split-brain and virtual machine downtime that cannot be switched, but also effectively solves the multi-master problem after the virtual machine is started.
  • the addition of the proxy can provide a kind of protection for Redis, such as the shielding of performance loss commands and the abnormal exit of Redis caused by the client connection full of Redis.

Abstract

An implementation method and apparatus for a Redis replica set, the method comprising the following steps: S1. using a preset method to detect the activity of a proxy, and achieving high availability for the proxy; S2. achieving automatic failover, manual master-slave node switching, automatic sentinel switching, self-rescue of failed nodes, and split-brain multi-master detection by means of preset rules; and S3. the proxy obtains the latest structure information of a database Redis by using a preset rule, and corrects a routing request. The beneficial effects are: by means of collaboratively using Proxy, KeepAlived, Redis-server, Redis-sentinel and Check-sentinel scripts, the lowest configuration Redis can be used to achieve a high-availability solution, which not only effectively solves the problem in which split brain and virtual machine downtime cannot be switched, but also effectively solves the multi-master problem after a virtual machine is started. At the same time, the addition of the proxy can provide protection for Redis, such as the shielding of performance loss commands and the client connection full filling of Redis causing Redis to exit abnormally and so on.

Description

一种Redis副本集的实现方法及装置A method and device for implementing a Redis replica set 技术领域technical field
本发明涉及数据库技术领域,具体来说,涉及一种Redis副本集的实现方法及装置。The present invention relates to the technical field of databases, and in particular, to a method and device for implementing a Redis replica set.
背景技术Background technique
目前网络博客或许多项目应用中,Redis副本集很多是一主两从三哨兵、多哨兵或一主一从两哨兵的搭建方式,很少谈及一主一从一哨兵最低配的搭建方式。常见的方案如下:方案一(如图1所示)为一主一从两哨兵,M1、R1分别为主从Redis,S1、S2为高可用哨兵;方案二(如图2所示)为一主一从三哨兵,如单独部署,3个哨兵会占用更多的资源;与Redis部署在一起,同样会遇到故障切换问题;方案三(如图3所示)为一主两从3哨兵,依然不是最低配,耗费更多的资源;另外没有代理,用户需要感知所有节点信息如IP,PORT等,通过客户端可以执行所有管理员操作如FLUSH等,带来安全隐患。At present, in online blogs or many project applications, many Redis replica sets are built with one master, two slaves, three sentinels, multiple sentinels, or one master, one slave, and two sentinels. The minimum configuration method of one master, one slave, and one sentinel is rarely mentioned. The common schemes are as follows: Scheme 1 (as shown in Figure 1) is one master, one slave and two sentinels, M1 and R1 are the master and slave Redis respectively, and S1 and S2 are high-availability sentinels; Scheme 2 (as shown in Figure 2) is one Master-slave three sentinels, if deployed separately, three sentinels will take up more resources; if deployed together with Redis, it will also encounter the problem of failover; solution 3 (as shown in Figure 3) is one master, two slaves, and three sentinels , is still not the minimum configuration, and consumes more resources; in addition, without an agent, users need to perceive all node information such as IP, PORT, etc., and all administrator operations such as FLUSH can be performed through the client, which brings security risks.
然而,对于上述方案一而言,其存在以下缺陷:1)无法解决网络故障后脑裂问题;2)如其中某一哨兵进程宕掉或某一虚机宕掉后,故障切换无法顺利进行;3)客户端需要明确底层部署架构信息如IP,PORT等,且可以执行一切管理员操作如FLUSH等。However, for the above scheme 1, it has the following defects: 1) it cannot solve the problem of split brain after a network failure; 2) if one of the sentinel processes is down or a certain virtual machine is down, the failover cannot be carried out smoothly; 3 ) The client needs to clear the underlying deployment architecture information such as IP, PORT, etc., and can perform all administrator operations such as FLUSH.
对于上述方案二而言,增加一个哨兵;如三个哨兵单独部署为带来额外的资源耗费,哨兵进程只是故障切换,不会占用太多资源;如哨兵进程与Redis部署在一起,同样会有两个明显的缺点:1)如其中哨兵多的一方虚机宕掉后,故障切换无法顺利进行;2)客户端需要明确底层部署架构信息如IP,PORT等,且可以执行一切管理员操作如FLUSH等。For the above scheme 2, add a sentinel; if three sentinels are deployed separately, it will cause additional resource consumption, and the sentinel process is just a failover and will not occupy too many resources; if the sentinel process is deployed together with Redis, there will also be Two obvious shortcomings: 1) If the virtual machine with many sentinels goes down, the failover cannot be carried out smoothly; 2) The client needs to clarify the underlying deployment architecture information such as IP, PORT, etc., and can perform all administrator operations such as FLUSH et al.
对于上述方案三而言,一主两从三哨兵,额外增加一台物理资源,已然不是最低配。For the above scheme 3, one master, two slaves and three sentinels, adding an additional physical resource is not the minimum configuration.
针对相关技术中的问题,目前尚未提出有效的解决方案。For the problems in the related technologies, no effective solutions have been proposed so far.
发明内容SUMMARY OF THE INVENTION
针对相关技术中的问题,本发明提出一种Redis副本集的实现方法及装置,以克服现有相关技术所存在的上述技术问题。Aiming at the problems in the related art, the present invention proposes a method and device for implementing a Redis replica set, so as to overcome the above-mentioned technical problems existing in the related art.
为此,本发明采用的具体技术方案如下:For this reason, the concrete technical scheme that the present invention adopts is as follows:
根据本发明的一个方面,提供了一种Redis副本集的实现方法,包括以下步骤:According to an aspect of the present invention, a method for implementing a Redis replica set is provided, comprising the following steps:
S1、采用预设方法对代理进行活性检测,实现代理高可用;S1. Use a preset method to detect the activity of the agent, so as to realize the high availability of the agent;
S2、通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测;S2. Implement automatic failover, manual master-slave node switching, sentinel automatic switching, fault node self-rescue and split-brain multi-master detection through preset rules;
S3、所述代理采用预设规则获取数据库Redis最新结构信息,正确路由请求。S3. The agent obtains the latest structure information of the Redis database by using a preset rule, and routes the request correctly.
进一步的,所述S1中采用预设方法对代理进行活性检测,实现代理高可用具体包括以下步骤:采用预设的软件KeepAlived通过检测代理活性来控制VIP偏移,实现所述代理高可用。Further, in the S1, a preset method is used to detect the activity of the agent, and the realization of the high availability of the agent specifically includes the following steps: using the preset software KeepAlived to control the VIP offset by detecting the agent activity, so as to realize the high availability of the agent.
进一步的,所述S1中的所述代理为开源代理Predixy,所述开源代理Predixy可屏蔽一些密码重置及参数修改的命令,且用户无需感知底层架构部署信息,连接所述代理犹如连接单个数据库Redis,可以实现后续副本集扩展。Further, the agent in the S1 is the open source agent Predixy, the open source agent Predixy can shield some password reset and parameter modification commands, and the user does not need to perceive the underlying architecture deployment information, and connecting the agent is like connecting to a single database. Redis, which can implement subsequent replica set expansion.
进一步的,所述S2中通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测具体包括以下步骤:Further, implementing automatic failover, manual master-slave node switching, sentinel automatic switching, faulty node self-rescue and split-brain multi-master detection through preset rules in S2 specifically includes the following steps:
S21、当副本集初始化后,哨兵运行于从节点,并周期性获取数据库Redis的状态及负责数据库Redis的自动故障转移和手动主从节点服务器的切换;S21. After the replica set is initialized, the sentinel runs on the slave node, and periodically obtains the status of the database Redis and is responsible for the automatic failover of the database Redis and manual master-slave server switching;
S22、当主从切换完成后,周期触发Check-sentinel脚本会检测到哨兵运行节点与数据库Redis角色不匹配,进而哨兵会被所述Check-sentinel脚本相应的切换到当下从节点服务器中。S22. After the master-slave switch is completed, the periodic triggering of the Check-sentinel script will detect that the sentinel running node does not match the database Redis role, and then the sentinel will be correspondingly switched to the current slave node server by the Check-sentinel script.
进一步的,所述S22中周期性触发Check-sentinel脚本具体包括以 下步骤:Further, periodically triggering Check-sentinel script in described S22 specifically comprises the following steps:
当服务器为主节点服务器,且存在哨兵,则停止所述哨兵进程,所述代理进程配置文件软连接指向本地,修改软连接指向远端代理配置文件,并重启代理;When the server is the main node server and there is a sentinel, the sentinel process is stopped, the agent process configuration file soft connection points to the local, the modified soft connection points to the remote agent configuration file, and the agent is restarted;
当服务器为从节点服务器,且不存在哨兵,则启动哨兵进程,所述代理进程配置文件软连接指向远端,修改软连接指向本地代理配置文件,并重启代理;When the server is a slave node server and there is no sentinel, start the sentinel process, the agent process configuration file soft connection points to the remote end, modify the soft connection to point to the local agent configuration file, and restart the agent;
当PING命令返回错误时,则视为从节点服务器,每周期累加一次,若5次依然失败,则修改所述代理配置文件软连接指向本地配置文件。When the PING command returns an error, it is regarded as a slave node server, and it is accumulated once every cycle. If it still fails 5 times, the soft connection of the proxy configuration file is modified to point to the local configuration file.
进一步的,所述S3中所述代理获取数据库Redis最新结构信息的预设规则指所述代理周期性的从哨兵获取。Further, the preset rule for the agent to obtain the latest structure information of the database Redis in the S3 refers to that the agent periodically obtains from the sentinel.
根据本发明的另一个方面,还提供了一种电子装置,所述电子装置包括存储器和处理器,所述存储器上存储有可在所述处理器上运行的Redis副本集的实现程序,所述Redis副本集的实现程序被所述处理器执行时实现如下步骤:According to another aspect of the present invention, an electronic device is also provided, the electronic device includes a memory and a processor, the memory stores an implementation program of a Redis replica set that can run on the processor, the When the implementation program of the Redis replica set is executed by the processor, the following steps are implemented:
S1、采用预设方法对代理进行活性检测,实现代理高可用;S1. Use a preset method to detect the activity of the agent, so as to realize the high availability of the agent;
S2、通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测;S2. Implement automatic failover, manual master-slave node switching, sentinel automatic switching, fault node self-rescue and split-brain multi-master detection through preset rules;
S3、所述代理采用预设规则获取数据库Redis最新结构信息,正确路由请求。S3. The agent obtains the latest structure information of the Redis database by using a preset rule, and routes the request correctly.
进一步的,所述S1中采用预设方法对代理进行活性检测,实现代理高可用具体包括以下步骤:采用预设的软件KeepAlived通过检测代理活性来控制VIP偏移,实现所述代理高可用。Further, in the S1, a preset method is used to detect the activity of the agent, and the realization of the high availability of the agent specifically includes the following steps: using the preset software KeepAlived to control the VIP offset by detecting the agent activity, so as to realize the high availability of the agent.
进一步的,所述S2中通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测具体包括以下步骤:Further, implementing automatic failover, manual master-slave node switching, sentinel automatic switching, faulty node self-rescue and split-brain multi-master detection through preset rules in S2 specifically includes the following steps:
S21、当副本集初始化后,哨兵运行于从节点,并周期性获取数据库Redis的状态及负责数据库Redis的自动故障转移和手动主从节点服务器的切换;S21. After the replica set is initialized, the sentinel runs on the slave node, and periodically obtains the status of the database Redis and is responsible for the automatic failover of the database Redis and manual master-slave server switching;
S22、当主从切换完成后,周期触发Check-sentinel脚本会检测到 哨兵运行节点与数据库Redis角色不匹配,进而哨兵会被所述Check-sentinel脚本相应的切换到当下从节点服务器中。S22. When the master-slave switch is completed, the periodic triggering of the Check-sentinel script will detect that the sentinel running node does not match the database Redis role, and then the sentinel will be correspondingly switched to the current slave node server by the Check-sentinel script.
进一步的,所述S22中周期性触发Check-sentinel脚本具体包括以下步骤:Further, periodically triggering the Check-sentinel script in S22 specifically includes the following steps:
当服务器为主节点服务器,且存在哨兵,则停止所述哨兵进程,所述代理进程配置文件软连接指向本地,修改软连接指向远端代理配置文件,并重启代理;When the server is the main node server and there is a sentinel, the sentinel process is stopped, the agent process configuration file soft connection points to the local, the modified soft connection points to the remote agent configuration file, and the agent is restarted;
当服务器为从节点服务器,且不存在哨兵,则启动哨兵进程,所述代理进程配置文件软连接指向远端,修改软连接指向本地代理配置文件,并重启代理;When the server is a slave node server and there is no sentinel, start the sentinel process, the agent process configuration file soft connection points to the remote end, modify the soft connection to point to the local agent configuration file, and restart the agent;
当PING命令返回错误时,则视为从节点服务器,每周期累加一次,若5次依然失败,则修改所述代理配置文件软连接指向本地配置文件。When the PING command returns an error, it is regarded as a slave node server, and it is accumulated once every cycle. If it still fails 5 times, the soft connection of the proxy configuration file is modified to point to the local configuration file.
本发明的有益效果为:通过组件Proxy、KeepAlived、Redis-server、Redis-sentinel及Check-sentinel脚本的配合使用,使得本发明可以采用最低配的Redis来实现高可用方案,不仅有效地解决了脑裂及虚机宕机无法切换的问题,而且还有效地解决了虚机启动后的多主问题,同时代理的加入能够对Redis提供一种保护如性能损耗命令的屏蔽及客户端连接打满Redis导致Redis异常退出等。The beneficial effects of the present invention are as follows: through the coordinated use of the components Proxy, KeepAlived, Redis-server, Redis-sentinel and Check-sentinel scripts, the present invention can use the lowest-configured Redis to realize the high-availability scheme, which not only effectively solves the problem of brain It also effectively solves the multi-master problem after the virtual machine is started. At the same time, the addition of the proxy can provide a kind of protection for Redis, such as the shielding of performance loss commands and the client connection full of Redis. Cause Redis to exit abnormally, etc.
附图说明Description of drawings
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the accompanying drawings required in the embodiments will be briefly introduced below. Obviously, the drawings in the following description are only some of the present invention. In the embodiments, for those of ordinary skill in the art, other drawings can also be obtained according to these drawings without any creative effort.
图1是现有技术中Redis副本集方案一的搭建方式示意图;Fig. 1 is the schematic diagram of the construction method of Redis replica set scheme 1 in the prior art;
图2是现有技术中Redis副本集方案二的搭建方式示意图;Fig. 2 is a schematic diagram of the construction method of Redis replica set solution 2 in the prior art;
图3是现有技术中Redis副本集方案三的搭建方式示意图;FIG. 3 is a schematic diagram of the construction method of Redis replica set solution 3 in the prior art;
图4根据本发明实施例的一种Redis副本集的实现方法的流程示意图;4 is a schematic flowchart of a method for implementing a Redis replica set according to an embodiment of the present invention;
图5是根据本发明实施例的一种Redis副本集的实现方法中原理框 架示意图。Fig. 5 is a schematic diagram of a principle framework in a method for implementing a Redis replica set according to an embodiment of the present invention.
具体实施方式detailed description
为进一步说明各实施例,本发明提供有附图,这些附图为本发明揭露内容的一部分,其主要用以说明实施例,并可配合说明书的相关描述来解释实施例的运作原理,配合参考这些内容,本领域普通技术人员应能理解其他可能的实施方式以及本发明的优点,图中的组件并未按比例绘制,而类似的组件符号通常用来表示类似的组件。In order to further illustrate the various embodiments, the present invention provides accompanying drawings, which are part of the disclosure of the present invention, and are mainly used to illustrate the embodiments, and can be used in conjunction with the relevant descriptions in the specification to explain the operation principles of the embodiments. For these, those of ordinary skill in the art will understand other possible implementations and the advantages of the present invention. Components in the figures are not drawn to scale, and similar component symbols are generally used to represent similar components.
根据本发明的实施例,提供了一种Redis副本集的实现方法及装置。According to the embodiments of the present invention, a method and apparatus for implementing a Redis replica set are provided.
现结合附图和具体实施方式对本发明进一步说明,如图4-5所示,根据本发明的一个实施例,提供了一种Redis副本集的实现方法,包括以下步骤:The present invention will now be further described with reference to the accompanying drawings and specific embodiments. As shown in Figures 4-5, according to an embodiment of the present invention, a method for implementing a Redis replica set is provided, including the following steps:
S1、采用预设方法对代理进行活性检测,实现代理高可用;S1. Use a preset method to detect the activity of the agent, so as to realize the high availability of the agent;
其中,所述S1具体包括以下步骤:采用预设的软件KeepAlived通过检测代理(Proxy)活性来控制VIP偏移,实现所述代理高可用。The S1 specifically includes the following steps: using the preset software KeepAlived to control the VIP offset by detecting the activity of the proxy (Proxy), so as to realize the high availability of the proxy.
具体的,所述S1中的所述代理为开源代理Predixy,所述开源代理Predixy可屏蔽一些密码重置、参数修改及损耗性能如SCAN,KEYS等命令,且用户无需感知底层架构部署信息,连接所述代理犹如连接单个数据库Redis,可以实现后续副本集扩展。Specifically, the agent in the S1 is the open source agent Predixy, which can shield some password reset, parameter modification and loss performance commands such as SCAN, KEYS and other commands, and the user does not need to perceive the underlying architecture deployment information, connect The agent is like connecting to a single database Redis, which can realize subsequent replica set expansion.
S2、通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测;S2. Implement automatic failover, manual master-slave node switching, sentinel automatic switching, fault node self-rescue and split-brain multi-master detection through preset rules;
其中,所述S2具体包括以下步骤:Wherein, the S2 specifically includes the following steps:
S21、当副本集初始化后,哨兵运行于从节点,并周期性获取数据库Redis的状态及负责数据库Redis的自动故障转移和手动主从节点服务器的切换;S21. After the replica set is initialized, the sentinel runs on the slave node, and periodically obtains the status of the database Redis and is responsible for the automatic failover of the database Redis and manual master-slave server switching;
具体的,所述S21中的故障转移包括以下步骤:Specifically, the failover in S21 includes the following steps:
在已下线主节点服务器的所有从节点服务器里挑选一个从节点服务器,并将其转换为主节点服务器;优选的,将从节点服务器转换为主节点服务器的选举原则如下:首先删除列表中处于下线或断线状态的从节点服务器,保证所有服务器都处于在线状态;然后删除列表中最近5 秒没有回复领头哨兵的服务器,保证所有服务器都是可以正常通信的;最后删除与已下线的主节点服务器断开超过预设时间的从节点服务器,用来筛选出较新数据的从数据库。当进行删减后,将优先设置优先级高,复制偏移量最大的从节点服务器,如果还无法选出,将选择运行ID最小的从节点服务器;Select a slave node server from all the slave node servers of the offline master node server, and convert it to the master node server; preferably, the election principle for converting the slave node server to the master node server is as follows: first, delete the nodes in the list. The slave node server in offline or disconnected state ensures that all servers are online; then delete the server that has not responded to the leading sentinel in the last 5 seconds to ensure that all servers can communicate normally; finally delete the offline server. The master node server disconnects the slave node server that exceeds the preset time, and is used to filter out the slave database of newer data. After deletion, the slave node server with the highest priority and the largest replication offset will be set first. If it cannot be selected, the slave node server with the smallest running ID will be selected;
当选举出新的主节点服务器时,哨兵会以每秒一次的频率进行INFO命令的发送,当被升级的role属性从slave升级为了master,就认为已经升级成了主节点服务器。当检测到选出的所述从节点服务器已经升级到主节点服务器之后,将继续向其他的所述从节点服务器发送SLAVEOF命令来更改所述主节点服务器的设置。When a new master node server is elected, the sentinel will send the INFO command at a frequency of once per second. When the upgraded role attribute is upgraded from slave to master, it is considered to have been upgraded to the master node server. After detecting that the selected slave node server has been upgraded to the master node server, it will continue to send the SLAVEOF command to the other slave node servers to change the settings of the master node server.
让已下线的主节点服务器的其他从节点服务器复制新的主节点服务器;Let the other slave node servers of the offline master node server replicate the new master node server;
将已下线的主节点服务器设置为新的主节点服务器的从节点服务器,当已下线的主节点服务器重新上线时,会成为新的主节点服务器的从节点服务器。Set the offline master node server as the slave node server of the new master node server. When the offline master node server comes back online, it will become the slave node server of the new master node server.
具体的,旧主节点服务器已经下线,所以设置是配置在领头哨兵的旧主节点服务器对象中,当旧节点主服务器上线后,哨兵会进行SLAVEOF命令的补发。Specifically, the old master node server has been offline, so the settings are configured in the old master node server object of the leading sentinel. When the old node master server goes online, the sentinel will reissue the SLAVEOF command.
S22、当主从切换完成后,周期触发Check-sentinel脚本会检测到哨兵运行节点与数据库Redis角色不匹配,进而哨兵会被所述Check-sentinel脚本相应的切换到当下从节点服务器中。S22. After the master-slave switch is completed, the periodic triggering of the Check-sentinel script will detect that the sentinel running node does not match the database Redis role, and then the sentinel will be correspondingly switched to the current slave node server by the Check-sentinel script.
具体的,所述S22中Check-sentinel脚本为周期性触发,如每3秒,具体如下:Specifically, the Check-sentinel script in S22 is triggered periodically, such as every 3 seconds, as follows:
当服务器为主节点服务器,且存在哨兵,则停止所述哨兵进程,所述代理进程配置文件软连接指向本地,修改软连接指向远端代理配置文件,并重启代理;When the server is the main node server and there is a sentinel, the sentinel process is stopped, the agent process configuration file soft connection points to the local, the modified soft connection points to the remote agent configuration file, and the agent is restarted;
当服务器为从节点服务器,且不存在哨兵,则启动哨兵进程,所述代理进程配置文件软连接指向远端,修改软连接指向本地代理配置文件,并重启代理;When the server is a slave node server and there is no sentinel, start the sentinel process, the agent process configuration file soft connection points to the remote end, modify the soft connection to point to the local agent configuration file, and restart the agent;
当PING命令返回错误(Error)时,则视为从节点服务器,每周 期累加一次,若5次依然失败,则修改所述代理配置文件软连接指向本地配置文件。When the PING command returns an error (Error), it is regarded as a slave node server, and it is accumulated once every cycle. If it still fails 5 times, then modify the proxy configuration file soft connection to point to the local configuration file.
此外,所述S22中还包括实现自动切换哨兵(因为故障哨兵会负责切换,切换后,Redis角色与哨兵只运行在从节点不符合,所以要切换哨兵;哨兵之运行在从节点,因为主节点宕掉,依然可以切换),故障节点自救如尝试3次服务依然启动失败,则会发出告警邮件、及脑裂多主出现会相应杀掉进程运行时间长的Redis进程。In addition, the S22 also includes the implementation of automatic switching of sentinels (because the faulty sentinel will be responsible for switching, after the switch, the Redis role and the sentinel only run on the slave node, which is inconsistent, so the sentinel needs to be switched; the sentinel runs on the slave node, because the master node. If the service fails to start after 3 attempts for self-rescue of the faulty node, an alarm email will be sent, and if a split-brain multi-master appears, the Redis process with a long running time will be killed accordingly.
S3、所述代理采用预设规则获取数据库Redis最新结构信息,正确路由请求。S3. The agent obtains the latest structure information of the Redis database by using a preset rule, and routes the request correctly.
其中,所述S3中所述代理获取数据库Redis最新结构信息的预设规则指所述代理周期性的从哨兵获取,所述信息包括状态/角色等信息。Wherein, the preset rule for the agent to obtain the latest structure information of the database Redis in S3 refers to the agent periodically obtains from the sentinel, and the information includes information such as status/role.
根据本发明的另一个实施例,还提供了一种电子装置。According to another embodiment of the present invention, an electronic device is also provided.
在本实施例中,所述电子装置可以是电脑或服务器。所述电子装置至少包括存储器、处理器、通信总线以及网络接口。In this embodiment, the electronic device may be a computer or a server. The electronic device includes at least a memory, a processor, a communication bus, and a network interface.
其中,存储器至少包括一种类型的可读存储介质,所述可读存储介质包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、磁性存储器、磁盘、光盘等。存储器在一些实施例中可以是电子装置的内部存储单元,例如所述电子装置的硬盘。存储器在另一些实施例中也可以是电子装置的外部存储设备,例如电子装置上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。进一步地,存储器还可以既包括电子装置的内部存储单元也包括外部存储设备。存储器不仅可以用于存储安装于电子装置的应用软件及各类数据,例如Redis副本集的实现程序的代码等,还可以用于暂时地存储已经输出或者将要输出的数据。Wherein, the memory includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (eg, SD or DX memory, etc.), magnetic memory, magnetic disk, optical disk, and the like. The memory may in some embodiments be an internal storage unit of an electronic device, such as a hard disk of the electronic device. In other embodiments, the memory can also be an external storage device of the electronic device, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, and a flash memory equipped on the electronic device. Card (Flash Card), etc. Further, the memory may also include both an internal storage unit of the electronic device and an external storage device. The memory can not only be used to store application software installed in the electronic device and various types of data, such as the code of the implementation program of the Redis replica set, etc., but also can be used to temporarily store the data that has been output or will be output.
处理器在一些实施例中可以是一中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器或其他数据处理芯片,用于运行存储器中存储的程序代码或处理数据。In some embodiments, the processor may be a central processing unit (CPU), controller, microcontroller, microprocessor or other data processing chip for executing program codes or processing data stored in the memory.
通信总线用于实现这些组件之间的连接通信。The communication bus is used to realize the connection communication between these components.
网络接口可选的可以包括标准的有线接口、无线接口(如WI-FI接口),通常用于在电子装置与其他电子设备之间建立通信连接。Optionally, the network interface may include a standard wired interface and a wireless interface (such as a WI-FI interface), which is generally used to establish a communication connection between the electronic device and other electronic devices.
可选地,电子装置还可以包括用户接口,用户接口可以包括显示器(Display)、输入单元比如键盘(Keyboard),可选的用户接口还可以包括标准的有线接口、无线接口。可选地,在一些实施例中,显示器可以是LED显示器、液晶显示器、触控式液晶显示器以及OLED(Organic Light-Emitting Diode,有机发光二极管)触摸器等。其中,显示器也可以适当的称为显示屏或显示单元,用于显示在电子装置中处理的信息以及用于显示可视化的用户界面。Optionally, the electronic device may further include a user interface, and the user interface may include a display (Display), an input unit such as a keyboard (Keyboard), and an optional user interface may further include a standard wired interface and a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode, organic light-emitting diode) touch device, and the like. The display may also be appropriately called a display screen or a display unit, which is used for displaying information processed in the electronic device and for displaying a visual user interface.
所述电子装置包括存储器和处理器,所述存储器上存储有可在所述处理器上运行的Redis副本集的实现程序,所述Redis副本集的实现程序被所述处理器执行时实现如下步骤:The electronic device includes a memory and a processor, the memory stores an implementation program of a Redis replica set that can run on the processor, and the implementation program of the Redis replica set is executed by the processor. The following steps are implemented :
S1、采用预设方法对代理进行活性检测,实现代理高可用;其中,所述S1具体包括以下步骤:采用预设的软件KeepAlived通过检测代理活性来控制VIP偏移,实现所述代理高可用。S1 , using a preset method to detect the activity of the agent to achieve high availability of the agent; wherein, the S1 specifically includes the following steps: using the preset software KeepAlived to detect the agent activity to control the VIP offset to achieve the high availability of the agent.
S2、通过预设法则实现自动故障转移、手动主从节点、切换、哨兵自动切换、故障节点自救及脑裂多主检测;其中,所述S2具体包括以下步骤:S21、当副本集初始化后,哨兵运行于从节点,并周期性获取数据库Redis的状态及负责数据库Redis的自动故障转移和手动主从节点服务器的切换;S22、当主从切换完成后,周期触发Check-sentinel脚本会检测到哨兵运行节点与数据库Redis角色不匹配,进而哨兵会被所述Check-sentinel脚本相应的切换到当下从节点服务器中。S2. Implement automatic failover, manual master-slave node switching, automatic sentinel switching, faulty node self-rescue and split-brain multi-master detection through preset rules; wherein, the S2 specifically includes the following steps: S21. After the replica set is initialized, Sentinel runs on the slave node, and periodically obtains the status of database Redis and is responsible for automatic failover of database Redis and manual master-slave server switching; S22. When master-slave switching is completed, the periodic triggering of the Check-sentinel script will detect the sentinel running The node does not match the database Redis role, and the sentinel will be correspondingly switched to the current slave node server by the Check-sentinel script.
具体的,所述S22中周期性触发Check-sentinel脚本具体包括以下步骤:Specifically, periodically triggering the Check-sentinel script in S22 specifically includes the following steps:
当服务器为主节点服务器,且存在哨兵,则停止所述哨兵进程,所述代理进程配置文件软连接指向本地,修改软连接指向远端代理配置文件,并重启代理;When the server is the main node server and there is a sentinel, the sentinel process is stopped, the agent process configuration file soft connection points to the local, the modified soft connection points to the remote agent configuration file, and the agent is restarted;
当服务器为从节点服务器,且不存在哨兵,则启动哨兵进程,所述代理进程配置文件软连接指向远端,修改软连接指向本地代理配置文件,并重启代理;When the server is a slave node server and there is no sentinel, start the sentinel process, the agent process configuration file soft connection points to the remote end, modify the soft connection to point to the local agent configuration file, and restart the agent;
当PING命令返回错误时,则视为从节点服务器,每周期累加一次,若5次依然失败,则修改所述代理配置文件软连接指向本地配置文件。When the PING command returns an error, it is regarded as a slave node server, and it is accumulated once every cycle. If it still fails 5 times, the soft connection of the proxy configuration file is modified to point to the local configuration file.
S3、所述代理采用预设规则获取数据库Redis最新结构信息,正确路由请求。S3. The agent obtains the latest structure information of the Redis database by using a preset rule, and routes the request correctly.
综上所述,借助于本发明的上述技术方案,通过组件Proxy(代理)、KeepAlived(可以实现高可用可靠的软件)、Redis-server(节点)、Redis-sentinel(哨兵)及Check-sentinel脚本的配合使用,使得本发明可以采用最低配的Redis来实现高可用方案,不仅有效地解决了脑裂及虚机宕机无法切换的问题,而且还有效地解决了虚机启动后的多主问题,同时代理的加入能够对Redis提供一种保护如性能损耗命令的屏蔽及客户端连接打满Redis导致Redis异常退出等。To sum up, with the help of the above technical solutions of the present invention, through the components Proxy (proxy), KeepAlived (highly available and reliable software), Redis-server (node), Redis-sentinel (sentinel) and Check-sentinel scripts The combined use of Redis enables the present invention to use the lowest configuration of Redis to implement a high-availability solution, which not only effectively solves the problem of split-brain and virtual machine downtime that cannot be switched, but also effectively solves the multi-master problem after the virtual machine is started. At the same time, the addition of the proxy can provide a kind of protection for Redis, such as the shielding of performance loss commands and the abnormal exit of Redis caused by the client connection full of Redis.
需要说明的是,上述本发明实施例序号仅仅为了描述,不代表实施例的优劣。并且本文中的术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、装置、物品或者方法不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、装置、物品或者方法所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、装置、物品或者方法中还存在另外的相同要素。It should be noted that the above-mentioned serial numbers of the embodiments of the present invention are only for description, and do not represent the advantages and disadvantages of the embodiments. And the terms "comprising", "comprising" or any other variation thereof herein are intended to encompass a non-exclusive inclusion such that a process, device, article or method comprising a list of elements includes not only those elements, but also includes no explicit Other elements listed, or those inherent to such a process, apparatus, article, or method are also included. Without further limitation, an element qualified by the phrase "comprising a..." does not preclude the presence of additional identical elements in the process, apparatus, article, or method that includes the element.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在如上所述的一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本发明各个实施例所述的方法。From the description of the above embodiments, those skilled in the art can clearly understand that the method of the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is better implementation. Based on such understanding, the technical solutions of the present invention can be embodied in the form of software products in essence or the parts that make contributions to the prior art, and the computer software products are stored in a storage medium (such as ROM/RAM) as described above. , magnetic disk, optical disc), including several instructions to make a terminal device (which may be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in the various embodiments of the present invention.
以上所述仅为本发明的较佳实施例而已,并不用以限制本发明,凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The above descriptions are only preferred embodiments of the present invention, and are not intended to limit the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the scope of the present invention. within the scope of protection.

Claims (10)

  1. 一种Redis副本集的实现方法,其中,包括以下步骤:A method for implementing a Redis replica set, which includes the following steps:
    S1、采用预设方法对代理进行活性检测,实现代理高可用;S1. Use a preset method to detect the activity of the agent, so as to realize the high availability of the agent;
    S2、通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测;S2. Implement automatic failover, manual master-slave node switching, sentinel automatic switching, fault node self-rescue and split-brain multi-master detection through preset rules;
    S3、所述代理采用预设规则获取数据库Redis最新结构信息,正确路由请求。S3. The agent obtains the latest structure information of the database Redis by using a preset rule, and routes the request correctly.
  2. 根据权利要求1所述的一种Redis副本集的实现方法,其中,所述S1中采用预设方法对代理进行活性检测,实现代理高可用具体包括以下步骤:采用预设的软件KeepAlived通过检测代理活性来控制VIP偏移,实现所述代理高可用。The method for implementing a Redis replica set according to claim 1, wherein in the S1, a preset method is used to detect the activity of the agent, and the realization of the high availability of the agent specifically includes the following steps: using the preset software KeepAlived to detect the agent by using the preset method. Liveness to control VIP offset and achieve high availability of the proxy.
  3. 根据权利要求1所述的一种Redis副本集的实现方法,其中,所述S1中的所述代理为开源代理Predixy,所述开源代理Predixy可屏蔽一些密码重置及参数修改的命令,且用户无需感知底层架构部署信息,连接所述代理犹如连接单个数据库Redis,可以实现后续副本集扩展。A method for implementing a Redis replica set according to claim 1, wherein the agent in the S1 is an open source agent Predixy, the open source agent Predixy can block some password reset and parameter modification commands, and the user There is no need to perceive the underlying architecture deployment information, and connecting the agent is like connecting to a single database Redis, which can realize subsequent replica set expansion.
  4. 根据权利要求1所述的一种Redis副本集的实现方法,其中,所述S2中通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测具体包括以下步骤:The method for implementing a Redis replica set according to claim 1, wherein in S2, automatic failover, manual master-slave node switching, sentinel automatic switching, fault node self-rescue, and split-brain multi-master detection are implemented through preset rules. Specifically include the following steps:
    S21、当副本集初始化后,哨兵运行于从节点,并周期性获取数据库Redis的状态及负责数据库Redis的自动故障转移和手动主从节点服务器的切换;S21. After the replica set is initialized, the sentinel runs on the slave node, and periodically obtains the status of the database Redis and is responsible for the automatic failover of the database Redis and manual master-slave server switching;
    S22、当主从切换完成后,周期触发Check-sentinel脚本会检测到哨兵运行节点与数据库Redis角色不匹配,进而哨兵会被所述Check-sentinel脚本相应的切换到当下从节点服务器中。S22. After the master-slave switch is completed, the periodic triggering of the Check-sentinel script will detect that the sentinel running node does not match the database Redis role, and then the sentinel will be correspondingly switched to the current slave node server by the Check-sentinel script.
  5. 根据权利要求4所述的一种Redis副本集的实现方法,其中,所述S22中周期性触发Check-sentinel脚本具体包括以下步骤:The method for realizing a Redis replica set according to claim 4, wherein the periodic triggering of the Check-sentinel script in the S22 specifically includes the following steps:
    当服务器为主节点服务器,且存在哨兵,则停止所述哨兵进程,所述代理进程配置文件软连接指向本地,修改软连接指向远端代理配置文件,并重启代理;When the server is the main node server and there is a sentinel, the sentinel process is stopped, the agent process configuration file soft connection points to the local, the modified soft connection points to the remote agent configuration file, and the agent is restarted;
    当服务器为从节点服务器,且不存在哨兵,则启动哨兵进程,所述代理进程配置文件软连接指向远端,修改软连接指向本地代理配置文件,并重启代理;When the server is a slave node server and there is no sentinel, start the sentinel process, the agent process configuration file soft connection points to the remote end, modify the soft connection to point to the local agent configuration file, and restart the agent;
    当PING命令返回错误时,则视为从节点服务器,每周期累加一次,若5次依然失败,则修改所述代理配置文件软连接指向本地配置文件。When the PING command returns an error, it is regarded as a slave node server, and it is accumulated once every cycle. If it still fails 5 times, the soft connection of the proxy configuration file is modified to point to the local configuration file.
  6. 根据权利要求1所述的一种Redis副本集的实现方法,其中,所述S3中所述代理获取数据库Redis最新结构信息的预设规则指所述代理周期性的从哨兵获取。The method for implementing a Redis replica set according to claim 1, wherein the preset rule for the agent to obtain the latest Redis structure information of the database in the S3 means that the agent periodically obtains from the sentinel.
  7. 一种电子装置,其中,所述电子装置包括存储器和处理器,所述存储器上存储有可在所述处理器上运行的Redis副本集的实现程序,所述Redis副本集的实现程序被所述处理器执行时实现如下步骤:An electronic device, wherein the electronic device includes a memory and a processor, the memory stores an implementation program of a Redis replica set that can run on the processor, and the implementation program of the Redis replica set is stored by the The processor implements the following steps when executing:
    S1、采用预设方法对代理进行活性检测,实现代理高可用;S1. Use a preset method to detect the activity of the agent, so as to realize the high availability of the agent;
    S2、通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测;S2. Implement automatic failover, manual master-slave node switching, sentinel automatic switching, fault node self-rescue and split-brain multi-master detection through preset rules;
    S3、所述代理采用预设规则获取数据库Redis最新结构信息,正确路由请求。S3. The agent obtains the latest structure information of the database Redis by using a preset rule, and routes the request correctly.
  8. 根据权利要求7所述的一种电子装置,其中,所述S1中采用预设方法对代理进行活性检测,实现代理高可用具体包括以下步骤:采用预设的软件KeepAlived通过检测代理活性来控制VIP偏移,实现所述代理高可用。The electronic device according to claim 7, wherein in the S1, a preset method is used to detect the activity of the agent, and realizing the high availability of the agent specifically includes the following steps: using the preset software KeepAlived to control the VIP by detecting the activity of the agent offset to achieve high availability of the proxy.
  9. 根据权利要求7所述的一种电子装置,其中,所述S2中通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测具体包括以下步骤:The electronic device according to claim 7, wherein, in said S2, implementing automatic failover, manual master-slave node switching, sentinel automatic switching, fault node self-rescue and split-brain multi-master detection through a preset rule specifically includes the following steps :
    S21、当副本集初始化后,哨兵运行于从节点,并周期性获取数据库Redis的状态及负责数据库Redis的自动故障转移和手动主从节点服务器的切换;S21. After the replica set is initialized, the sentinel runs on the slave node, and periodically obtains the status of the database Redis and is responsible for the automatic failover of the database Redis and manual master-slave server switching;
    S22、当主从切换完成后,周期触发Check-sentinel脚本会检测到哨兵运行节点与数据库Redis角色不匹配,进而哨兵会被所述Check-sentinel脚本相应的切换到当下从节点服务器中。S22. After the master-slave switch is completed, the periodic triggering of the Check-sentinel script will detect that the sentinel running node does not match the database Redis role, and then the sentinel will be correspondingly switched to the current slave node server by the Check-sentinel script.
  10. 根据权利要求9所述的一种电子装置,其中,所述S22中周期性触发Check-sentinel脚本具体包括以下步骤:A kind of electronic device according to claim 9, wherein, periodically triggering Check-sentinel script in described S22 specifically comprises the following steps:
    当服务器为主节点服务器,且存在哨兵,则停止所述哨兵进程,所述代理进程配置文件软连接指向本地,修改软连接指向远端代理配置文件,并重启代理;When the server is the master node server and there is a sentinel, the sentinel process is stopped, the agent process configuration file soft connection points to the local, the modified soft connection points to the remote agent configuration file, and the agent is restarted;
    当服务器为从节点服务器,且不存在哨兵,则启动哨兵进程,所述代理进程配置文件软连接指向远端,修改软连接指向本地代理配置文件,并重启代理;When the server is a slave node server and there is no sentinel, start the sentinel process, the agent process configuration file soft connection points to the remote end, modify the soft connection to point to the local agent configuration file, and restart the agent;
    当PING命令返回错误时,则视为从节点服务器,每周期累加一次,若5次依然失败,则修改所述代理配置文件软连接指向本地配置文件。When the PING command returns an error, it is regarded as a slave node server, and it is accumulated once every cycle. If it still fails 5 times, the soft connection of the proxy configuration file is modified to point to the local configuration file.
PCT/CN2020/130220 2020-08-20 2020-11-19 Implementation method and apparatus for redis replica set WO2022036901A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010842617.3A CN112100005B (en) 2020-08-20 2020-08-20 Redis copy set implementation method and device
CN202010842617.3 2020-08-20

Publications (1)

Publication Number Publication Date
WO2022036901A1 true WO2022036901A1 (en) 2022-02-24

Family

ID=73753084

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/130220 WO2022036901A1 (en) 2020-08-20 2020-11-19 Implementation method and apparatus for redis replica set

Country Status (2)

Country Link
CN (1) CN112100005B (en)
WO (1) WO2022036901A1 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115190005A (en) * 2022-06-30 2022-10-14 南京信息工程大学 High-availability method of double-host system based on Redis
CN115426249A (en) * 2022-11-02 2022-12-02 飞天诚信科技股份有限公司 High-availability solution method and device for Redis master-slave architecture
CN116303364A (en) * 2023-03-28 2023-06-23 云启智慧科技有限公司 Redis high-availability and high-expansibility installation method and device

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112783611A (en) * 2021-01-29 2021-05-11 紫光云技术有限公司 Universal configurable method for preparing cloud database Redis instance resources
CN112866035A (en) * 2021-02-24 2021-05-28 紫光云技术有限公司 Method for switching specified slave node into master node of redis service on cloud platform
CN114785713B (en) * 2022-03-31 2024-02-23 度小满科技(北京)有限公司 Method and proxy middleware for realizing high availability of Redis cluster

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120317354A1 (en) * 2010-02-19 2012-12-13 Tokyo Institute Of Technology Storage device, control method for same and system management program
CN103207841A (en) * 2013-03-06 2013-07-17 青岛海信传媒网络技术有限公司 Method and device for data reading and writing on basis of key-value buffer
CN106209447A (en) * 2016-07-07 2016-12-07 深圳市创梦天地科技有限公司 The fault handling method of distributed caching and device
CN110140119A (en) * 2016-10-27 2019-08-16 Mz知识产权控股有限责任公司 System and method for managing cache server cluster

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104199957B (en) * 2014-09-17 2018-03-02 合一网络技术(北京)有限公司 A kind of implementation method of Redis general-purpose proxies
CN107343034B (en) * 2017-06-26 2019-12-27 杭州铭师堂教育科技发展有限公司 QConf-based Redis high availability system and method
CN109656753B (en) * 2018-12-03 2023-02-28 上海电科智能系统股份有限公司 Redundant hot standby system applied to rail transit comprehensive monitoring system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120317354A1 (en) * 2010-02-19 2012-12-13 Tokyo Institute Of Technology Storage device, control method for same and system management program
CN103207841A (en) * 2013-03-06 2013-07-17 青岛海信传媒网络技术有限公司 Method and device for data reading and writing on basis of key-value buffer
CN106209447A (en) * 2016-07-07 2016-12-07 深圳市创梦天地科技有限公司 The fault handling method of distributed caching and device
CN110140119A (en) * 2016-10-27 2019-08-16 Mz知识产权控股有限责任公司 System and method for managing cache server cluster

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115190005A (en) * 2022-06-30 2022-10-14 南京信息工程大学 High-availability method of double-host system based on Redis
CN115190005B (en) * 2022-06-30 2023-05-16 南京信息工程大学 Redis-based high availability method of double-host system
CN115426249A (en) * 2022-11-02 2022-12-02 飞天诚信科技股份有限公司 High-availability solution method and device for Redis master-slave architecture
CN115426249B (en) * 2022-11-02 2023-03-24 飞天诚信科技股份有限公司 High-availability solution method and device for Redis master-slave architecture
CN116303364A (en) * 2023-03-28 2023-06-23 云启智慧科技有限公司 Redis high-availability and high-expansibility installation method and device
CN116303364B (en) * 2023-03-28 2023-12-15 云启智慧科技有限公司 Redis high-availability and high-expansibility installation method and device

Also Published As

Publication number Publication date
CN112100005B (en) 2022-11-25
CN112100005A (en) 2020-12-18

Similar Documents

Publication Publication Date Title
WO2022036901A1 (en) Implementation method and apparatus for redis replica set
EP3493471B1 (en) Data disaster recovery method, apparatus and system
CN107343034B (en) QConf-based Redis high availability system and method
US9454439B2 (en) Disaster recovery validation
US20150039931A1 (en) Replaying jobs at a secondary location of a service
US11144405B2 (en) Optimizing database migration in high availability and disaster recovery computing environments
US20100174807A1 (en) System and method for providing configuration synchronicity
US8533525B2 (en) Data management apparatus, monitoring apparatus, replica apparatus, cluster system, control method and computer-readable medium
CN106657167B (en) Management server, server cluster, and management method
CN111478796B (en) Cluster capacity expansion exception handling method for AI platform
US20140297834A1 (en) Management of a plurality of system control networks
CN111752488B (en) Management method and device of storage cluster, management node and storage medium
CN112380062A (en) Method and system for rapidly recovering system for multiple times based on system backup point
US8612799B2 (en) Method and apparatus of backing up subversion repository
CN111666134A (en) Method and system for scheduling distributed tasks
WO2022037268A1 (en) Container management method, device, and medium
WO2017080362A1 (en) Data managing method and device
CN111290859B (en) Method for synchronizing initialization attribute of dual-system terminal and terminal
CN114860782B (en) Data query method, device, equipment and medium
CN111324632B (en) Transparent database session restoration with client-side caching
JP2015114952A (en) Network system, monitoring control unit, and software verification method
CN114676118A (en) Database switching method, device, equipment and storage medium
US9853774B2 (en) System and method for restoring a status of an apparatus controlled by multiple commands
CN112433860B (en) Event management method, system, equipment and medium
WO2023071724A1 (en) Configuration management method, apparatus and system, and storage medium and program product

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20950104

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 030823)

122 Ep: pct application non-entry in european phase

Ref document number: 20950104

Country of ref document: EP

Kind code of ref document: A1