WO2020253596A1 - High availability method and apparatus for redis cluster - Google Patents

High availability method and apparatus for redis cluster Download PDF

Info

Publication number
WO2020253596A1
WO2020253596A1 PCT/CN2020/095421 CN2020095421W WO2020253596A1 WO 2020253596 A1 WO2020253596 A1 WO 2020253596A1 CN 2020095421 W CN2020095421 W CN 2020095421W WO 2020253596 A1 WO2020253596 A1 WO 2020253596A1
Authority
WO
WIPO (PCT)
Prior art keywords
redis
redis server
server
cluster
address
Prior art date
Application number
PCT/CN2020/095421
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 WO2020253596A1 publication Critical patent/WO2020253596A1/en

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/06Management of faults, events, alarms or notifications
    • H04L41/0654Management of faults, events, alarms or notifications using network fault recovery
    • H04L41/0663Performing the actions predefined by failover planning, e.g. switching to standby network elements
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/06Management of faults, events, alarms or notifications
    • H04L41/0654Management of faults, events, alarms or notifications using network fault recovery
    • H04L41/0668Management of faults, events, alarms or notifications using network fault recovery by dynamic selection of recovery network elements, e.g. replacement by the most appropriate element after failure
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/30Decision processes by autonomous network management units using voting and bidding
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/10Mapping addresses of different types
    • H04L61/103Mapping addresses of different types across network layers, e.g. resolution of network layer into physical layer addresses or address resolution protocol [ARP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/58Caching of addresses or names

Definitions

  • the present invention relates to the field of communication technology of financial technology (Fintech), and in particular to a high-availability method and device of a Redis cluster.
  • Redis is essentially a key-value memory database.
  • Redis has simple operation commands. While ensuring the validity of data, it also guarantees high performance.
  • the embodiment of the present invention provides a high-availability method and device for a Redis cluster to solve the problem of too many components accessing the Redis database in the prior art and high maintenance cost.
  • the embodiment of the present invention provides a high-availability method for a Redis cluster.
  • the cluster includes at least two Redis servers and monitoring components configured corresponding to the Redis servers; the method includes:
  • the monitoring component of the first Redis server detects the connection link of each Redis server by initiating a detection thread
  • the monitoring component of the first Redis server determines that the connection link of the second Redis server is faulty, it initiates a vote; the second Redis server is the master Redis server;
  • the monitoring component of the first Redis server determines that the slave Redis server whose voting result is greater than or equal to half is the first Redis server, the first Redis server is determined to be the slave that switches with the second Redis server Redis server;
  • the monitoring component of the first Redis server sets the VIP address of the first Redis server to the VIP address of the Redis cluster, so that clients that access the Redis cluster can access the first Redis cluster according to the modified VIP address. Redis server.
  • the monitoring component of the first Redis server setting the VIP address of the first Redis server to the VIP address of the Redis cluster includes:
  • the monitoring component of the first Redis server determines that the source IP address in the parameter is the IP address of the second Redis server, it initiates an unbinding operation of the VIP address;
  • the monitoring component of the first Redis server determines that the destination IP address in the parameter is the IP address of the first Redis server, it detects whether the VIP address of the Redis cluster is in a connected state;
  • the monitoring component of the first Redis server If the monitoring component of the first Redis server does not receive the connection return message, it binds the VIP address of the first Redis server to the Redis cluster.
  • the method further includes:
  • the VIP address of the first Redis server is updated to the ARP cache, so that the gateway device of the Redis cluster confirms that the VIP address of the Redis cluster corresponds to the first Redis server.
  • the monitoring component of the first Redis server detects the connection link of each Redis server by initiating a detection thread, including:
  • the monitoring component of the first Redis server sends a heartbeat detection to each Redis server;
  • the available connection link is determined from the Redis instance that succeeded in the heartbeat detection.
  • An embodiment of the present invention provides a high-availability device for a Redis cluster.
  • the cluster includes at least two Redis servers and monitoring components configured corresponding to the Redis servers; the device includes:
  • the monitoring unit is used to detect the connection link of each Redis server by initiating a detection thread
  • the processing unit is configured to initiate a voting if it is determined that the connection link of the second Redis server is faulty; the second Redis server is the primary Redis server; if it is determined that the secondary Redis server whose voting result is greater than or equal to half is the first Redis Server, the first Redis server is determined to be the slave Redis server that switches with the second Redis server; the VIP address of the first Redis server is set to the VIP address of the Redis cluster, so that the The client of the Redis cluster accesses the first Redis server according to the modified VIP address.
  • the processing unit is specifically configured to:
  • the parameters transmitted by the monitoring component of the second Redis server during failover if it is determined that the source IP address in the parameters is the IP address of the second Redis server, initiate the unbinding operation of the VIP address; if It is determined that the destination IP address in the parameter is the IP address of the first Redis server, then it is detected whether the VIP address of the Redis cluster is in a connected state; if the connection return message is not received, the first Redis server The VIP address of is bound to the Redis cluster.
  • the processing unit is further configured to: update the VIP address of the first Redis server to the ARP cache, so that the gateway device of the Redis cluster confirms that the VIP address of the Redis cluster corresponds to the The first Redis server is described.
  • the monitoring unit is specifically used for:
  • the cluster includes at least two Redis servers and monitoring components configured corresponding to the Redis servers; the number of monitoring components in the prior art is reduced; the monitoring component of the first Redis server is initiated by The detection thread detects the connection link of each Redis server; if the monitoring component of the first Redis server determines that the connection link of the second Redis server is faulty, it initiates a vote; the second Redis server is the main Redis server; The monitoring component of the first Redis server determines that the secondary Redis server whose voting result is greater than or equal to half is the secondary Redis server that switches with the second Redis server; the monitoring component of the first Redis server determines the first Redis
  • the VIP address of the server is set to the VIP address of the Redis cluster, so that the client accessing the Redis cluster accesses the first Redis server according to the modified VIP address.
  • Figure 1a is a Redis cluster architecture provided by an embodiment of the present invention.
  • Figure 1b shows a Redis cluster architecture provided by an embodiment of the present invention
  • FIG. 2 is a schematic diagram of the architecture of a Redis cluster provided by an embodiment of the present invention.
  • FIG. 3 is a schematic flowchart of a high-availability method for a Redis cluster provided by an embodiment of the present invention
  • FIG. 4 is a schematic structural diagram of a high-availability device for Redis cluster provided by an embodiment of the present invention.
  • FIG. 5 is a schematic structural diagram of a Redis monitoring component provided by an embodiment of the present invention.
  • High-availability cluster refers to server cluster technology for the purpose of reducing service interruption time. It minimizes the impact of software, hardware, or human-caused failures on the business by protecting the user's business program to provide uninterrupted services to the outside world.
  • Redis server an open source, network-supported, memory-based, optional persistence key-value storage database written in ANSI C, and is usually used as a cache database.
  • Monitoring component sentinel monitor the available status of the Redis server. When using Redis as a high-availability solution for the main Redis server and the secondary Redis server, if the main Redis server goes down, Redis itself (including many of its clients) does not realize automatic active/standby switching. Through the monitoring component sentinel component, you can Monitor whether Redis is running as expected; if a Redis node is found to be malfunctioning, it can notify another process (such as its client) to automatically switch.
  • the Redis-monitoring component sentinel itself is also an independently running process. It can monitor multiple master Redis servers-slave Redis server clusters, and automatically switch after the master Redis server is down. It is unreliable to use only a single monitoring component sentinel process to monitor the Redis cluster. When the monitoring component sentinel process runs incorrectly, or the network is blocked, the active and standby redis cluster cannot be switched (the monitoring component sentinel itself also has a single point of problem, single -point-of-failure) The entire cluster system will not operate as expected. Therefore, it is necessary to cluster the monitoring component sentinel, that is, multiple monitoring components sentinel need to be set up.
  • the monitoring component can elect at least one of the slave Redis servers of the master Redis server as the new master Redis server.
  • Other slave Redis server nodes will change the address of the master Redis server that it follows to: the new address of the slave Redis server promoted to the master Redis server. If most of the monitoring components sentinels can communicate with each other, there will eventually be one authorized to perform fault migration, ensuring the liveness of Redis.
  • Keepalived A component for health check in a load balancing cluster and a component for maintaining failover between the active and standby machines.
  • HAProxy is a free and open source software written in C language that provides high availability, load balancing, and application proxy based on TCP and HTTP.
  • Vip The ip address for external access in the cluster, usually only one.
  • one deployment method is to deploy VIP nodes.
  • the VIP nodes manage multiple nodes, each The node manages an instance group, and the VIP node implements the function of data fragmentation, that is, the read and write requests sent by the application are allocated to the corresponding instance group of the corresponding node for processing by the VIP node.
  • the HAProxy component can be set in each Redis server, and the master-slave switch of the Redis server can be detected instantly through the HAProxy component. If it is determined that the master-slave switch of the Redis server is completed, the new master Redis server is activated Set the VIP address as the VIP address of the current Redis cluster. The specific setting can be implemented through the Virtual Router Redundancy Protocol (VRRP) to switch the VIP address.
  • VRRP Virtual Router Redundancy Protocol
  • VRRP can virtualize the physical router device of the first Redis server and the physical router device of the second Redis server into a virtual router.
  • This virtual router provides services to the outside through a virtual IP (VIP), while inside the virtual router It can include multiple physical routers working together. Only one physical router provides external services at the same time, that is, the main router. For example, if the current main Redis server is the first Redis server, at this time, only the physical of the first Redis server The router provides external servers. Among them, the main router is generated by an election algorithm.
  • each master Redis server and slave Redis server is configured with a monitoring component sentinel component; in addition, due to the need to elect multiple slave Redis servers of the master Redis server One of them will be used as the new master Redis server. If the total number of the master Redis server and the slave Redis server is an even number, in order to ensure the smooth progress of the election, an additional monitoring component sentinel of the Redis server needs to be set up. The problem is in a large cluster It's not obvious, but in small clusters, additional components increase maintenance costs.
  • the embodiment of the present invention provides another deployment method.
  • the switch of the main Redis server needs to notify the client through the monitoring component sentinel, and the client needs to reconnect to the switched main Redis server.
  • the client needs to monitor the event queue of the monitoring component sentinel, obtain the ip port of the main Redis server after the switch, and initiate access to the ip port of the main Redis server after the switch, compared to the deployment scenario with VIP nodes , Is not conducive to the timeliness of handover.
  • the cluster includes at least two Redis servers and monitoring components configured corresponding to the Redis servers; as shown in Figure 3, the embodiment of the present invention provides a high availability of a Redis cluster Schematic diagram of the method flow, the specific implementation methods include:
  • Step 301 The monitoring component sentinel of the first Redis server detects the connection link of each Redis server by initiating a detection thread
  • the monitoring component of the first Redis server detects the connection link of each Redis server by initiating a detection thread, including:
  • the monitoring component of the first Redis server sends a heartbeat detection to each Redis server;
  • the available connection link is determined from the Redis instance that succeeded in the heartbeat detection.
  • a separate thread can be started to periodically send detection messages to each Redis instance, and its health status can be judged based on its response.
  • the feedback interface is also opened to external callers. When the caller encounters an exception while reading and writing Redis, the feedback interface can be called to update the health status of the Redis instance in time.
  • Step 302 If the monitoring component of the first Redis server determines that the connection link of the second Redis server is faulty, it initiates a vote; the second Redis server is the master Redis server;
  • the monitoring component sentinel detects that the main Redis server cannot be connected at a specific time, it confirms that the second Redis server is faulty and needs to trigger a failover.
  • Step 303 If the monitoring component of the first Redis server determines that the secondary Redis server whose voting result is greater than or equal to half is the first Redis server, then the first Redis server is determined to be the one to switch to the second Redis server From the Redis server;
  • the voting method in the embodiment of the present invention is greater than or equal to half, and the specific code may be as follows:
  • Step 304 The monitoring component of the first Redis server sets the VIP address of the first Redis server to the VIP address of the Redis cluster, so that the clients that access the Redis cluster can access the first Redis cluster according to the modified VIP address.
  • the cluster includes at least two Redis servers and monitoring components configured corresponding to the Redis servers; the number of monitoring components in the prior art is reduced; the monitoring component of the first Redis server is initiated by The detection thread detects the connection link of each Redis server; if the monitoring component of the first Redis server determines that the connection link of the second Redis server is faulty, it initiates a vote; the second Redis server is the main Redis server; The monitoring component of the first Redis server determines that the secondary Redis server whose voting result is greater than or equal to half is the secondary Redis server that switches with the second Redis server; the monitoring component of the first Redis server determines the first Redis
  • the VIP address of the server is set to the VIP address of the Redis cluster, so that the client accessing the Redis cluster accesses the first Redis server according to the modified VIP address.
  • the redis server switch in the Redis cluster is realized through the voting mechanism.
  • the VIP drift of the failure of the Redis server is realized, no additional monitoring components are required, and because the setting of the VIP address is completed through the monitoring component Yes, it does not require other components in the prior art to complete, thereby further reducing component settings and reducing maintenance costs.
  • the cost is lower and the maintenance cost is also reduced, which has more obvious economic benefits.
  • a possible implementation manner includes:
  • Step 1 The monitoring component of the first Redis server obtains the parameters transmitted by the monitoring component of the second Redis server during failover;
  • Step 2 If the monitoring component of the first Redis server determines that the source IP address in the parameter is the IP address of the second Redis server, it initiates an unbinding operation of the VIP address;
  • Step 3 If the monitoring component of the first Redis server determines that the destination IP address in the parameter is the IP address of the first Redis server, it detects whether the VIP address of the Redis cluster is in a connected state;
  • Step 4 If the monitoring component of the first Redis server does not receive the connection return message, it binds the VIP address of the first Redis server to the Redis cluster.
  • a script is triggered when the main Redis server of the Redis cluster fails over.
  • the script can be written in shell language.
  • the script is used to determine the parameters transmitted by the monitoring component from the monitoring component of the second Redis server during failover. For example, if the IP address in the parameter from-ip is the local ip, the address that can be bound by the VIP is still the second Redis server. Therefore, the VIP unbinding operation can be performed through the ip command of the operating system. For example, "/bin/ip addr del ⁇ VIP ⁇ /24 dev eth0". For example, if the IP address in the parameter to-ip is the local ip, it can be determined that the address of the VIP is the main Redis server after the switch.
  • a ping message needs to be sent to the VIP; if it is determined that the corresponding PONG message can be received, you can After confirming that the link is normal, wait for the relevant time to start the VIP after the handover. If the PONG message corresponding to the sent ping cannot be received, it means that the current VIP is unbound, and the first Redis server after the switch is not bound, and the VIP needs to be bound to the first Redis server.
  • the above implementation can be achieved by the following code: "/bin/ip addr add ⁇ VIP ⁇ /24 dev eth0".
  • a possible implementation manner if the monitoring component of the first Redis server does not receive the connection return message, further includes:
  • the VIP address of the first Redis server is updated to the ARP cache, so that the gateway device of the Redis cluster confirms that the VIP address of the Redis cluster corresponds to the first Redis server.
  • the arp cache of the VIP in the local area network can be updated.
  • the above implementation can be achieved by the following code: /usr/sbin/arping-I eth0-A ⁇ VIP ⁇ -c 3.
  • the new VIP can be bound to the first Redis server, and the arp cache is updated, so that the gateway confirms that the mac address corresponding to the ip is on the first Redis server, so that the client can pass through the VIP in the event of a failure Access the first Redis server, thus realizing a highly available cluster that can drift through VIP.
  • the embodiment of the present invention provides a more efficient Redis cluster high-availability method. Compared with other clusters, the maintenance components are reduced and the cost of learning other components is eliminated; and the use of monitoring components is effectively reduced, saving The host resource that needs to be consumed.
  • the Redis active/standby switch process is relatively simple, and the client does not need to change the access ip to achieve the purpose of accessing the main Redis server after the switch.
  • an embodiment of the present invention provides a high-availability device for a Redis cluster.
  • the cluster includes at least two Redis servers and monitoring components configured corresponding to the Redis servers; the device include:
  • the monitoring unit 401 is configured to detect the connection link of each Redis server by initiating a detection thread
  • the processing unit 402 is configured to initiate a voting if it is determined that the connection link of the second Redis server is faulty; the second Redis server is the primary Redis server; and the secondary Redis server whose voting result is greater than or equal to half is determined to be with the first Redis server.
  • the second Redis server to switch from the Redis server; the VIP address of the first Redis server is set to the VIP address of the Redis cluster, so that the clients that access the Redis cluster can access the first Redis cluster according to the modified VIP address A Redis server.
  • processing unit 402 is specifically configured to:
  • the parameters transmitted by the monitoring component of the second Redis server during failover if it is determined that the source IP address in the parameters is the IP address of the second Redis server, initiate the unbinding operation of the VIP address; if It is determined that the destination IP address in the parameter is the IP address of the first Redis server, then it is detected whether the VIP address of the Redis cluster is in a connected state; if the connection return message is not received, the first Redis server The VIP address of is bound to the Redis cluster.
  • the processing unit 402 is further configured to: update the VIP address of the first Redis server to the ARP cache, so that the gateway device of the Redis cluster confirms that the VIP address of the Redis cluster corresponds to The first Redis server.
  • the monitoring unit 401 is specifically configured to:
  • the Redis cluster in the embodiment of the present invention obtains the read and write request sent by the application, it may include:
  • the Redis cluster receives a read and write request from an application, and first determines which VIP node the read and write request corresponds to. After the VIP node is determined, the Redis cluster selects one from the corresponding connection pool Connect the link and transmit the read and write request to the VIP node. The VIP node then determines which Redis server corresponds to the read and write request according to the data primary key value in the read and write request, and then performs a hash operation based on the data primary key value to generate the ha Ultimately, the port of the corresponding Redis server is determined, and the Redis instance corresponding to the read and write request is determined according to the determined port. After the Redis instance is determined, the Redis cluster obtains a long connection from the connection pool corresponding to the Redis instance, so that the read and write request can be sent through the long connection.
  • the Redis cluster in the embodiment of the present invention does not require cross-node access, which avoids that in the prior art, a large cluster of Redis version 3.0 or higher requires at least 3 main Redis servers, and the key is divided into slots. Each main Redis has a different slot.
  • the client accesses a certain Redis server, if the slot of the key is not in the Redis that is being accessed, it needs to be redirected to the Redis where the key is located, which is more efficient than the single Redis server. Access efficiency is low, and Redis commands that need to process multiple keys at the same time are not supported. For example, commands such as mset/mget do not support cross-node access.
  • FIG. 5 in the embodiment of the present invention, a schematic structural diagram of a computer device is shown.
  • the embodiment of the present invention provides a computer device.
  • the computer device may include a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002.
  • the communication bus 1002 is used to implement connection and communication between these components.
  • the user interface 1003 may include a display screen (Display) and an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface.
  • the network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface).
  • the memory 1005 may be a high-speed RAM memory, or a non-volatile memory (non-volatile memory), such as a magnetic disk memory.
  • the memory 1005 may also be a storage device independent of the foregoing processor 1001.
  • FIG. 5 does not constitute a limitation on the computer device, and may include more or less components than those shown in the figure, or a combination of certain components, or different component arrangements.
  • the memory 1005 may include an operating system, a network communication module, a user interface module, and an information recommendation model generation program.
  • the operating system is a program that manages and controls model parameters to obtain system hardware and software resources, and supports the generation of information recommendation models and the operation of other software or programs.
  • the user interface 1003 is mainly used to connect, the second server, the third server, etc., to communicate with each server;
  • the network interface 1004 is mainly used to connect to the background server, and to communicate with the background server;
  • the processor 1001 can be used to call the memory
  • the second Redis server is the main Redis server; the Redis server whose voting result is greater than or equal to half is determined as the switch to the second Redis server From the Redis server; the VIP address of the first Redis server is set to the VIP address of the Redis cluster, so that clients accessing the Redis cluster can access the first Redis server according to the modified VIP address.
  • the processor 1001 is specifically configured to:
  • the parameters transmitted by the monitoring component of the second Redis server during failover if it is determined that the source IP address in the parameters is the IP address of the second Redis server, initiate the unbinding operation of the VIP address; if It is determined that the destination IP address in the parameter is the IP address of the first Redis server, then it is detected whether the VIP address of the Redis cluster is in a connected state; if the connection return message is not received, the first Redis server The VIP address of is bound to the Redis cluster.
  • the processor 1001 is further configured to: update the VIP address of the first Redis server to the ARP cache, so that the gateway device of the Redis cluster confirms that the VIP address of the Redis cluster corresponds to The first Redis server.
  • the processor 1001 is specifically configured to:
  • These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing equipment to work in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including the instruction device.
  • the device implements the functions specified in one process or multiple processes in the flowchart and/or one block or multiple blocks in the block diagram.
  • These computer program instructions can also be loaded on a computer or other programmable data processing equipment, so that a series of operation steps are executed on the computer or other programmable equipment to produce computer-implemented processing, so as to execute on the computer or other programmable equipment.
  • the instructions provide steps for implementing functions specified in a flow or multiple flows in the flowchart and/or a block or multiple blocks in the block diagram.

