WO2022036901A1 - 一种Redis副本集的实现方法及装置 - Google Patents
一种Redis副本集的实现方法及装置 Download PDFInfo
- 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
Links
- 238000000034 method Methods 0.000 title claims abstract description 66
- 238000013515 script Methods 0.000 claims abstract description 21
- 230000000694 effects Effects 0.000 claims abstract description 16
- 238000001514 detection method Methods 0.000 claims abstract description 11
- 230000008569 process Effects 0.000 claims description 31
- 230000000737 periodic effect Effects 0.000 claims description 7
- 230000004048 modification Effects 0.000 claims description 4
- 238000012986 modification Methods 0.000 claims description 4
- 210000004556 brain Anatomy 0.000 abstract description 3
- 230000009286 beneficial effect Effects 0.000 abstract description 2
- 239000003795 chemical substances by application Substances 0.000 description 58
- 238000004891 communication Methods 0.000 description 4
- 238000010586 diagram Methods 0.000 description 4
- 238000010276 construction Methods 0.000 description 3
- 238000012545 processing Methods 0.000 description 3
- 239000004973 liquid crystal related substance Substances 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 230000002159 abnormal effect Effects 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 238000012217 deletion Methods 0.000 description 1
- 230000037430 deletion Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 230000010076 replication Effects 0.000 description 1
- 230000001960 triggered effect Effects 0.000 description 1
- 230000000007 visual effect Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/07—Responding to the occurrence of a fault, e.g. fault tolerance
- G06F11/16—Error detection or correction of the data by redundancy in hardware
- G06F11/20—Error 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/202—Error 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/2023—Failover techniques
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/3003—Monitoring arrangements specially adapted to the computing system or computing system component being monitored
- G06F11/3006—Monitoring 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
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/3055—Monitoring 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.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Quality & Reliability (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Mathematical Physics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
- Debugging And Monitoring (AREA)
- Hardware Redundancy (AREA)
Abstract
一种Redis副本集的实现方法及装置,该方法包括以下步骤:S1、采用预设方法对代理进行活性检测,实现代理高可用;S2、通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测;S3、所述代理采用预设规则获取数据库Redis最新结构信息,正确路由请求。有益效果:通过组件Proxy、KeepAlived、Redis-server、Redis-sentinel及Check-sentinel脚本的配合使用,使得可以采用最低配的Redis来实现高可用方案,不仅有效地解决了脑裂及虚机宕机无法切换的问题,而且还有效地解决了虚机启动后的多主问题,同时代理的加入能够对Redis提供一种保护如性能损耗命令的屏蔽及客户端连接打满Redis导致Redis异常退出等。
Description
本发明涉及数据库技术领域,具体来说,涉及一种Redis副本集的实现方法及装置。
目前网络博客或许多项目应用中,Redis副本集很多是一主两从三哨兵、多哨兵或一主一从两哨兵的搭建方式,很少谈及一主一从一哨兵最低配的搭建方式。常见的方案如下:方案一(如图1所示)为一主一从两哨兵,M1、R1分别为主从Redis,S1、S2为高可用哨兵;方案二(如图2所示)为一主一从三哨兵,如单独部署,3个哨兵会占用更多的资源;与Redis部署在一起,同样会遇到故障切换问题;方案三(如图3所示)为一主两从3哨兵,依然不是最低配,耗费更多的资源;另外没有代理,用户需要感知所有节点信息如IP,PORT等,通过客户端可以执行所有管理员操作如FLUSH等,带来安全隐患。
然而,对于上述方案一而言,其存在以下缺陷:1)无法解决网络故障后脑裂问题;2)如其中某一哨兵进程宕掉或某一虚机宕掉后,故障切换无法顺利进行;3)客户端需要明确底层部署架构信息如IP,PORT等,且可以执行一切管理员操作如FLUSH等。
对于上述方案二而言,增加一个哨兵;如三个哨兵单独部署为带来额外的资源耗费,哨兵进程只是故障切换,不会占用太多资源;如哨兵进程与Redis部署在一起,同样会有两个明显的缺点:1)如其中哨兵多的一方虚机宕掉后,故障切换无法顺利进行;2)客户端需要明确底层部署架构信息如IP,PORT等,且可以执行一切管理员操作如FLUSH等。
对于上述方案三而言,一主两从三哨兵,额外增加一台物理资源,已然不是最低配。
针对相关技术中的问题,目前尚未提出有效的解决方案。
发明内容
针对相关技术中的问题,本发明提出一种Redis副本集的实现方法及装置,以克服现有相关技术所存在的上述技术问题。
为此,本发明采用的具体技术方案如下:
根据本发明的一个方面,提供了一种Redis副本集的实现方法,包括以下步骤:
S1、采用预设方法对代理进行活性检测,实现代理高可用;
S2、通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测;
S3、所述代理采用预设规则获取数据库Redis最新结构信息,正确路由请求。
进一步的,所述S1中采用预设方法对代理进行活性检测,实现代理高可用具体包括以下步骤:采用预设的软件KeepAlived通过检测代理活性来控制VIP偏移,实现所述代理高可用。
进一步的,所述S1中的所述代理为开源代理Predixy,所述开源代理Predixy可屏蔽一些密码重置及参数修改的命令,且用户无需感知底层架构部署信息,连接所述代理犹如连接单个数据库Redis,可以实现后续副本集扩展。
进一步的,所述S2中通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测具体包括以下步骤:
S21、当副本集初始化后,哨兵运行于从节点,并周期性获取数据库Redis的状态及负责数据库Redis的自动故障转移和手动主从节点服务器的切换;
S22、当主从切换完成后,周期触发Check-sentinel脚本会检测到哨兵运行节点与数据库Redis角色不匹配,进而哨兵会被所述Check-sentinel脚本相应的切换到当下从节点服务器中。
进一步的,所述S22中周期性触发Check-sentinel脚本具体包括以 下步骤:
当服务器为主节点服务器,且存在哨兵,则停止所述哨兵进程,所述代理进程配置文件软连接指向本地,修改软连接指向远端代理配置文件,并重启代理;
当服务器为从节点服务器,且不存在哨兵,则启动哨兵进程,所述代理进程配置文件软连接指向远端,修改软连接指向本地代理配置文件,并重启代理;
当PING命令返回错误时,则视为从节点服务器,每周期累加一次,若5次依然失败,则修改所述代理配置文件软连接指向本地配置文件。
进一步的,所述S3中所述代理获取数据库Redis最新结构信息的预设规则指所述代理周期性的从哨兵获取。
根据本发明的另一个方面,还提供了一种电子装置,所述电子装置包括存储器和处理器,所述存储器上存储有可在所述处理器上运行的Redis副本集的实现程序,所述Redis副本集的实现程序被所述处理器执行时实现如下步骤:
S1、采用预设方法对代理进行活性检测,实现代理高可用;
S2、通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测;
S3、所述代理采用预设规则获取数据库Redis最新结构信息,正确路由请求。
进一步的,所述S1中采用预设方法对代理进行活性检测,实现代理高可用具体包括以下步骤:采用预设的软件KeepAlived通过检测代理活性来控制VIP偏移,实现所述代理高可用。
进一步的,所述S2中通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测具体包括以下步骤:
S21、当副本集初始化后,哨兵运行于从节点,并周期性获取数据库Redis的状态及负责数据库Redis的自动故障转移和手动主从节点服务器的切换;
S22、当主从切换完成后,周期触发Check-sentinel脚本会检测到 哨兵运行节点与数据库Redis角色不匹配,进而哨兵会被所述Check-sentinel脚本相应的切换到当下从节点服务器中。
进一步的,所述S22中周期性触发Check-sentinel脚本具体包括以下步骤:
当服务器为主节点服务器,且存在哨兵,则停止所述哨兵进程,所述代理进程配置文件软连接指向本地,修改软连接指向远端代理配置文件,并重启代理;
当服务器为从节点服务器,且不存在哨兵,则启动哨兵进程,所述代理进程配置文件软连接指向远端,修改软连接指向本地代理配置文件,并重启代理;
当PING命令返回错误时,则视为从节点服务器,每周期累加一次,若5次依然失败,则修改所述代理配置文件软连接指向本地配置文件。
本发明的有益效果为:通过组件Proxy、KeepAlived、Redis-server、Redis-sentinel及Check-sentinel脚本的配合使用,使得本发明可以采用最低配的Redis来实现高可用方案,不仅有效地解决了脑裂及虚机宕机无法切换的问题,而且还有效地解决了虚机启动后的多主问题,同时代理的加入能够对Redis提供一种保护如性能损耗命令的屏蔽及客户端连接打满Redis导致Redis异常退出等。
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1是现有技术中Redis副本集方案一的搭建方式示意图;
图2是现有技术中Redis副本集方案二的搭建方式示意图;
图3是现有技术中Redis副本集方案三的搭建方式示意图;
图4根据本发明实施例的一种Redis副本集的实现方法的流程示意图;
图5是根据本发明实施例的一种Redis副本集的实现方法中原理框 架示意图。
为进一步说明各实施例,本发明提供有附图,这些附图为本发明揭露内容的一部分,其主要用以说明实施例,并可配合说明书的相关描述来解释实施例的运作原理,配合参考这些内容,本领域普通技术人员应能理解其他可能的实施方式以及本发明的优点,图中的组件并未按比例绘制,而类似的组件符号通常用来表示类似的组件。
根据本发明的实施例,提供了一种Redis副本集的实现方法及装置。
现结合附图和具体实施方式对本发明进一步说明,如图4-5所示,根据本发明的一个实施例,提供了一种Redis副本集的实现方法,包括以下步骤:
S1、采用预设方法对代理进行活性检测,实现代理高可用;
其中,所述S1具体包括以下步骤:采用预设的软件KeepAlived通过检测代理(Proxy)活性来控制VIP偏移,实现所述代理高可用。
具体的,所述S1中的所述代理为开源代理Predixy,所述开源代理Predixy可屏蔽一些密码重置、参数修改及损耗性能如SCAN,KEYS等命令,且用户无需感知底层架构部署信息,连接所述代理犹如连接单个数据库Redis,可以实现后续副本集扩展。
S2、通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测;
其中,所述S2具体包括以下步骤:
S21、当副本集初始化后,哨兵运行于从节点,并周期性获取数据库Redis的状态及负责数据库Redis的自动故障转移和手动主从节点服务器的切换;
具体的,所述S21中的故障转移包括以下步骤:
在已下线主节点服务器的所有从节点服务器里挑选一个从节点服务器,并将其转换为主节点服务器;优选的,将从节点服务器转换为主节点服务器的选举原则如下:首先删除列表中处于下线或断线状态的从节点服务器,保证所有服务器都处于在线状态;然后删除列表中最近5 秒没有回复领头哨兵的服务器,保证所有服务器都是可以正常通信的;最后删除与已下线的主节点服务器断开超过预设时间的从节点服务器,用来筛选出较新数据的从数据库。当进行删减后,将优先设置优先级高,复制偏移量最大的从节点服务器,如果还无法选出,将选择运行ID最小的从节点服务器;
当选举出新的主节点服务器时,哨兵会以每秒一次的频率进行INFO命令的发送,当被升级的role属性从slave升级为了master,就认为已经升级成了主节点服务器。当检测到选出的所述从节点服务器已经升级到主节点服务器之后,将继续向其他的所述从节点服务器发送SLAVEOF命令来更改所述主节点服务器的设置。
让已下线的主节点服务器的其他从节点服务器复制新的主节点服务器;
将已下线的主节点服务器设置为新的主节点服务器的从节点服务器,当已下线的主节点服务器重新上线时,会成为新的主节点服务器的从节点服务器。
具体的,旧主节点服务器已经下线,所以设置是配置在领头哨兵的旧主节点服务器对象中,当旧节点主服务器上线后,哨兵会进行SLAVEOF命令的补发。
S22、当主从切换完成后,周期触发Check-sentinel脚本会检测到哨兵运行节点与数据库Redis角色不匹配,进而哨兵会被所述Check-sentinel脚本相应的切换到当下从节点服务器中。
具体的,所述S22中Check-sentinel脚本为周期性触发,如每3秒,具体如下:
当服务器为主节点服务器,且存在哨兵,则停止所述哨兵进程,所述代理进程配置文件软连接指向本地,修改软连接指向远端代理配置文件,并重启代理;
当服务器为从节点服务器,且不存在哨兵,则启动哨兵进程,所述代理进程配置文件软连接指向远端,修改软连接指向本地代理配置文件,并重启代理;
当PING命令返回错误(Error)时,则视为从节点服务器,每周 期累加一次,若5次依然失败,则修改所述代理配置文件软连接指向本地配置文件。
此外,所述S22中还包括实现自动切换哨兵(因为故障哨兵会负责切换,切换后,Redis角色与哨兵只运行在从节点不符合,所以要切换哨兵;哨兵之运行在从节点,因为主节点宕掉,依然可以切换),故障节点自救如尝试3次服务依然启动失败,则会发出告警邮件、及脑裂多主出现会相应杀掉进程运行时间长的Redis进程。
S3、所述代理采用预设规则获取数据库Redis最新结构信息,正确路由请求。
其中,所述S3中所述代理获取数据库Redis最新结构信息的预设规则指所述代理周期性的从哨兵获取,所述信息包括状态/角色等信息。
根据本发明的另一个实施例,还提供了一种电子装置。
在本实施例中,所述电子装置可以是电脑或服务器。所述电子装置至少包括存储器、处理器、通信总线以及网络接口。
其中,存储器至少包括一种类型的可读存储介质,所述可读存储介质包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、磁性存储器、磁盘、光盘等。存储器在一些实施例中可以是电子装置的内部存储单元,例如所述电子装置的硬盘。存储器在另一些实施例中也可以是电子装置的外部存储设备,例如电子装置上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。进一步地,存储器还可以既包括电子装置的内部存储单元也包括外部存储设备。存储器不仅可以用于存储安装于电子装置的应用软件及各类数据,例如Redis副本集的实现程序的代码等,还可以用于暂时地存储已经输出或者将要输出的数据。
处理器在一些实施例中可以是一中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器或其他数据处理芯片,用于运行存储器中存储的程序代码或处理数据。
通信总线用于实现这些组件之间的连接通信。
网络接口可选的可以包括标准的有线接口、无线接口(如WI-FI接口),通常用于在电子装置与其他电子设备之间建立通信连接。
可选地,电子装置还可以包括用户接口,用户接口可以包括显示器(Display)、输入单元比如键盘(Keyboard),可选的用户接口还可以包括标准的有线接口、无线接口。可选地,在一些实施例中,显示器可以是LED显示器、液晶显示器、触控式液晶显示器以及OLED(Organic Light-Emitting Diode,有机发光二极管)触摸器等。其中,显示器也可以适当的称为显示屏或显示单元,用于显示在电子装置中处理的信息以及用于显示可视化的用户界面。
所述电子装置包括存储器和处理器,所述存储器上存储有可在所述处理器上运行的Redis副本集的实现程序,所述Redis副本集的实现程序被所述处理器执行时实现如下步骤:
S1、采用预设方法对代理进行活性检测,实现代理高可用;其中,所述S1具体包括以下步骤:采用预设的软件KeepAlived通过检测代理活性来控制VIP偏移,实现所述代理高可用。
S2、通过预设法则实现自动故障转移、手动主从节点、切换、哨兵自动切换、故障节点自救及脑裂多主检测;其中,所述S2具体包括以下步骤:S21、当副本集初始化后,哨兵运行于从节点,并周期性获取数据库Redis的状态及负责数据库Redis的自动故障转移和手动主从节点服务器的切换;S22、当主从切换完成后,周期触发Check-sentinel脚本会检测到哨兵运行节点与数据库Redis角色不匹配,进而哨兵会被所述Check-sentinel脚本相应的切换到当下从节点服务器中。
具体的,所述S22中周期性触发Check-sentinel脚本具体包括以下步骤:
当服务器为主节点服务器,且存在哨兵,则停止所述哨兵进程,所述代理进程配置文件软连接指向本地,修改软连接指向远端代理配置文件,并重启代理;
当服务器为从节点服务器,且不存在哨兵,则启动哨兵进程,所述代理进程配置文件软连接指向远端,修改软连接指向本地代理配置文件,并重启代理;
当PING命令返回错误时,则视为从节点服务器,每周期累加一次,若5次依然失败,则修改所述代理配置文件软连接指向本地配置文件。
S3、所述代理采用预设规则获取数据库Redis最新结构信息,正确路由请求。
综上所述,借助于本发明的上述技术方案,通过组件Proxy(代理)、KeepAlived(可以实现高可用可靠的软件)、Redis-server(节点)、Redis-sentinel(哨兵)及Check-sentinel脚本的配合使用,使得本发明可以采用最低配的Redis来实现高可用方案,不仅有效地解决了脑裂及虚机宕机无法切换的问题,而且还有效地解决了虚机启动后的多主问题,同时代理的加入能够对Redis提供一种保护如性能损耗命令的屏蔽及客户端连接打满Redis导致Redis异常退出等。
需要说明的是,上述本发明实施例序号仅仅为了描述,不代表实施例的优劣。并且本文中的术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、装置、物品或者方法不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、装置、物品或者方法所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、装置、物品或者方法中还存在另外的相同要素。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在如上所述的一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本发明各个实施例所述的方法。
以上所述仅为本发明的较佳实施例而已,并不用以限制本发明,凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。
Claims (10)
- 一种Redis副本集的实现方法,其中,包括以下步骤:S1、采用预设方法对代理进行活性检测,实现代理高可用;S2、通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测;S3、所述代理采用预设规则获取数据库Redis最新结构信息,正确路由请求。
- 根据权利要求1所述的一种Redis副本集的实现方法,其中,所述S1中采用预设方法对代理进行活性检测,实现代理高可用具体包括以下步骤:采用预设的软件KeepAlived通过检测代理活性来控制VIP偏移,实现所述代理高可用。
- 根据权利要求1所述的一种Redis副本集的实现方法,其中,所述S1中的所述代理为开源代理Predixy,所述开源代理Predixy可屏蔽一些密码重置及参数修改的命令,且用户无需感知底层架构部署信息,连接所述代理犹如连接单个数据库Redis,可以实现后续副本集扩展。
- 根据权利要求1所述的一种Redis副本集的实现方法,其中,所述S2中通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测具体包括以下步骤:S21、当副本集初始化后,哨兵运行于从节点,并周期性获取数据库Redis的状态及负责数据库Redis的自动故障转移和手动主从节点服务器的切换;S22、当主从切换完成后,周期触发Check-sentinel脚本会检测到哨兵运行节点与数据库Redis角色不匹配,进而哨兵会被所述Check-sentinel脚本相应的切换到当下从节点服务器中。
- 根据权利要求4所述的一种Redis副本集的实现方法,其中,所述S22中周期性触发Check-sentinel脚本具体包括以下步骤:当服务器为主节点服务器,且存在哨兵,则停止所述哨兵进程,所述代理进程配置文件软连接指向本地,修改软连接指向远端代理配置文件,并重启代理;当服务器为从节点服务器,且不存在哨兵,则启动哨兵进程,所述代理进程配置文件软连接指向远端,修改软连接指向本地代理配置文件,并重启代理;当PING命令返回错误时,则视为从节点服务器,每周期累加一次,若5次依然失败,则修改所述代理配置文件软连接指向本地配置文件。
- 根据权利要求1所述的一种Redis副本集的实现方法,其中,所述S3中所述代理获取数据库Redis最新结构信息的预设规则指所述代理周期性的从哨兵获取。
- 一种电子装置,其中,所述电子装置包括存储器和处理器,所述存储器上存储有可在所述处理器上运行的Redis副本集的实现程序,所述Redis副本集的实现程序被所述处理器执行时实现如下步骤:S1、采用预设方法对代理进行活性检测,实现代理高可用;S2、通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测;S3、所述代理采用预设规则获取数据库Redis最新结构信息,正确路由请求。
- 根据权利要求7所述的一种电子装置,其中,所述S1中采用预设方法对代理进行活性检测,实现代理高可用具体包括以下步骤:采用预设的软件KeepAlived通过检测代理活性来控制VIP偏移,实现所述代理高可用。
- 根据权利要求7所述的一种电子装置,其中,所述S2中通过预设法则实现自动故障转移、手动主从节点切换、哨兵自动切换、故障节点自救及脑裂多主检测具体包括以下步骤:S21、当副本集初始化后,哨兵运行于从节点,并周期性获取数据库Redis的状态及负责数据库Redis的自动故障转移和手动主从节点服务器的切换;S22、当主从切换完成后,周期触发Check-sentinel脚本会检测到哨兵运行节点与数据库Redis角色不匹配,进而哨兵会被所述Check-sentinel脚本相应的切换到当下从节点服务器中。
- 根据权利要求9所述的一种电子装置,其中,所述S22中周期性触发Check-sentinel脚本具体包括以下步骤:当服务器为主节点服务器,且存在哨兵,则停止所述哨兵进程,所述代理进程配置文件软连接指向本地,修改软连接指向远端代理配置文件,并重启代理;当服务器为从节点服务器,且不存在哨兵,则启动哨兵进程,所述代理进程配置文件软连接指向远端,修改软连接指向本地代理配置文件,并重启代理;当PING命令返回错误时,则视为从节点服务器,每周期累加一次,若5次依然失败,则修改所述代理配置文件软连接指向本地配置文件。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010842617.3 | 2020-08-20 | ||
CN202010842617.3A CN112100005B (zh) | 2020-08-20 | 2020-08-20 | 一种Redis副本集的实现方法及装置 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2022036901A1 true WO2022036901A1 (zh) | 2022-02-24 |
Family
ID=73753084
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2020/130220 WO2022036901A1 (zh) | 2020-08-20 | 2020-11-19 | 一种Redis副本集的实现方法及装置 |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN112100005B (zh) |
WO (1) | WO2022036901A1 (zh) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115190005A (zh) * | 2022-06-30 | 2022-10-14 | 南京信息工程大学 | 一种基于Redis的双宿主***的高可用方法 |
CN115426249A (zh) * | 2022-11-02 | 2022-12-02 | 飞天诚信科技股份有限公司 | 一种Redis主从架构的高可用解决方法及装置 |
CN116303364A (zh) * | 2023-03-28 | 2023-06-23 | 云启智慧科技有限公司 | 一种Redis高可用、高扩展性的安装方法及装置 |
Families Citing this family (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112783611A (zh) * | 2021-01-29 | 2021-05-11 | 紫光云技术有限公司 | 一种通用的可配置的准备云数据库Redis实例资源的方法 |
CN112866035A (zh) * | 2021-02-24 | 2021-05-28 | 紫光云技术有限公司 | 一种云平台上redis服务可指定从节点切换为主节点的方法 |
CN114785713B (zh) * | 2022-03-31 | 2024-02-23 | 度小满科技(北京)有限公司 | 一种用于实现Redis集群高可用的方法和代理中间件 |
Citations (4)
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 (zh) * | 2013-03-06 | 2013-07-17 | 青岛海信传媒网络技术有限公司 | 基于键值对缓存的数据读写方法及装置 |
CN106209447A (zh) * | 2016-07-07 | 2016-12-07 | 深圳市创梦天地科技有限公司 | 分布式缓存的故障处理方法及装置 |
CN110140119A (zh) * | 2016-10-27 | 2019-08-16 | Mz知识产权控股有限责任公司 | 用于管理缓存服务器群集的***和方法 |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104199957B (zh) * | 2014-09-17 | 2018-03-02 | 合一网络技术(北京)有限公司 | 一种Redis通用代理的实现方法 |
CN107343034B (zh) * | 2017-06-26 | 2019-12-27 | 杭州铭师堂教育科技发展有限公司 | 基于QConf的Redis高可用***及方法 |
CN109656753B (zh) * | 2018-12-03 | 2023-02-28 | 上海电科智能***股份有限公司 | 一种应用于轨道交通综合监控***的冗余热备*** |
-
2020
- 2020-08-20 CN CN202010842617.3A patent/CN112100005B/zh active Active
- 2020-11-19 WO PCT/CN2020/130220 patent/WO2022036901A1/zh active Application Filing
Patent Citations (4)
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 (zh) * | 2013-03-06 | 2013-07-17 | 青岛海信传媒网络技术有限公司 | 基于键值对缓存的数据读写方法及装置 |
CN106209447A (zh) * | 2016-07-07 | 2016-12-07 | 深圳市创梦天地科技有限公司 | 分布式缓存的故障处理方法及装置 |
CN110140119A (zh) * | 2016-10-27 | 2019-08-16 | Mz知识产权控股有限责任公司 | 用于管理缓存服务器群集的***和方法 |
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115190005A (zh) * | 2022-06-30 | 2022-10-14 | 南京信息工程大学 | 一种基于Redis的双宿主***的高可用方法 |
CN115190005B (zh) * | 2022-06-30 | 2023-05-16 | 南京信息工程大学 | 一种基于Redis的双宿主***的高可用方法 |
CN115426249A (zh) * | 2022-11-02 | 2022-12-02 | 飞天诚信科技股份有限公司 | 一种Redis主从架构的高可用解决方法及装置 |
CN115426249B (zh) * | 2022-11-02 | 2023-03-24 | 飞天诚信科技股份有限公司 | 一种Redis主从架构的高可用解决方法及装置 |
CN116303364A (zh) * | 2023-03-28 | 2023-06-23 | 云启智慧科技有限公司 | 一种Redis高可用、高扩展性的安装方法及装置 |
CN116303364B (zh) * | 2023-03-28 | 2023-12-15 | 云启智慧科技有限公司 | 一种Redis高可用、高扩展性的安装方法及装置 |
Also Published As
Publication number | Publication date |
---|---|
CN112100005B (zh) | 2022-11-25 |
CN112100005A (zh) | 2020-12-18 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2022036901A1 (zh) | 一种Redis副本集的实现方法及装置 | |
EP3493471B1 (en) | Data disaster recovery method, apparatus and system | |
CN107343034B (zh) | 基于QConf的Redis高可用***及方法 | |
US9454439B2 (en) | Disaster recovery validation | |
US8719386B2 (en) | System and method for providing configuration synchronicity | |
US20150039931A1 (en) | Replaying jobs at a secondary location of a service | |
US11144405B2 (en) | Optimizing database migration in high availability and disaster recovery computing environments | |
US8533525B2 (en) | Data management apparatus, monitoring apparatus, replica apparatus, cluster system, control method and computer-readable medium | |
CN106657167B (zh) | 管理服务器、服务器集群、以及管理方法 | |
US20140297834A1 (en) | Management of a plurality of system control networks | |
US8612799B2 (en) | Method and apparatus of backing up subversion repository | |
CN112380062A (zh) | 一种基于***备份点多次快速恢复***的方法及*** | |
WO2022037268A1 (zh) | 一种容器管理方法、设备以及介质 | |
CN111752488B (zh) | 存储集群的管理方法、装置、管理节点及存储介质 | |
CN111666134A (zh) | 一种分布式任务调度的方法和*** | |
WO2017080362A1 (zh) | 数据管理方法及装置 | |
CN116346834A (zh) | 一种会话同步方法、装置、计算设备及计算机存储介质 | |
CN111324632B (zh) | 利用客户端侧高速缓存的透明数据库会话恢复 | |
JP2015114952A (ja) | ネットワークシステム、監視制御装置およびソフトウェア検証方法 | |
CN114036129A (zh) | 一种减小数据丢失的数据库切换方法 | |
CN110554731B (zh) | 一种时钟同步控制方法、智能终端及存储介质 | |
CN114930313A (zh) | 用于管理区块链节点的***和方法 | |
CN112433860B (zh) | 一种事件管理的方法、***、设备及介质 | |
WO2023071724A1 (zh) | 配置管理的方法、装置、***、存储介质及程序产品 | |
CN115499296B (zh) | 一种云桌面热备管理方法、装置及*** |
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 |