Abstract

The embodiments of the present invention relate to the field of Fintech. Disclosed are a high availability method and apparatus for a Redis cluster, the cluster comprising at least two Redis servers and monitoring assemblies correspondingly configured for the Redis servers. The method comprises: a monitoring assembly of a first Redis server detecting a connection link of each Redis server by initiating a detection thread; if the monitoring assembly of the first Redis server determines that a connection link of a second Redis server has a fault, initiating a vote; and the monitoring assembly of the first Redis server determining a slave Redis server with a voting result greater than or equal to half as a slave Redis server for switching with the second Redis server. In the present invention, the VIP drift of a fault of a Redis server is realized, and the cost is reduced.

Description

一种Redis集群的高可用方法及装置High-availability method and device for Redis cluster
相关申请的交叉引用Cross references to related applications
本申请要求在2019年06月21日提交中国专利局、申请号为201910540450.2、申请名称为“一种Redis集群的高可用方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of a Chinese patent application filed with the Chinese Patent Office on June 21, 2019, the application number is 201910540450.2, and the application name is "a high-availability method and device for Redis clusters", the entire content of which is incorporated by reference In this application.
技术领域Technical field
本发明涉及金融科技(Fintech)的通信技术领域,尤其涉及一种Redis集群的高可用方法及装置。The present invention relates to the field of communication technology of financial technology (Fintech), and in particular to a high-availability method and device of a Redis cluster.
背景技术Background technique
随着计算机技术的发展,越来越多的技术应用在金融领域,传统金融业正在逐步向金融科技(Fintech)转变,Redis集群技术也不例外,但由于金融行业的安全性、实时性要求,也对技术提出的更高的要求。With the development of computer technology, more and more technologies are applied in the financial field. The traditional financial industry is gradually transforming into Fintech. Redis cluster technology is no exception. However, due to the security and real-time requirements of the financial industry, There are also higher requirements for technology.
目前web应用系统为了解决高并发带来的性能问题,都会在web应用系统与数据库之间采取缓存层,使用最为广泛的就是Redis(Redis本质上是一个键-值类型的内存数据库)。Redis作为软件和传统数据库之间的缓冲层,操作命令简单,在保证了数据有效性的情况下,同时也保证了高性能。At present, in order to solve the performance problems caused by high concurrency, web application systems will adopt a caching layer between the web application system and the database. The most widely used is Redis (Redis is essentially a key-value memory database). As a buffer layer between software and traditional databases, Redis has simple operation commands. While ensuring the validity of data, it also guarantees high performance.
现有技术中,为实现Redis的高可用,减少服务中断时间为目的的服务器,通过保护用户的业务程序对外不间断提供的服务,把因软件/硬件/人为造成的故障对业务的影响降低到最小程度,需要迁移组件进行故障迁移、需要多个监控组件进行服务器的监控,需要的组件过多,维护成本较高。In the prior art, in order to achieve the high availability of Redis and reduce the service interruption time of the server, by protecting the service provided by the user's business program continuously, the impact of the software/hardware/man-made failure on the business is reduced to At a minimum, components need to be migrated for fault migration, multiple monitoring components are needed for server monitoring, too many components are required, and maintenance costs are high.
发明内容Summary of the invention
本发明实施例提供一种Redis集群的高可用方法及装置,用以解决现有技术访问Redis数据库的组件过多,维护成本较高的问题。The embodiment of the present invention provides a high-availability method and device for a Redis cluster to solve the problem of too many components accessing the Redis database in the prior art and high maintenance cost.
本发明实施例提供一种Redis集群的高可用方法,所述集群包括至少两个Redis服务器,及与所述Redis服务器对应配置的监控组件;该方法包括:The embodiment of the present invention provides a high-availability method for a Redis cluster. The cluster includes at least two Redis servers and monitoring components configured corresponding to the Redis servers; the method includes:
第一Redis服务器的监控组件通过发起侦测线程侦测各Redis服务器的连接链路;The monitoring component of the first Redis server detects the connection link of each Redis server by initiating a detection thread;
所述第一Redis服务器的监控组件若确定第二Redis服务器连接链路发生故障,则发起投票;所述第二Redis服务器为主Redis服务器;If the monitoring component of the first Redis server determines that the connection link of the second Redis server is faulty, it initiates a vote; the second Redis server is the master Redis server;
所述第一Redis服务器的监控组件若确定投票结果大于或等于半数的从Redis服务器为所述第一Redis服务器,则将所述第一Redis服务器确定为与所述第二Redis服务器进行切换的从Redis服务器;If the monitoring component of the first Redis server determines that the slave Redis server whose voting result is greater than or equal to half is the first Redis server, the first Redis server is determined to be the slave that switches with the second Redis server Redis server;
所述第一Redis服务器的监控组件将所述第一Redis服务器的VIP地址设置为所述Redis集群的VIP地址,以使访问所述Redis集群的客户端根据修改后的VIP地址访问所述第一Redis服务器。The monitoring component of the first Redis server sets the VIP address of the first Redis server to the VIP address of the Redis cluster, so that clients that access the Redis cluster can access the first Redis cluster according to the modified VIP address. Redis server.
一种可能的实现方式,所述第一Redis服务器的监控组件将所述第一Redis服务器的VIP地址设置为所述Redis集群的VIP地址,包括:In a possible implementation manner, the monitoring component of the first Redis server setting the VIP address of the first Redis server to the VIP address of the Redis cluster includes:
所述第一Redis服务器的监控组件获取所述第二Redis服务器的监控组件在故障切换时传出的参数;Acquiring, by the monitoring component of the first Redis server, the parameters transmitted by the monitoring component of the second Redis server during failover;
所述第一Redis服务器的监控组件若确定所述参数中的源IP地址为所述第二Redis服务器的IP地址,则发起VIP地址的解绑操作;If the monitoring component of the first Redis server determines that the source IP address in the parameter is the IP address of the second Redis server, it initiates an unbinding operation of the VIP address;
所述第一Redis服务器的监控组件若确定所述参数中的目的IP地址为所述第一Redis服务器的IP地址,则检测所述Redis集群的VIP地址是否为连通状态;If the monitoring component of the first Redis server determines that the destination IP address in the parameter is the IP address of the first Redis server, it detects whether the VIP address of the Redis cluster is in a connected state;
所述第一Redis服务器的监控组件若未接收到连通返回消息,则将所述第一Redis服务器的VIP地址绑定至所述Redis集群。If the monitoring component of the first Redis server does not receive the connection return message, it binds the VIP address of the first Redis server to the Redis cluster.
一种可能的实现方式,所述第一Redis服务器的监控组件若未接收到连通返回消息,还包括:In a possible implementation manner, if the monitoring component of the first Redis server does not receive the connection return message, the method further includes:
将所述第一Redis服务器的VIP地址更新至ARP缓存,以使所述Redis集群的网关设备确认所述Redis集群的VIP地址对应所述第一Redis服务器。The VIP address of the first Redis server is updated to the ARP cache, so that the gateway device of the Redis cluster confirms that the VIP address of the Redis cluster corresponds to the first Redis server.
一种可能的实现方式,所述第一Redis服务器的监控组件通过发起侦测线程侦测各Redis服务器的连接链路,包括:In a possible implementation manner, the monitoring component of the first Redis server detects the connection link of each Redis server by initiating a detection thread, including:
所述第一Redis服务器的监控组件向各Redis服务器发送心跳检测;The monitoring component of the first Redis server sends a heartbeat detection to each Redis server;
若心跳检测成功,则从心跳检测成功的Redis实例确定可用的连接链路。If the heartbeat detection is successful, the available connection link is determined from the Redis instance that succeeded in the heartbeat detection.
本发明实施例提供一种Redis集群的高可用装置,所述集群包括至少两个Redis服务器,及与所述Redis服务器对应配置的监控组件;该装置包括:An embodiment of the present invention provides a high-availability device for a Redis cluster. The cluster includes at least two Redis servers and monitoring components configured corresponding to the Redis servers; the device includes:
监控单元,用于通过发起侦测线程侦测各Redis服务器的连接链路;The monitoring unit is used to detect the connection link of each Redis server by initiating a detection thread;
处理单元,用于若确定第二Redis服务器连接链路发生故障,则发起投票;所述第二Redis服务器为主Redis服务器;若确定投票结果大于或等于半数的从Redis服务器为所述第一Redis服务器,则将所述第一Redis服务器确定为与所述第二Redis服务器进行切换的从Redis服务器;将所述第一Redis服务器的VIP地址设置为所述Redis集群的VIP地址,以使访问所述Redis集群的客户端根据修改后的VIP地址访问所述第一Redis服务器。The processing unit is configured to initiate a voting if it is determined that the connection link of the second Redis server is faulty; the second Redis server is the primary Redis server; if it is determined that the secondary Redis server whose voting result is greater than or equal to half is the first Redis Server, the first Redis server is determined to be the slave Redis server that switches with the second Redis server; the VIP address of the first Redis server is set to the VIP address of the Redis cluster, so that the The client of the Redis cluster accesses the first Redis server according to the modified VIP address.
一种可能的实现方式,所述处理单元,具体用于:In a possible implementation manner, the processing unit is specifically configured to:
获取所述第二Redis服务器的监控组件在故障切换时传出的参数;若确定所述参数中的源IP地址为所述第二Redis服务器的IP地址,则发起VIP地址的解绑操作;若确定所述参数中的目的IP地址为所述第一Redis服务器的IP地址,则检测所述Redis集群的VIP地址是否为连通状态;若未接收到连通返回消息,则将所述第一Redis服务器的VIP地址绑定至所述Redis集群。Obtain the parameters transmitted by the monitoring component of the second Redis server during failover; if it is determined that the source IP address in the parameters is the IP address of the second Redis server, initiate the unbinding operation of the VIP address; if It is determined that the destination IP address in the parameter is the IP address of the first Redis server, then it is detected whether the VIP address of the Redis cluster is in a connected state; if the connection return message is not received, the first Redis server The VIP address of is bound to the Redis cluster.
一种可能的实现方式,所述处理单元,还用于:将所述第一Redis服务器的VIP地址更新至ARP缓存,以使所述Redis集群的网关设备确认所述Redis集群的VIP地址对应所述第一Redis服务器。In a possible implementation manner, the processing unit is further configured to: update the VIP address of the first Redis server to the ARP cache, so that the gateway device of the Redis cluster confirms that the VIP address of the Redis cluster corresponds to the The first Redis server is described.
一种可能的实现方式,所述监控单元,具体用于:In a possible implementation manner, the monitoring unit is specifically used for:
向各Redis服务器发送心跳检测;若心跳检测成功,则从心跳检测成功的Redis实例确定可用的连接链路。Send a heartbeat detection to each Redis server; if the heartbeat detection is successful, the available connection link is determined from the Redis instance with a successful heartbeat detection.
本发明实施例通过所述集群包括至少两个Redis服务器,及与所述Redis服务器对应配置的监控组件;减少了现有技术中的监控组件的个数;通过第一Redis服务器的监控组件通过发起侦测线程侦测各Redis服务器的连接链路;所述第一Redis服务器的监控组件若确定第二Redis服务器连接链路发生故障,则发起投票;所述第二Redis服务器为主Redis服务器;所述第一Redis服务器的监控组件将投票结果大于或等于半数的从Redis服务器确定为与所述第二Redis服务器进行切换的从Redis服务器;所述第一Redis服务器的监控组件将所述第一Redis服务器的VIP地址设置为所述Redis集群的VIP地址,以使访问所述Redis集群的客户端根据修改后的VIP地址访问所述第一Redis服务器。在减少监控组件的同时,实现了Redis服务器的故障的VIP漂移,不需要增加额外的监控组件,并且,由于VIP地址的设置是通过监控组件完成的,不需要现有技术中的其他组件完成,进一步减少了组件的设置,降低了维护的成本。In the embodiment of the present invention, the cluster includes at least two Redis servers and monitoring components configured corresponding to the Redis servers; the number of monitoring components in the prior art is reduced; the monitoring component of the first Redis server is initiated by The detection thread detects the connection link of each Redis server; if the monitoring component of the first Redis server determines that the connection link of the second Redis server is faulty, it initiates a vote; the second Redis server is the main Redis server; The monitoring component of the first Redis server determines that the secondary Redis server whose voting result is greater than or equal to half is the secondary Redis server that switches with the second Redis server; the monitoring component of the first Redis server determines the first Redis The VIP address of the server is set to the VIP address of the Redis cluster, so that the client accessing the Redis cluster accesses the first Redis server according to the modified VIP address. While reducing the monitoring components, it realizes the VIP drift of the Redis server failure without adding additional monitoring components. Moreover, because the setting of the VIP address is completed by the monitoring component, it does not require other components in the prior art to complete, It further reduces the set of components and reduces the cost of maintenance.
附图说明Description of the drawings
为了更清楚地说明本发明实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简要介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域的普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly describe the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings needed in the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative work, other drawings can be obtained from these drawings.
图1a为本发明实施例提供一种Redis集群架构;Figure 1a is a Redis cluster architecture provided by an embodiment of the present invention;
图1b为本发明实施例提供一种Redis集群架构;Figure 1b shows a Redis cluster architecture provided by an embodiment of the present invention;
图2为本发明实施例提供一种Redis集群的架构示意图;2 is a schematic diagram of the architecture of a Redis cluster provided by an embodiment of the present invention;
图3为本发明实施例提供一种Redis集群的高可用方法流程示意图;FIG. 3 is a schematic flowchart of a high-availability method for a Redis cluster provided by an embodiment of the present invention;
图4为本发明实施例提供一种Redis集群的高可用装置的结构示意图;4 is a schematic structural diagram of a high-availability device for Redis cluster provided by an embodiment of the present invention;
图5为本发明实施例还提供一种Redis监控组件的结构示意图。FIG. 5 is a schematic structural diagram of a Redis monitoring component provided by an embodiment of the present invention.
具体实施方式Detailed ways
为了使本发明的目的、技术方案和优点更加清楚,下面将结合附图对本发明作进一步地详细描述,显然,所描述的实施例仅仅是本发明一部份实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其它实施例,都属于本发明保护的范围。In order to make the objectives, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, not all of the embodiments. . Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative work shall fall within the protection scope of the present invention.
高可用集群:是指以减少服务中断时间为目的的服务器集群技术。它通过保护用户的业务程序对外不间断提供的服务,将因软件、硬件或人为造成的故障对业务的影响降低到最小程度。High-availability cluster: refers to server cluster technology for the purpose of reducing service interruption time. It minimizes the impact of software, hardware, or human-caused failures on the business by protecting the user's business program to provide uninterrupted services to the outside world.
Redis服务器:一个使用ANSI C编写的开源的、支持网络、基于内存、可选持久性的键值对存储数据库,通常也用作缓存数据库。Redis server: an open source, network-supported, memory-based, optional persistence key-value storage database written in ANSI C, and is usually used as a cache database.
监控组件sentinel:监听Redis服务器的可用状态。当用Redis做主Redis服务器以及从Redis服务器的高可用方案时,假如主Redis服务器宕机了,Redis本身(包括它的很多客户端)都没有实现自动进行主备切换,通过监控组件sentinel组件,可以监控Redis是否按照预期良好地运行;如果发现某个Redis节点运行出现故障,能够通知另外一个进程(例如它的客户端),进行自动切换。Monitoring component sentinel: monitor the available status of the Redis server. When using Redis as a high-availability solution for the main Redis server and the secondary Redis server, if the main Redis server goes down, Redis itself (including many of its clients) does not realize automatic active/standby switching. Through the monitoring component sentinel component, you can Monitor whether Redis is running as expected; if a Redis node is found to be malfunctioning, it can notify another process (such as its client) to automatically switch.
Redis-监控组件sentinel本身也是一个独立运行的进程,它能监控多个主Redis服务器-从Redis服务器集群,发现主Redis服务器宕机后能进行自动切换。只使用单个监控组件sentinel进程来监控Redis集群是不可靠的,当监控组件sentinel进程运行出错,或者是网络堵塞,那么将无法实现Redis集群的主备切换(监控组件sentinel本身也有单点问题,single-point-of-failure)整个集群系统将无法按照预期的方式运行。所以有必要将监控组件sentinel集群,即需要设置有多个监控组件sentinel。The Redis-monitoring component sentinel itself is also an independently running process. It can monitor multiple master Redis servers-slave Redis server clusters, and automatically switch after the master Redis server is down. It is unreliable to use only a single monitoring component sentinel process to monitor the Redis cluster. When the monitoring component sentinel process runs incorrectly, or the network is blocked, the active and standby redis cluster cannot be switched (the monitoring component sentinel itself also has a single point of problem, single -point-of-failure) The entire cluster system will not operate as expected. Therefore, it is necessary to cluster the monitoring component sentinel, that is, multiple monitoring components sentinel need to be set up.
当一个主Redis服务器节点不可用时,监控组件能够选举出主Redis服务器的至少一个从Redis服务器中的一个来作为新的主Redis服务器。其它的从Redis服务器节点会将它所追随的主Redis服务器的地址改为:被提升为主Redis服务器的从Redis服务器的新地址。如果大多数监控组件sentinel能够 互相通信,最终将会有一个被授权去进行故障迁移,保证了Redis的活跃性。When a master Redis server node is unavailable, the monitoring component can elect at least one of the slave Redis servers of the master Redis server as the new master Redis server. Other slave Redis server nodes will change the address of the master Redis server that it follows to: the new address of the slave Redis server promoted to the master Redis server. If most of the monitoring components sentinels can communicate with each other, there will eventually be one authorized to perform fault migration, ensuring the liveness of Redis.
Keepalived:一个负载均衡集群下健康状态检查的组件以及用于保持主备机之间的故障转移组件。Keepalived: A component for health check in a load balancing cluster and a component for maintaining failover between the active and standby machines.
HAProxy:是一个使用C语言编写的自由及开放源代码软件,其提供高可用性、负载均衡,以及基于TCP和HTTP的应用程序代理。HAProxy: is a free and open source software written in C language that provides high availability, load balancing, and application proxy based on TCP and HTTP.
Vip:集群中供外部访问的ip地址,通常只有一个。Vip: The ip address for external access in the cluster, usually only one.
在实际应用中,Redis的部署有多种结构,本发明实施例中,提供部署方式的示例,如图1a所示,一种部署方式是部署VIP节点,由VIP节点管控多个节点,每个节点管理一个实例组,由VIP节点实现数据分片的功能,即应用程序发送的读写请求通过VIP节点分配至相应节点对应的实例组处理。In practical applications, Redis deployment has multiple structures. In the embodiment of the present invention, examples of deployment methods are provided. As shown in Figure 1a, one deployment method is to deploy VIP nodes. The VIP nodes manage multiple nodes, each The node manages an instance group, and the VIP node implements the function of data fragmentation, that is, the read and write requests sent by the application are allocated to the corresponding instance group of the corresponding node for processing by the VIP node.
若出现故障迁移,针对Redis服务器的主从切换,可以通过Keepalived将从Redis服务器切换为主Redis服务器。Keepalived可以设置于每个Redis服务器中,若监控组件sentinel确定当前的主Redis服务器运行故障,确定需要进行故障迁移,可以通过Keepalived,将故障的主Redis服务器上的进程,迁移至监控组件sentinel确定出的新的主Redis服务器。In case of failure migration, for the master-slave switch of the Redis server, you can switch from the Redis server to the master Redis server through Keepalived. Keepalived can be set in each Redis server. If the monitoring component sentinel determines that the current main Redis server is running faulty, it is determined that fault migration is required. You can use Keepalived to migrate the process on the failed main Redis server to the monitoring component sentinel. The new main Redis server.
针对VIP节点的切换,可以将HAProxy组件设置于每个Redis服务器中,通过HAProxy组件可以对Redis服务器的主从切换实现即时探测,若确定Redis服务器的主从切换完成,则启用新的主Redis服务器的VIP地址,将该VIP地址设置为当前的Redis集群的VIP地址,具体的设置可以通过虚拟路由冗余协议(Virtual Router Redundancy Protocol,简称VRRP)实现VIP地址的切换。For the switch of VIP nodes, the HAProxy component can be set in each Redis server, and the master-slave switch of the Redis server can be detected instantly through the HAProxy component. If it is determined that the master-slave switch of the Redis server is completed, the new master Redis server is activated Set the VIP address as the VIP address of the current Redis cluster. The specific setting can be implemented through the Virtual Router Redundancy Protocol (VRRP) to switch the VIP address.
针对VIP地址的切换,VRRP可以将第一Redis服务器的物理路由器设备和第二Redis服务器的物理路由器设备虚拟成一个虚拟路由,这个虚拟路由器通过虚拟IP(VIP)对外提供服务,而在虚拟路由器内部可以包括多个物理路由器协同工作,同一时间只有一台物理路由器对外提供服务,即主路由器,例如,若当前的主Redis服务器为第一Redis服务器,则此时,只通过第一Redis服务器的物理路由器对外提供服务器。其中,主路由器由选举算法产生, 它拥有对外服务的虚拟IP,提供各种网络功能,如:ARP请求,ICMP(Internet Control Message Protocol,互联网控制消息协议)数据转发等,而且其它的物理路由器不拥有对外的虚拟IP,也不提供对外网络功能,仅仅接收主路由器的VRRP状态通告信息,这些路由器为备份路由器。当主路由器失败时,处于备份路由器将重新进行选举,产生一个新的主路由器进入主路由器,继续提供对外服务,整个切换对客户端来说是完全透明的。For the switching of VIP addresses, VRRP can virtualize the physical router device of the first Redis server and the physical router device of the second Redis server into a virtual router. This virtual router provides services to the outside through a virtual IP (VIP), while inside the virtual router It can include multiple physical routers working together. Only one physical router provides external services at the same time, that is, the main router. For example, if the current main Redis server is the first Redis server, at this time, only the physical of the first Redis server The router provides external servers. Among them, the main router is generated by an election algorithm. It has a virtual IP for external services and provides various network functions, such as: ARP request, ICMP (Internet Control Message Protocol, Internet Control Message Protocol) data forwarding, etc., and other physical routers do not It has an external virtual IP and does not provide external network functions. It only receives VRRP status notification information from the main routers, which are backup routers. When the main router fails, the backup router will re-elect and generate a new main router to enter the main router and continue to provide external services. The entire switchover is completely transparent to the client.
在一个主Redis服务器与一个或多个从Redis服务器的情况下,每个主Redis服务器和从Redis服务器分别配置一个监控组件sentinel组件;另外,由于需要选举出主Redis服务器的多个从Redis服务器中的一个来作为新的主Redis服务器,若主Redis服务器与从Redis服务器的总数为偶数,为保证选举的顺利进行,需要额外设置1个Redis服务器的监听组件监控组件sentinel,该问题在大型集群中并不明显,但是在小型集群中,额外设置的组件增加维护的成本。In the case of a master Redis server and one or more slave Redis servers, each master Redis server and slave Redis server is configured with a monitoring component sentinel component; in addition, due to the need to elect multiple slave Redis servers of the master Redis server One of them will be used as the new master Redis server. If the total number of the master Redis server and the slave Redis server is an even number, in order to ensure the smooth progress of the election, an additional monitoring component sentinel of the Redis server needs to be set up. The problem is in a large cluster It's not obvious, but in small clusters, additional components increase maintenance costs.
如图1b所示,本发明实施例提供另一种部署方式,Redis集群中有若干实例组,应用程序与多个实例组直连,即应用程序连接有多组主从配合的服务器,每个主服务器中运行若干负责数据备份的实例。As shown in Figure 1b, the embodiment of the present invention provides another deployment method. There are several instance groups in a Redis cluster, and the application is directly connected to multiple instance groups, that is, the application is connected to multiple sets of master-slave servers, each Several instances responsible for data backup are running in the main server.
该方案下,为不基于VIP的集群的部署方案,需要在发生切换时候,主Redis服务器的切换需要通过监控组件sentinel通知客户端,客户端需要重新连到切换后的主Redis服务器上。在具体实施过程中,客户端需要监听监控组件sentinel的事件队列,获取切换后的主Redis服务器的ip端口,并向切换后的主Redis服务器的ip端口发起访问,相比具有VIP节点的部署场景,不利于切换的及时性。Under this scheme, for a non-VIP-based cluster deployment scheme, when switching occurs, the switch of the main Redis server needs to notify the client through the monitoring component sentinel, and the client needs to reconnect to the switched main Redis server. In the specific implementation process, the client needs to monitor the event queue of the monitoring component sentinel, obtain the ip port of the main Redis server after the switch, and initiate access to the ip port of the main Redis server after the switch, compared to the deployment scenario with VIP nodes , Is not conducive to the timeliness of handover.
基于相同的理由,由于需要从多个从Redis服务器中选举出一个从Redis服务器来作为新的主Redis服务器,若主Redis服务器与从Redis服务器的总数为偶数,为保证选举的顺利进行,在一个主Redis服务器和一个从Redis服务器的前提下,需要额外设置1个监控组件sentinel,在小型集群中,额外设置的组件会增加维护的成本。For the same reason, since it is necessary to elect a slave Redis server from multiple slave Redis servers as the new master Redis server, if the total number of the master Redis server and the slave Redis server is an even number, in order to ensure the smooth progress of the election, Under the premise of a master Redis server and a slave Redis server, an additional monitoring component sentinel is required. In a small cluster, the additional components will increase the cost of maintenance.
基于上述问题,参见图2所示,所述集群包括至少两个Redis服务器,及与所述Redis服务器对应配置的监控组件;如图3所示,本发明实施例提供一种Redis集群的高可用方法流程示意图,具体地实现方法包括:Based on the above problems, referring to Figure 2, the cluster includes at least two Redis servers and monitoring components configured corresponding to the Redis servers; as shown in Figure 3, the embodiment of the present invention provides a high availability of a Redis cluster Schematic diagram of the method flow, the specific implementation methods include:
步骤301:第一Redis服务器的监控组件sentinel通过发起侦测线程侦测各Redis服务器的连接链路;Step 301: The monitoring component sentinel of the first Redis server detects the connection link of each Redis server by initiating a detection thread;
一种可能的实现方式,所述第一Redis服务器的监控组件通过发起侦测线程侦测各Redis服务器的连接链路,包括:In a possible implementation manner, the monitoring component of the first Redis server detects the connection link of each Redis server by initiating a detection thread, including:
所述第一Redis服务器的监控组件向各Redis服务器发送心跳检测;The monitoring component of the first Redis server sends a heartbeat detection to each Redis server;
若心跳检测成功,则从心跳检测成功的Redis实例确定可用的连接链路。If the heartbeat detection is successful, the available connection link is determined from the Redis instance that succeeded in the heartbeat detection.
具体的,可以启动单独的线程定期地向每个Redis实例发送检测报文,根据其响应来判断其健康状态。另外,也向外部调用者开放了反馈接口,当调用者读写Redis遇到异常时,可以调用反馈接口,以便及时对Redis实例的健康状态进行更新。Specifically, a separate thread can be started to periodically send detection messages to each Redis instance, and its health status can be judged based on its response. In addition, the feedback interface is also opened to external callers. When the caller encounters an exception while reading and writing Redis, the feedback interface can be called to update the health status of the Redis instance in time.
步骤302:第一Redis服务器的监控组件若确定第二Redis服务器连接链路发生故障,则发起投票;所述第二Redis服务器为主Redis服务器;Step 302: If the monitoring component of the first Redis server determines that the connection link of the second Redis server is faulty, it initiates a vote; the second Redis server is the master Redis server;
具体的,监控组件sentinel在监听到主Redis服务器在特定时间连接不上后,确认第二Redis服务器故障,需要触发故障转移。Specifically, after the monitoring component sentinel detects that the main Redis server cannot be connected at a specific time, it confirms that the second Redis server is faulty and needs to trigger a failover.
步骤303:第一Redis服务器的监控组件若确定投票结果大于或等于半数的从Redis服务器为所述第一Redis服务器,则将所述第一Redis服务器确定为与所述第二Redis服务器进行切换的从Redis服务器;Step 303: If the monitoring component of the first Redis server determines that the secondary Redis server whose voting result is greater than or equal to half is the first Redis server, then the first Redis server is determined to be the one to switch to the second Redis server From the Redis server;
在具体实施过程中,所有监听主Redis服务器的监控组件sentinel都参与投票,选举出一个从Redis服务器切换成主Redis服务器。在只有一个从Redis服务器的架构场景下,并不需要更多的监控组件sentinel参与投票,只需要一半的投票即可,这样既可以在主Redis服务器宕机情况下保证了能够切换成功,并且也节约了监控组件sentinel的资源。对应的,本发明实施例中的投票方式为大于或等于半数,具体的代码可以如下:In the specific implementation process, all the monitoring components sentinels that monitor the main Redis server participate in the voting and elect a switch from the Redis server to the main Redis server. In an architecture scenario where there is only one slave Redis server, there is no need for more monitoring components sentinel to participate in the voting, only half of the voting is enough, so that the success of the switch can be guaranteed when the main Redis server is down, and also Save the resources of the monitoring component sentinel. Correspondingly, the voting method in the embodiment of the present invention is greater than or equal to half, and the specific code may be as follows:
监控组件sentinel.c:voters_quorum=voters/2;Monitoring component sentinel.c:voters_quorum=voters/2;
从而实现了集群中只有半数的监控组件sentinel就可以完成故障转移的触发。In this way, only half of the monitoring components sentinel in the cluster can trigger the failover.
步骤304:第一Redis服务器的监控组件将所述第一Redis服务器的VIP地址设置为所述Redis集群的VIP地址,以使访问所述Redis集群的客户端根据修改后的VIP地址访问所述第一Redis服务器。Step 304: The monitoring component of the first Redis server sets the VIP address of the first Redis server to the VIP address of the Redis cluster, so that the clients that access the Redis cluster can access the first Redis cluster according to the modified VIP address. A Redis server.
本发明实施例通过所述集群包括至少两个Redis服务器,及与所述Redis服务器对应配置的监控组件;减少了现有技术中的监控组件的个数;通过第一Redis服务器的监控组件通过发起侦测线程侦测各Redis服务器的连接链路;所述第一Redis服务器的监控组件若确定第二Redis服务器连接链路发生故障,则发起投票;所述第二Redis服务器为主Redis服务器;所述第一Redis服务器的监控组件将投票结果大于或等于半数的从Redis服务器确定为与所述第二Redis服务器进行切换的从Redis服务器;所述第一Redis服务器的监控组件将所述第一Redis服务器的VIP地址设置为所述Redis集群的VIP地址,以使访问所述Redis集群的客户端根据修改后的VIP地址访问所述第一Redis服务器。In the embodiment of the present invention, the cluster includes at least two Redis servers and monitoring components configured corresponding to the Redis servers; the number of monitoring components in the prior art is reduced; the monitoring component of the first Redis server is initiated by The detection thread detects the connection link of each Redis server; if the monitoring component of the first Redis server determines that the connection link of the second Redis server is faulty, it initiates a vote; the second Redis server is the main Redis server; The monitoring component of the first Redis server determines that the secondary Redis server whose voting result is greater than or equal to half is the secondary Redis server that switches with the second Redis server; the monitoring component of the first Redis server determines the first Redis The VIP address of the server is set to the VIP address of the Redis cluster, so that the client accessing the Redis cluster accesses the first Redis server according to the modified VIP address.
通过投票机制实现Redis集群中Redis服务器的切换,在减少监控组件的基础上,实现了Redis服务器的故障的VIP漂移,不需要增加额外的监控组件,并且,由于VIP地址的设置是通过监控组件完成的,不需要现有技术中的其他组件完成,从而进一步减少了组件的设置,降低了维护的成本。使得银行等金融机构的Redis集群进行Redis服务器切换时,所花费的成本更低,维护成本也降低,具有更加明显的经济效益。The redis server switch in the Redis cluster is realized through the voting mechanism. On the basis of reducing the monitoring components, the VIP drift of the failure of the Redis server is realized, no additional monitoring components are required, and because the setting of the VIP address is completed through the monitoring component Yes, it does not require other components in the prior art to complete, thereby further reducing component settings and reducing maintenance costs. When the Redis clusters of banks and other financial institutions switch Redis servers, the cost is lower and the maintenance cost is also reduced, which has more obvious economic benefits.
在步骤304中,一种可能的实现方式,包括:In step 304, a possible implementation manner includes:
步骤一、第一Redis服务器的监控组件获取所述第二Redis服务器的监控组件在故障切换时传出的参数;Step 1: The monitoring component of the first Redis server obtains the parameters transmitted by the monitoring component of the second Redis server during failover;
步骤二、第一Redis服务器的监控组件若确定所述参数中的源IP地址为所述第二Redis服务器的IP地址,则发起VIP地址的解绑操作;Step 2: If the monitoring component of the first Redis server determines that the source IP address in the parameter is the IP address of the second Redis server, it initiates an unbinding operation of the VIP address;
步骤三、第一Redis服务器的监控组件若确定所述参数中的目的IP地址 为所述第一Redis服务器的IP地址,则检测所述Redis集群的VIP地址是否为连通状态;Step 3: If the monitoring component of the first Redis server determines that the destination IP address in the parameter is the IP address of the first Redis server, it detects whether the VIP address of the Redis cluster is in a connected state;
步骤四、第一Redis服务器的监控组件若未接收到连通返回消息,则将所述第一Redis服务器的VIP地址绑定至所述Redis集群。Step 4: If the monitoring component of the first Redis server does not receive the connection return message, it binds the VIP address of the first Redis server to the Redis cluster.
在具体实施过程中,在Redis集群的主Redis服务器故障转移时会触发一个脚本,该脚本可以是shell语言编写。In the specific implementation process, a script is triggered when the main Redis server of the Redis cluster fails over. The script can be written in shell language.
具体的,该脚本用于判断监控组件从所述第二Redis服务器的监控组件在故障切换时传出的参数。例如,参数from-ip中的IP地址为本机ip,则可以VIP绑定的地址仍为第二Redis服务器,因此,可以通过操作系统的ip命令,执行解绑VIP操作。例如,“/bin/ip addr del{VIP}/24 dev eth0”。例如,参数to-ip中的IP地址为本机ip,则可以确定VIP的地址为切换后的主Redis服务器,因此,需要向VIP发送ping消息;若确定可以接收到对应的PONG消息,则可以确定链路正常,则等待相关时间,以启动切换后的VIP。如果无法接收到发送的ping对应的PONG消息,则说明当前的VIP解绑,并未绑定切换后的第一Redis服务器,需要在第一Redis服务器上绑定该VIP。上述实现方式可以通过以下代码实现:“/bin/ip addr add{VIP}/24 dev eth0”。Specifically, the script is used to determine the parameters transmitted by the monitoring component from the monitoring component of the second Redis server during failover. For example, if the IP address in the parameter from-ip is the local ip, the address that can be bound by the VIP is still the second Redis server. Therefore, the VIP unbinding operation can be performed through the ip command of the operating system. For example, "/bin/ip addr del{VIP}/24 dev eth0". For example, if the IP address in the parameter to-ip is the local ip, it can be determined that the address of the VIP is the main Redis server after the switch. Therefore, a ping message needs to be sent to the VIP; if it is determined that the corresponding PONG message can be received, you can After confirming that the link is normal, wait for the relevant time to start the VIP after the handover. If the PONG message corresponding to the sent ping cannot be received, it means that the current VIP is unbound, and the first Redis server after the switch is not bound, and the VIP needs to be bound to the first Redis server. The above implementation can be achieved by the following code: "/bin/ip addr add{VIP}/24 dev eth0".
在具有ARP(Address Resolution Protocol,地址解析协议,即ARP)的场景中,一种可能的实现方式,所述第一Redis服务器的监控组件若未接收到连通返回消息,还包括:In a scenario with ARP (Address Resolution Protocol, namely ARP), a possible implementation manner, if the monitoring component of the first Redis server does not receive the connection return message, further includes:
将所述第一Redis服务器的VIP地址更新至ARP缓存,以使所述Redis集群的网关设备确认所述Redis集群的VIP地址对应所述第一Redis服务器。The VIP address of the first Redis server is updated to the ARP cache, so that the gateway device of the Redis cluster confirms that the VIP address of the Redis cluster corresponds to the first Redis server.
具体的,可以更新局域网内的该VIP的arp缓存。上述实现方式可以通过以下代码实现:/usr/sbin/arping-I eth0-A{VIP}-c 3。Specifically, the arp cache of the VIP in the local area network can be updated. The above implementation can be achieved by the following code: /usr/sbin/arping-I eth0-A{VIP}-c 3.
因此,可以使得新的VIP会绑定到第一Redis服务器上,并且更新了arp缓存,使得网关确认该ip对应的mac地址是在第一Redis服务器上,这样在故障时客户端就可以通过VIP访问第一Redis服务器,从而实现了一个可以通过VIP漂移的高可用集群。Therefore, the new VIP can be bound to the first Redis server, and the arp cache is updated, so that the gateway confirms that the mac address corresponding to the ip is on the first Redis server, so that the client can pass through the VIP in the event of a failure Access the first Redis server, thus realizing a highly available cluster that can drift through VIP.
本发明实施例提供一种效率更高的Redis集群的高可用方法,相对其他集群来说,减少了维护的组件,免去了学习其他组件的成本;并且,有效减少了监控组件的使用,节约了需消耗的主机资源。Redis主备切换过程相对其他简单,并且客户端是不需要更换访问的ip从而达到访问切换后的主Redis服务器的目的。The embodiment of the present invention provides a more efficient Redis cluster high-availability method. Compared with other clusters, the maintenance components are reduced and the cost of learning other components is eliminated; and the use of monitoring components is effectively reduced, saving The host resource that needs to be consumed. The Redis active/standby switch process is relatively simple, and the client does not need to change the access ip to achieve the purpose of accessing the main Redis server after the switch.
基于相同的发明构思,如图4所示,本发明实施例提供一种Redis集群的高可用装置,所述集群包括至少两个Redis服务器,及与所述Redis服务器对应配置的监控组件;该装置包括:Based on the same inventive concept, as shown in FIG. 4, an embodiment of the present invention provides a high-availability device for a Redis cluster. The cluster includes at least two Redis servers and monitoring components configured corresponding to the Redis servers; the device include:
监控单元401,用于通过发起侦测线程侦测各Redis服务器的连接链路;The monitoring unit 401 is configured to detect the connection link of each Redis server by initiating a detection thread;
处理单元402,用于若确定第二Redis服务器连接链路发生故障,则发起投票;所述第二Redis服务器为主Redis服务器;将投票结果大于或等于半数的从Redis服务器确定为与所述第二Redis服务器进行切换的从Redis服务器;将所述第一Redis服务器的VIP地址设置为所述Redis集群的VIP地址,以使访问所述Redis集群的客户端根据修改后的VIP地址访问所述第一Redis服务器。The processing unit 402 is configured to initiate a voting if it is determined that the connection link of the second Redis server is faulty; the second Redis server is the primary Redis server; and the secondary Redis server whose voting result is greater than or equal to half is determined to be with the first Redis server. The second Redis server to switch from the Redis server; the VIP address of the first Redis server is set to the VIP address of the Redis cluster, so that the clients that access the Redis cluster can access the first Redis cluster according to the modified VIP address A Redis server.
一种可能的实现方式,所述处理单元402,具体用于:In a possible implementation manner, the processing unit 402 is specifically configured to:
获取所述第二Redis服务器的监控组件在故障切换时传出的参数;若确定所述参数中的源IP地址为所述第二Redis服务器的IP地址,则发起VIP地址的解绑操作;若确定所述参数中的目的IP地址为所述第一Redis服务器的IP地址,则检测所述Redis集群的VIP地址是否为连通状态;若未接收到连通返回消息,则将所述第一Redis服务器的VIP地址绑定至所述Redis集群。Obtain the parameters transmitted by the monitoring component of the second Redis server during failover; if it is determined that the source IP address in the parameters is the IP address of the second Redis server, initiate the unbinding operation of the VIP address; if It is determined that the destination IP address in the parameter is the IP address of the first Redis server, then it is detected whether the VIP address of the Redis cluster is in a connected state; if the connection return message is not received, the first Redis server The VIP address of is bound to the Redis cluster.
一种可能的实现方式,所述处理单元402,还用于:将所述第一Redis服务器的VIP地址更新至ARP缓存,以使所述Redis集群的网关设备确认所述Redis集群的VIP地址对应所述第一Redis服务器。In a possible implementation manner, the processing unit 402 is further configured to: update the VIP address of the first Redis server to the ARP cache, so that the gateway device of the Redis cluster confirms that the VIP address of the Redis cluster corresponds to The first Redis server.
一种可能的实现方式,所述监控单元401,具体用于:In a possible implementation manner, the monitoring unit 401 is specifically configured to:
向各Redis服务器发送心跳检测;若心跳检测成功,则从心跳检测成功的 Redis实例确定可用的连接链路。Send a heartbeat detection to each Redis server; if the heartbeat detection is successful, the available connection link is determined from the Redis instance with a successful heartbeat detection.
考虑到本发明实施例中的Redis集群获取应用程序发来的读写请求后,可以包括:Taking into account that the Redis cluster in the embodiment of the present invention obtains the read and write request sent by the application, it may include:
根据读写请求中的数据主键值,确定对应的Redis服务器;Determine the corresponding Redis server according to the data primary key value in the read and write request;
根据所述数据主键值进行哈希运算生成的哈希值,确定对应的所述Redis服务器的端口;根据确定的端口确定所述读写请求对应的Redis实例。Determine the corresponding port of the Redis server according to the hash value generated by the hash operation based on the data primary key value; determine the Redis instance corresponding to the read/write request according to the determined port.
例如,对于Redis集群来说,Redis集群收到应用程序发来的读写请求,首先确定本条读写请求对应的哪个VIP节点,当确定好VIP节点之后,Redis集群从对应的连接池中选择一条连接链路,将读写请求传送给VIP节点,VIP节点再根据读写请求中的数据主键值确定本条读写请求对应的哪个Redis服务器,再根据数据主键值进行哈希运算生成的哈希值,确定对应的所述Redis服务器的端口,并根据确定的端口确定所述读写请求对应的Redis实例。当确定好Redis实例之后,Redis集群从该Redis实例对应的连接池中获取一个长连接,这样就可以通过长连接发送该条读写请求。For example, for a Redis cluster, the Redis cluster receives a read and write request from an application, and first determines which VIP node the read and write request corresponds to. After the VIP node is determined, the Redis cluster selects one from the corresponding connection pool Connect the link and transmit the read and write request to the VIP node. The VIP node then determines which Redis server corresponds to the read and write request according to the data primary key value in the read and write request, and then performs a hash operation based on the data primary key value to generate the ha Hopefully, the port of the corresponding Redis server is determined, and the Redis instance corresponding to the read and write request is determined according to the determined port. After the Redis instance is determined, the Redis cluster obtains a long connection from the connection pool corresponding to the Redis instance, so that the read and write request can be sent through the long connection.
因此,本发明实施例中的Redis集群不需要跨节点的访问,避免了现有技术中,Redis3.0版本以上大集群,需要至少3个主Redis服务器,并且会将key划分为槽的形式,每个主Redis分别存不同的槽,导致在客户端访问某一个Redis服务器时,如果该key所在槽不在该访问的Redis则需要重定向到该key所在的Redis上访问,效率比单Redis服务器的访问效率低,并且不支持那些需要同时处理多个键的Redis命令,例如,mset/mget等命令不支持跨节点的访问。Therefore, the Redis cluster in the embodiment of the present invention does not require cross-node access, which avoids that in the prior art, a large cluster of Redis version 3.0 or higher requires at least 3 main Redis servers, and the key is divided into slots. Each main Redis has a different slot. When the client accesses a certain Redis server, if the slot of the key is not in the Redis that is being accessed, it needs to be redirected to the Redis where the key is located, which is more efficient than the single Redis server. Access efficiency is low, and Redis commands that need to process multiple keys at the same time are not supported. For example, commands such as mset/mget do not support cross-node access.
基于相同的发明构思,基于上述实施例,参阅图5所示,本发明实施例中,一种计算机设备的结构示意图。Based on the same inventive concept, based on the above-mentioned embodiment, referring to FIG. 5, in the embodiment of the present invention, a schematic structural diagram of a computer device is shown.
本发明实施例提供了一种计算机设备,该计算机设备可以包括:处理器1001,例如CPU,网络接口1004,用户接口1003,存储器1005,通信总线1002。其中,通信总线1002用于实现这些组件之间的连接通信。用户接口1003可以包括显示屏(Display)、输入单元比如键盘(Keyboard),可选用户接口 1003还可以包括标准的有线接口、无线接口。网络接口1004可选的可以包括标准的有线接口、无线接口(如WI-FI接口)。存储器1005可以是高速RAM存储器,也可以是稳定的存储器(non-volatile memory),例如磁盘存储器。存储器1005可选的还可以是独立于前述处理器1001的存储装置。The embodiment of the present invention provides a computer device. The computer device may include a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to implement connection and communication between these components. The user interface 1003 may include a display screen (Display) and an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory, or a non-volatile memory (non-volatile memory), such as a magnetic disk memory. Optionally, the memory 1005 may also be a storage device independent of the foregoing processor 1001.
本领域技术人员可以理解,图5中示出的结构并不构成对计算机设备的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。Those skilled in the art can understand that the structure shown in FIG. 5 does not constitute a limitation on the computer device, and may include more or less components than those shown in the figure, or a combination of certain components, or different component arrangements.
作为一种计算机存储介质的存储器1005中可以包括操作系统、网络通信模块、用户接口模块以及信息推荐模型的生成程序。其中,操作系统是管理和控制模型参数获取系统硬件和软件资源的程序,支持信息推荐模型的生成程序以及其它软件或程序的运行。As a computer storage medium, the memory 1005 may include an operating system, a network communication module, a user interface module, and an information recommendation model generation program. Among them, the operating system is a program that manages and controls model parameters to obtain system hardware and software resources, and supports the generation of information recommendation models and the operation of other software or programs.
用户接口1003主要用于连接、第二服务器和第三服务器等,与各个服务器进行数据通信;网络接口1004主要用于连接后台服务器,与后台服务器进行数据通信;而处理器1001可以用于调用存储器1005中存储的信息推荐模型的生成程序,并执行以下操作:The user interface 1003 is mainly used to connect, the second server, the third server, etc., to communicate with each server; the network interface 1004 is mainly used to connect to the background server, and to communicate with the background server; and the processor 1001 can be used to call the memory The information recommended model generation program stored in 1005, and performs the following operations:
若确定第二Redis服务器连接链路发生故障,则发起投票;所述第二Redis服务器为主Redis服务器;将投票结果大于或等于半数的从Redis服务器确定为与所述第二Redis服务器进行切换的从Redis服务器;将所述第一Redis服务器的VIP地址设置为所述Redis集群的VIP地址,以使访问所述Redis集群的客户端根据修改后的VIP地址访问所述第一Redis服务器。If it is determined that the connection link of the second Redis server is faulty, a voting is initiated; the second Redis server is the main Redis server; the Redis server whose voting result is greater than or equal to half is determined as the switch to the second Redis server From the Redis server; the VIP address of the first Redis server is set to the VIP address of the Redis cluster, so that clients accessing the Redis cluster can access the first Redis server according to the modified VIP address.
一种可能的实现方式,所述处理器1001,具体用于:In a possible implementation manner, the processor 1001 is specifically configured to:
获取所述第二Redis服务器的监控组件在故障切换时传出的参数;若确定所述参数中的源IP地址为所述第二Redis服务器的IP地址,则发起VIP地址的解绑操作;若确定所述参数中的目的IP地址为所述第一Redis服务器的IP地址,则检测所述Redis集群的VIP地址是否为连通状态;若未接收到连通返回消息,则将所述第一Redis服务器的VIP地址绑定至所述Redis集群。Obtain the parameters transmitted by the monitoring component of the second Redis server during failover; if it is determined that the source IP address in the parameters is the IP address of the second Redis server, initiate the unbinding operation of the VIP address; if It is determined that the destination IP address in the parameter is the IP address of the first Redis server, then it is detected whether the VIP address of the Redis cluster is in a connected state; if the connection return message is not received, the first Redis server The VIP address of is bound to the Redis cluster.
一种可能的实现方式,所述处理器1001,还用于:将所述第一Redis服 务器的VIP地址更新至ARP缓存,以使所述Redis集群的网关设备确认所述Redis集群的VIP地址对应所述第一Redis服务器。In a possible implementation manner, the processor 1001 is further configured to: update the VIP address of the first Redis server to the ARP cache, so that the gateway device of the Redis cluster confirms that the VIP address of the Redis cluster corresponds to The first Redis server.
一种可能的实现方式,所述处理器1001,具体用于:In a possible implementation manner, the processor 1001 is specifically configured to:
向各Redis服务器发送心跳检测;若心跳检测成功,则从心跳检测成功的Redis实例确定可用的连接链路。Send a heartbeat detection to each Redis server; if the heartbeat detection is successful, the available connection link is determined from the Redis instance with a successful heartbeat detection.
本发明是参照根据本发明实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。The present invention is described with reference to flowcharts and/or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and/or block in the flowchart and/or block diagram, and the combination of processes and/or blocks in the flowchart and/or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing equipment to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing equipment are generated It is a device that realizes the functions specified in one process or multiple processes in the flowchart and/or one block or multiple blocks in the block diagram.
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing equipment to work in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including the instruction device. The device implements the functions specified in one process or multiple processes in the flowchart and/or one block or multiple blocks in the block diagram.
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions can also be loaded on a computer or other programmable data processing equipment, so that a series of operation steps are executed on the computer or other programmable equipment to produce computer-implemented processing, so as to execute on the computer or other programmable equipment. The instructions provide steps for implementing functions specified in a flow or multiple flows in the flowchart and/or a block or multiple blocks in the block diagram.
显然,本领域的技术人员可以对本发明进行各种改动和变型而不脱离本发明的精神和范围。这样,倘若本发明的这些修改和变型属于本发明权利要求及其等同技术的范围之内,则本发明也意图包含这些改动和变型在内。Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. In this way, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalent technologies, the present invention is also intended to include these modifications and variations.

Claims (10)

  1. 一种Redis集群的高可用方法,其特征在于,所述集群包括至少两个Redis服务器,及与所述Redis服务器对应配置的监控组件;该方法包括:A high-availability method for a Redis cluster, characterized in that the cluster includes at least two Redis servers and monitoring components configured corresponding to the Redis servers; the method includes:
    第一Redis服务器的监控组件通过发起侦测线程侦测各Redis服务器的连接链路;The monitoring component of the first Redis server detects the connection link of each Redis server by initiating a detection thread;
    所述第一Redis服务器的监控组件若确定第二Redis服务器连接链路发生故障,则发起投票;所述第二Redis服务器为主Redis服务器;If the monitoring component of the first Redis server determines that the connection link of the second Redis server is faulty, it initiates a vote; the second Redis server is the master Redis server;
    所述第一Redis服务器的监控组件若确定投票结果大于或等于半数的从Redis服务器为所述第一Redis服务器,则将所述第一Redis服务器确定为与所述第二Redis服务器进行切换的从Redis服务器;If the monitoring component of the first Redis server determines that the slave Redis server whose voting result is greater than or equal to half is the first Redis server, the first Redis server is determined to be the slave that switches with the second Redis server Redis server;
    所述第一Redis服务器的监控组件将所述第一Redis服务器的VIP地址设置为所述Redis集群的VIP地址,以使访问所述Redis集群的客户端根据修改后的VIP地址访问所述第一Redis服务器。The monitoring component of the first Redis server sets the VIP address of the first Redis server to the VIP address of the Redis cluster, so that clients that access the Redis cluster can access the first Redis cluster according to the modified VIP address. Redis server.
  2. 如权利要求1所述的方法,其特征在于,所述第一Redis服务器的监控组件将所述第一Redis服务器的VIP地址设置为所述Redis集群的VIP地址,包括:The method according to claim 1, wherein the monitoring component of the first Redis server setting the VIP address of the first Redis server to the VIP address of the Redis cluster comprises:
    所述第一Redis服务器的监控组件获取所述第二Redis服务器的监控组件在故障切换时传出的参数;Acquiring, by the monitoring component of the first Redis server, the parameters transmitted by the monitoring component of the second Redis server during failover;
    所述第一Redis服务器的监控组件若确定所述参数中的源IP地址为所述第二Redis服务器的IP地址,则发起VIP地址的解绑操作;If the monitoring component of the first Redis server determines that the source IP address in the parameter is the IP address of the second Redis server, it initiates an unbinding operation of the VIP address;
    所述第一Redis服务器的监控组件若确定所述参数中的目的IP地址为所述第一Redis服务器的IP地址,则检测所述Redis集群的VIP地址是否为连通状态;If the monitoring component of the first Redis server determines that the destination IP address in the parameter is the IP address of the first Redis server, it detects whether the VIP address of the Redis cluster is in a connected state;
    所述第一Redis服务器的监控组件若未接收到连通返回消息,则将所述第一Redis服务器的VIP地址绑定至所述Redis集群。If the monitoring component of the first Redis server does not receive the connection return message, it binds the VIP address of the first Redis server to the Redis cluster.
  3. 如权利要求2所述的方法,其特征在于,所述第一Redis服务器的监 控组件若未接收到连通返回消息,还包括:The method according to claim 2, wherein if the monitoring component of the first Redis server does not receive the connection return message, the method further comprises:
    将所述第一Redis服务器的VIP地址更新至ARP缓存,以使所述Redis集群的网关设备确认所述Redis集群的VIP地址对应所述第一Redis服务器。The VIP address of the first Redis server is updated to the ARP cache, so that the gateway device of the Redis cluster confirms that the VIP address of the Redis cluster corresponds to the first Redis server.
  4. 如权利要求1-3任一项所述的方法,其特征在于,所述第一Redis服务器的监控组件通过发起侦测线程侦测各Redis服务器的连接链路,包括:The method according to any one of claims 1 to 3, wherein the monitoring component of the first Redis server detects the connection link of each Redis server by initiating a detection thread, comprising:
    所述第一Redis服务器的监控组件向各Redis服务器发送心跳检测;The monitoring component of the first Redis server sends a heartbeat detection to each Redis server;
    若心跳检测成功,则从心跳检测成功的Redis实例确定可用的连接链路。If the heartbeat detection is successful, the available connection link is determined from the Redis instance that succeeded in the heartbeat detection.
  5. 一种Redis集群的高可用装置,其特征在于,所述集群包括至少两个Redis服务器,及与所述Redis服务器对应配置的监控组件;该装置包括:A high-availability device for a Redis cluster, characterized in that the cluster includes at least two Redis servers and monitoring components configured corresponding to the Redis servers; the device includes:
    监控单元,用于通过发起侦测线程侦测各Redis服务器的连接链路;The monitoring unit is used to detect the connection link of each Redis server by initiating a detection thread;
    处理单元,用于若确定第二Redis服务器连接链路发生故障,则发起投票;所述第二Redis服务器为主Redis服务器;若确定投票结果大于或等于半数的从Redis服务器为所述第一Redis服务器,则将所述第一Redis服务器确定为与所述第二Redis服务器进行切换的从Redis服务器;将所述第一Redis服务器的VIP地址设置为所述Redis集群的VIP地址,以使访问所述Redis集群的客户端根据修改后的VIP地址访问所述第一Redis服务器。The processing unit is configured to initiate a voting if it is determined that the connection link of the second Redis server is faulty; the second Redis server is the primary Redis server; if it is determined that the secondary Redis server whose voting result is greater than or equal to half is the first Redis Server, the first Redis server is determined to be the slave Redis server that switches with the second Redis server; the VIP address of the first Redis server is set to the VIP address of the Redis cluster, so that the The client of the Redis cluster accesses the first Redis server according to the modified VIP address.
  6. 如权利要求5所述的装置,其特征在于,所述处理单元,具体用于:The device according to claim 5, wherein the processing unit is specifically configured to:
    获取所述第二Redis服务器的监控组件在故障切换时传出的参数;若确定所述参数中的源IP地址为所述第二Redis服务器的IP地址,则发起VIP地址的解绑操作;若确定所述参数中的目的IP地址为所述第一Redis服务器的IP地址,则检测所述Redis集群的VIP地址是否为连通状态;若未接收到连通返回消息,则将所述第一Redis服务器的VIP地址绑定至所述Redis集群。Obtain the parameters transmitted by the monitoring component of the second Redis server during failover; if it is determined that the source IP address in the parameters is the IP address of the second Redis server, initiate the unbinding operation of the VIP address; if It is determined that the destination IP address in the parameter is the IP address of the first Redis server, then it is detected whether the VIP address of the Redis cluster is in a connected state; if the connection return message is not received, the first Redis server The VIP address of is bound to the Redis cluster.
  7. 如权利要求6所述的装置,其特征在于,所述处理单元,还用于:将所述第一Redis服务器的VIP地址更新至ARP缓存,以使所述Redis集群的网关设备确认所述Redis集群的VIP地址对应所述第一Redis服务器。7. The device according to claim 6, wherein the processing unit is further configured to: update the VIP address of the first Redis server to the ARP cache, so that the gateway device of the Redis cluster confirms the Redis The VIP address of the cluster corresponds to the first Redis server.
  8. 如权利要求5-7任一项所述的装置,其特征在于,所述监控单元,具体用于:The device according to any one of claims 5-7, wherein the monitoring unit is specifically configured to:
    向各Redis服务器发送心跳检测;若心跳检测成功,则从心跳检测成功的Redis实例确定可用的连接链路。Send a heartbeat detection to each Redis server; if the heartbeat detection is successful, the available connection link is determined from the Redis instance with a successful heartbeat detection.
  9. 一种计算机设备,其特征在于,包括:A computer device, characterized in that it comprises:
    至少一个处理器;以及,At least one processor; and,
    与所述至少一个处理器通信连接的存储器;其中,A memory communicatively connected with the at least one processor; wherein,
    所述存储器存储有可被所述至少一个处理器执行的指令,所述指令被所述至少一个处理器执行,以使所述至少一个处理器能够执行权利要求1-4任一所述的方法。The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor, so that the at least one processor can execute the method according to any one of claims 1 to 4 .
  10. 一种非暂态计算机可读存储介质,其特征在于,所述非暂态计算机可读存储介质存储计算机指令,所述计算机指令用于使所述计算机执行权利要求1~4任一所述方法。A non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to make the computer execute the method described in any one of claims 1 to 4 .
PCT/CN2020/095421 2019-06-21 2020-06-10 High availability method and apparatus for redis cluster WO2020253596A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910540450.2A CN110224871B (en) 2019-06-21 2019-06-21 High-availability method and device for Redis cluster
CN201910540450.2 2019-06-21

Publications (1)

Publication Number Publication Date
WO2020253596A1 true WO2020253596A1 (en) 2020-12-24

Family

ID=67814194

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/095421 WO2020253596A1 (en) 2019-06-21 2020-06-10 High availability method and apparatus for redis cluster

Country Status (2)

Country Link
CN (1) CN110224871B (en)
WO (1) WO2020253596A1 (en)

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112860485A (en) * 2021-02-03 2021-05-28 北京北信源信息安全技术有限公司 Control method of dual-computer hot standby system based on keepalived
US20210243250A1 (en) * 2020-02-04 2021-08-05 Nutanix, Inc. Efficient virtual ip address management for service clusters
CN113806181A (en) * 2021-09-24 2021-12-17 重庆富民银行股份有限公司 Redis multi-cluster automatic monitoring method and system
CN114598711A (en) * 2022-03-29 2022-06-07 百果园技术(新加坡)有限公司 Data migration method, device, equipment and medium
CN114785713A (en) * 2022-03-31 2022-07-22 度小满科技(北京)有限公司 Method and proxy middleware for realizing high availability of Redis cluster
CN115037785A (en) * 2022-08-12 2022-09-09 深圳市星卡软件技术开发有限公司 Instant communication system and method
CN115484267A (en) * 2022-09-15 2022-12-16 中国联合网络通信集团有限公司 Multi-cluster deployment processing method and device, electronic equipment and storage medium
CN116546092A (en) * 2023-07-04 2023-08-04 深圳市亲邻科技有限公司 Redis-based object model storage system

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110674192A (en) * 2019-10-09 2020-01-10 浪潮云信息技术有限公司 Redis high-availability VIP (very important person) drifting method, terminal and storage medium
CN111444062B (en) * 2020-04-01 2023-09-19 山东汇贸电子口岸有限公司 Method and device for managing master node and slave node of cloud database
CN113535126A (en) * 2020-04-14 2021-10-22 天津科技大学 House renting platform based on SSM
CN112306720B (en) * 2020-11-23 2022-06-21 迈普通信技术股份有限公司 Service system cluster management method
CN113079192B (en) * 2021-02-08 2021-12-31 马上消费金融股份有限公司 Information processing method, device, equipment and readable storage medium
CN114363156A (en) * 2022-01-25 2022-04-15 南瑞集团有限公司 Hydropower station computer monitoring system deployment method based on cluster technology

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105933407A (en) * 2016-04-20 2016-09-07 中国银联股份有限公司 Method and system for achieving high availability of Redis cluster
CN106534328A (en) * 2016-11-28 2017-03-22 网宿科技股份有限公司 Node connection method and distributed computing system
US20180121304A1 (en) * 2016-10-27 2018-05-03 Machine Zone, Inc. System and method for managing a cluster of cache servers (trask)
CN108206843A (en) * 2016-12-16 2018-06-26 北京金山云网络技术有限公司 A kind of cluster access method and device

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106210151A (en) * 2016-09-27 2016-12-07 深圳市彬讯科技有限公司 A kind of zedis distributed caching and server cluster monitoring method

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105933407A (en) * 2016-04-20 2016-09-07 中国银联股份有限公司 Method and system for achieving high availability of Redis cluster
US20180121304A1 (en) * 2016-10-27 2018-05-03 Machine Zone, Inc. System and method for managing a cluster of cache servers (trask)
CN106534328A (en) * 2016-11-28 2017-03-22 网宿科技股份有限公司 Node connection method and distributed computing system
CN108206843A (en) * 2016-12-16 2018-06-26 北京金山云网络技术有限公司 A kind of cluster access method and device

Cited By (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20210243250A1 (en) * 2020-02-04 2021-08-05 Nutanix, Inc. Efficient virtual ip address management for service clusters
US11917001B2 (en) * 2020-02-04 2024-02-27 Nutanix, Inc. Efficient virtual IP address management for service clusters
CN112860485A (en) * 2021-02-03 2021-05-28 北京北信源信息安全技术有限公司 Control method of dual-computer hot standby system based on keepalived
CN113806181A (en) * 2021-09-24 2021-12-17 重庆富民银行股份有限公司 Redis multi-cluster automatic monitoring method and system
CN114598711A (en) * 2022-03-29 2022-06-07 百果园技术(新加坡)有限公司 Data migration method, device, equipment and medium
CN114598711B (en) * 2022-03-29 2024-04-16 百果园技术(新加坡)有限公司 Data migration method, device, equipment and medium
CN114785713A (en) * 2022-03-31 2022-07-22 度小满科技(北京)有限公司 Method and proxy middleware for realizing high availability of Redis cluster
CN114785713B (en) * 2022-03-31 2024-02-23 度小满科技(北京)有限公司 Method and proxy middleware for realizing high availability of Redis cluster
CN115037785A (en) * 2022-08-12 2022-09-09 深圳市星卡软件技术开发有限公司 Instant communication system and method
CN115484267A (en) * 2022-09-15 2022-12-16 中国联合网络通信集团有限公司 Multi-cluster deployment processing method and device, electronic equipment and storage medium
CN116546092A (en) * 2023-07-04 2023-08-04 深圳市亲邻科技有限公司 Redis-based object model storage system
CN116546092B (en) * 2023-07-04 2023-10-13 深圳市亲邻科技有限公司 Redis-based object model storage system

Also Published As

Publication number Publication date
CN110224871B (en) 2022-11-08
CN110224871A (en) 2019-09-10

Similar Documents

Publication Publication Date Title
WO2020253596A1 (en) High availability method and apparatus for redis cluster
US20200358848A1 (en) Methods, systems, and media for providing distributed database access during a network split
WO2021120970A1 (en) Distributed local dns system and domain name inquiry method
US10983880B2 (en) Role designation in a high availability node
US8676760B2 (en) Maintaining data integrity in data servers across data centers
US7340637B2 (en) Server duplexing method and duplexed server system
KR101099822B1 (en) Redundant routing capabilities for a network node cluster
CN108075971B (en) Main/standby switching method and device
JP2019219954A (en) Cluster storage system, data management control method, and data management control program
WO2016058307A1 (en) Fault handling method and apparatus for resource
US10771318B1 (en) High availability on a distributed networking platform
US9992058B2 (en) Redundant storage solution
US8082344B2 (en) Transaction manager virtualization
US20150113313A1 (en) Method of operating a server system with high availability
US20080307254A1 (en) Information-processing equipment and system therefor
US11403319B2 (en) High-availability network device database synchronization
US11153269B2 (en) On-node DHCP implementation for virtual machines
US20200112499A1 (en) Multiple quorum witness
WO2020024615A1 (en) Consensus process recovery method and related nodes
CN104158707A (en) Method and device of detecting and processing brain split in cluster
CN113849136B (en) Automatic FC block storage processing method and system based on domestic platform
CN112540827A (en) Load balancing system based on k8s platform and implementation method
JP2012014674A (en) Failure recovery method, server, and program in virtual environment
US11418382B2 (en) Method of cooperative active-standby failover between logical routers based on health of attached services
US20230254270A1 (en) Computer-readable recording medium storing program, information processing method, and information processing system

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: 20826467

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20826467

Country of ref document: EP

Kind code of ref document: A1

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 290322)

122 Ep: pct application non-entry in european phase

Ref document number: 20826467

Country of ref document: EP

Kind code of ref document: A1