WO2020238057A1 - 基于Redis的mqtt集群的监控方法、装置及存储介质 - Google Patents

基于Redis的mqtt集群的监控方法、装置及存储介质 Download PDF

Info

Publication number
WO2020238057A1
WO2020238057A1 PCT/CN2019/118006 CN2019118006W WO2020238057A1 WO 2020238057 A1 WO2020238057 A1 WO 2020238057A1 CN 2019118006 W CN2019118006 W CN 2019118006W WO 2020238057 A1 WO2020238057 A1 WO 2020238057A1
Authority
WO
WIPO (PCT)
Prior art keywords
server
control system
cache control
client
master
Prior art date
Application number
PCT/CN2019/118006
Other languages
English (en)
French (fr)
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 WO2020238057A1 publication Critical patent/WO2020238057A1/zh

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
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network

Definitions

  • This application relates to the field of mqtt clusters, and in particular to a monitoring method, device and computer-readable storage medium for mqtt clusters based on Redis.
  • the mqtt protocol is currently the standard transmission protocol for Internet of Things messages.
  • mqtt products on the market which are basically clusters.
  • the cluster implementation is either very poor or not implemented.
  • the monitoring module needs to collect the data of each node.
  • the monitoring module needs to send a notification message to each business network element, and to each The IP address of Redis stored by the service network element is modified, resulting in low efficiency of switching between master and slave servers.
  • This application provides a Redis-based mqtt cluster monitoring method, device, and computer-readable storage medium, the main purpose of which is to improve the efficiency of switching between master and slave servers.
  • this application provides a Redis-based mqtt cluster monitoring method, which is applied to an electronic device.
  • the method includes: loading master-slave server configuration information stored in the Redis cache control system into the memory; The cache control system monitors the master server; when it is determined that one of the master servers is down, the configuration information of the master-slave server stored in the memory is changed through the Redis cache control system; the master-slave switching instruction is sent to the Redis cache control system
  • One of the slave servers replaces the master server as the new master server, and changes the master server address reserved by other slave servers to the address of the new master server.
  • the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a monitoring program of the Redis-based mqtt cluster that can run on the processor, and the Redis-based mqtt cluster
  • the monitoring program is executed by the processor, the following steps are implemented: load the master-slave server configuration information stored in the Redis cache control system into the memory; monitor the master server through the Redis cache control system; when judging one of the master servers When it is down, change the configuration information of the master-slave server stored in the memory through the Redis cache control system; send a master-slave switching instruction to one of the slave servers to replace the master server as the new master server through the Redis cache control system, And change the address of the master server reserved by other slave servers to the address of the new master server.
  • this application also provides a computer-readable storage medium on which is stored a monitoring program of the mqtt cluster based on Redis, and the monitoring program of the mqtt cluster based on Redis can be One or more processors are executed to realize the steps of the above-mentioned Redis-based mqtt cluster monitoring method.
  • the Redis-based mqtt cluster monitoring method, device, and computer-readable storage medium provided in this application monitor the master-slave server through the Redis cache control system, and when it is determined that one of the master servers is down, the Redis cache control system Change the master-slave server configuration information stored in the memory to further switch the master-slave server, which can ensure timely and effective master-slave server switching, thereby improving the efficiency of master-slave server switching.
  • FIG. 1 is a schematic flow diagram of a monitoring method for a Redis-based mqtt cluster provided by an embodiment of the application;
  • FIG. 2 is a schematic diagram of the internal structure of an electronic device provided by an embodiment of the application.
  • FIG. 3 is a schematic diagram of modules of a monitoring program of an mqtt cluster based on Redis in an electronic device provided by an embodiment of the application.
  • This application provides a monitoring method of mqtt cluster based on Redis.
  • FIG. 1 it is a schematic flowchart of a method for monitoring a Redis-based mqtt cluster provided by an embodiment of this application.
  • the method may be executed by a device, and the device may be implemented by software and/or hardware.
  • the device is a server.
  • the monitoring method of the mqtt cluster based on Redis includes:
  • S107 Send a master-slave switching instruction to one of the slave servers to replace the master server as the new master server through the Redis cache control system, and change the master server addresses reserved by other slave servers to the new master server the address of.
  • each master server corresponds to multiple slave servers.
  • the master server connects to the client, and the slave server is used to back up the data of the master server.
  • the master server is down ,
  • One of the slave servers corresponding to the down master server is switched to the master server by the Redis cache control system, and the master server address reserved by the other corresponding servers is changed to the address of the new master server.
  • the method further includes:
  • the Redis cache control system determines that the current client identifier of the currently accessed client is consistent with the stored client identifier, the currently accessed client is disconnected.
  • the main server will store the client identifier of all connected clients.
  • the Redis cache control system will look for the previous client The identifier is compared with the current client identifier, and if they are the same, the currently connected client is disconnected.
  • the method further includes:
  • the step of monitoring the main server through the Redis cache control system includes: sending a Ping command to the main server through the Redis cache control system within a preset time to monitor whether the main server is down. For example, send a Ping command to the main server every 5 seconds, 10 seconds, or 15 seconds.
  • the step of loading the master-slave server configuration information stored in the Redis cache control system into the memory includes:
  • the configuration information table includes the configuration information of the master server and the configuration information of the slave server;
  • the configuration information of the master server includes the IP and port information of the master server, and the slave server
  • the configuration information includes the IP and port information of the slave server;
  • the configuration information table is sent and loaded into the memory.
  • the Redis cache control system can judge the operation of the slave server, and change the master-slave configuration information stored in the memory when the slave server is judged to be normal, otherwise it will issue an alarm command to the alarm device.
  • the monitoring method of the mqtt cluster based on Redis proposed in this embodiment monitors the master-slave server through the Redis cache control system.
  • the Redis cache control system changes the master-slave stored in the memory Server configuration information to further switch between the master and slave servers, which can ensure timely and effective master-slave server switching, thereby improving the efficiency of master-slave server switching.
  • it in addition to effectively monitoring the operation of the master server and the slave server, it can also monitor whether the client is reconnected, so that the monitoring effect is more comprehensive and effective.
  • This application also provides an electronic device 1.
  • FIG. 2 it is a schematic diagram of the internal structure of an electronic device provided by an embodiment of this application.
  • the electronic device 1 may be a computer or a server.
  • the electronic device 1 at least includes a memory 11, a processor 13, a communication bus 15, and a network interface 17.
  • the electronic device 1 is a server.
  • the memory 11 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), magnetic memory, magnetic disk, optical disk, etc.
  • the memory 11 may be an internal storage unit of the electronic device, such as a hard disk of the electronic device.
  • the memory 11 may also be an external storage device of the electronic device, for example, a plug-in hard disk, a smart media card (SMC), and a secure digital (SD) card equipped on the electronic device. Flash Card, etc.
  • the memory 11 may also include both an internal storage unit of an electronic device and an external storage device.
  • the memory 11 can be used not only to store application software and various data installed in the electronic device 1, such as the code of the monitoring program 111 of the mqtt cluster based on Redis, etc., but also to temporarily store data that has been output or will be output.
  • the processor 13 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other data processing chip in some embodiments, and is used to run the program code or processing stored in the memory 11 data.
  • CPU central processing unit
  • controller microcontroller
  • microprocessor or other data processing chip in some embodiments, and is used to run the program code or processing stored in the memory 11 data.
  • the communication bus 15 is used to realize the connection and communication between these components.
  • the network interface 17 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface), and is generally used to establish a communication connection between the electronic device 1 and other electronic devices.
  • a standard wired interface and a wireless interface such as a WI-FI interface
  • the electronic device 1 may further include a user interface.
  • the user interface may include a display (Display) and an input unit such as a keyboard (Keyboard).
  • the optional user interface may also include a standard wired interface and a wireless interface.
  • the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode, organic light emitting diode) touch device, etc.
  • the display can also be appropriately called a display screen or a display unit, which is used to display information processed in the electronic device and to display a visualized user interface.
  • FIG. 2 only shows the electronic device 1 with components 11-17. Those skilled in the art can understand that the structure shown in FIG. 2 does not constitute a limitation on the electronic device, and may include fewer or more components than shown. Component, or combination of some components, or different component arrangements.
  • the memory 11 stores a monitoring program 111 based on the Redis mqtt cluster; when the processor 13 executes the monitoring program 111 based on the Redis mqtt cluster stored in the memory 11, the implementation is as follows step:
  • the configuration information of the primary and secondary servers stored in the memory is changed through the Redis cache control system
  • each master server corresponds to multiple slave servers.
  • the master server connects to the client, and the slave server is used to back up the data of the master server.
  • the master server is down ,
  • One of the slave servers corresponding to the down master server is switched to the master server by the Redis cache control system, and the master server address reserved by the other corresponding servers is changed to the address of the new master server.
  • the following steps are implemented when the monitoring program of the mqtt cluster based on Redis is executed by the processor:
  • the Redis cache control system determines that the current client identifier of the currently accessed client is consistent with the stored client identifier, the currently accessed client is disconnected.
  • the main server will store the client identifier of all connected clients.
  • the Redis cache control system will look up the previous client identifier Compare with the current client identifier, if the same, disconnect the currently connected client.
  • the following steps are implemented when the monitoring program of the mqtt cluster based on Redis is executed by the processor before determining whether the current client identifier of the previously accessed client is consistent with the stored client identifier:
  • the step of monitoring the main server through the Redis cache control system includes: sending a Ping command to the main server through the Redis cache control system within a preset time to monitor whether the main server is down. For example, send a Ping command to the main server every 5 seconds, 10 seconds, or 15 seconds.
  • the step of loading the master-slave server configuration information stored in the Redis cache control system into the memory includes:
  • the configuration information table includes the configuration information of the master server and the configuration information of the slave server;
  • the configuration information of the master server includes the IP and port information of the master server, and the slave server
  • the configuration information includes the IP and port information of the slave server;
  • the configuration information table is sent and loaded into the memory.
  • the Redis cache control system can judge the operation of the slave server, and change the master-slave configuration information stored in the memory when the slave server is judged to be normal, otherwise it will issue an alarm command to the alarm device.
  • the electronic device proposed in this embodiment monitors the master-slave server through the Redis cache control system.
  • the Redis cache control system changes the master-slave server configuration information stored in the memory, thereby further Switching the master-slave server can ensure timely and effective switching of the master-slave server, thereby improving the efficiency of the master-slave server switching.
  • the client in addition to effectively monitoring the operation of the master server and the slave server, it can also monitor whether the client is reconnected, so that the monitoring effect is more comprehensive and effective.
  • an embodiment of the present application also proposes a computer-readable storage medium that stores a monitoring program 111 based on the Redis mqtt cluster on the computer-readable storage medium, and the monitoring program 111 based on the Redis mqtt cluster can be One or more processors execute to implement the following operations: load the master-slave server configuration information stored in the Redis cache control system into the memory;
  • the configuration information of the primary and secondary servers stored in the memory is changed through the Redis cache control system
  • each master server corresponds to multiple slave servers.
  • the master server connects to the client, and the slave server is used to back up the data of the master server.
  • the master server is down ,
  • One of the slave servers corresponding to the down master server is switched to the master server by the Redis cache control system, and the master server address reserved by the other corresponding servers is changed to the address of the new master server.
  • the monitoring program 111 of the Redis-based mqtt cluster may also be divided into one or more modules, one or more modules are stored in the memory 11, and composed of one or more modules.
  • the processor (the processor 13 in this embodiment) is executed to complete this application.
  • the module referred to in this application refers to a series of computer program instruction segments that can complete specific functions, and is used to describe the monitoring program 111 of the mqtt cluster based on Redis. The execution process in the electronic device.
  • FIG. 3 a schematic diagram of the program modules of the monitoring program 111 of the mqtt cluster based on Redis in an embodiment of the electronic device of this application.
  • the monitoring program 111 of the mqtt cluster based on Redis can be divided into The loading module 10, the monitoring module 20, the changing module 30, and the switching module 40 are illustratively:
  • the loading module 10 is used to load the master-slave server configuration information stored in the Redis cache control system into the memory;
  • the monitoring module 20 is used to monitor the main server through the Redis cache control system
  • the change module 30 is used to change the configuration information of the master and slave servers stored in the memory through the Redis cache control system when it is determined that one of the master servers is down.
  • the switching module 40 is configured to send a master-slave switching instruction to one of the slave servers through the Redis cache control system to replace the master server as the new master server, and change the master server addresses reserved by other slave servers Is the address of the new main server.
  • each master server corresponds to multiple slave servers.
  • the master server connects to the client, and the slave server is used to back up the data of the master server.
  • the master server is down ,
  • One of the slave servers corresponding to the down master server is switched to the master server by the Redis cache control system, and the master server address reserved by the other corresponding servers is changed to the address of the new master server.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)

Abstract

本申请涉及一种云监控技术,揭露了一种基于Redis的mqtt集群的监控方法、装置及计算机可读存储介质,该方法包括:将存储在Redis缓存控制系统中的主从服务器配置信息加载到内存中;通过Redis缓存控制系统对主服务器进行监控;当判断其中一主服务器宕机时,通过所述Redis缓存控制系统变更内存中保存的主从服务器配置信息;通过所述Redis缓存控制系统发送主从切换指令给其中一从服务器一替代所述主服务器作为新的主服务器,并将其它从服务器保留的所述主服务器地址改为所述新的主服务器的地址。

Description

基于Redis的mqtt集群的监控方法、装置及存储介质
本申请要求于2019年5月29日提交中国专利局,申请号为201910460725.1、发明名称为“基于Redis的mqtt集群的监控方法、装置及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及mqtt集群领域,尤其涉及一种基于Redis的mqtt集群的监控方法、装置及计算机可读存储介质。
背景技术
mqtt协议目前已是物联网消息标准传输协议,在目前的市场上已经有许多mqtt产品,基本都是集群,对于开源的mqtt服务端,其集群实现要么是很差,要么就是没有实现。
在现有的集群服务中,一般包含的节点多,监控模块需要采集每个节点的数据,当监控到出现宕机情况时,监控模块需要向每个业务网元发送通知消息,并对每个业务网元存储的Redis的IP地址进行修改,导致主从服务器切换效率低下。
发明内容
本申请提供一种基于Redis的mqtt集群的监控方法、装置及计算机可读存储介质,其主要目的在于提升主从服务器切换的效率。
为实现上述目的,本申请提供一种基于Redis的mqtt集群的监控方法,应用于电子装置,所述方法包括:将存储在Redis缓存控制系统中的主从服务器配置信息加载到内存中;通过Redis缓存控制系统对主服务器进行监控;当 判断其中一主服务器宕机时,通过所述Redis缓存控制系统变更内存中保存的主从服务器配置信息;通过所述Redis缓存控制系统发送主从切换指令给其中一从服务器替代所述主服务器作为新的主服务器,并将其它从服务器保留的所述主服务器地址改为所述新的主服务器的地址。
本申请还提供一种电子装置,所述电子装置包括存储器和处理器,所述存储器上存储有可在所述处理器上运行的基于Redis的mqtt集群的监控程序,所述基于Redis的mqtt集群的监控程序被所述处理器执行时实现如下步骤:将存储在Redis缓存控制系统中的主从服务器配置信息加载到内存中;通过Redis缓存控制系统对主服务器进行监控;当判断其中一主服务器宕机时,通过所述Redis缓存控制系统变更内存中保存的主从服务器配置信息;通过所述Redis缓存控制系统发送主从切换指令给其中一从服务器替代所述主服务器作为新的主服务器,并将其它从服务器保留的所述主服务器地址改为所述新的主服务器的地址。
此外,为实现上述目的,本申请还提供一种计算机可读存储介质,所述计算机可读存储介质上存储有基于Redis的mqtt集群的监控程序,所述基于Redis的mqtt集群的监控程序可被一个或者多个处理器执行,以实现上述的基于Redis的mqtt集群的监控方法的步骤。
本申请提供的基于Redis的mqtt集群的监控方法、装置及计算机可读存储介质通过Redis缓存控制系统对所述主从服务器进行监控,当判断其中一主服务器宕机时,所述Redis缓存控制系统变更内存中保存的主从服务器配置信息,从而进一步对主从服务器进行切换,这样可以确保及时有效地进行主从服务器切换,从而提升了主从服务器切换的效率。
附图说明
图1为本申请一实施例提供的基于Redis的mqtt集群的监控方法的流程示意图;
图2为本申请一实施例提供的电子装置的内部结构示意图;
图3为本申请一实施例提供的电子装置中基于Redis的mqtt集群的监控程序的模块示意图。
本申请目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。
具体实施方式
应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。
本申请提供一种基于Redis的mqtt集群的监控方法。参照图1所示,为本申请一实施例提供的基于Redis的mqtt集群的监控方法的流程示意图。该方法可以由一个装置执行,该装置可以由软件和/或硬件实现,本实施例中,所述装置为服务端。
在本实施例中,基于Redis的mqtt集群的监控方法包括:
S101,将存储在Redis缓存控制系统中的主从服务器配置信息加载到内存中;
S103,通过Redis缓存控制系统对主服务器进行监控;
S105,当判断其中一主服务器宕机时,通过所述Redis缓存控制系统变更内存中保存的主从服务器配置信息;
S107,通过所述Redis缓存控制系统发送主从切换指令给其中一从服务器替代所述主服务器作为新的主服务器,并将其它从服务器保留的所述主服务器地址改为所述新的主服务器的地址。
例如,在mqtt集群服务器中,有多个主服务器,每个主服务器对应多个从服务器,在正常运行中,主服务器连接客户端,从服务器用于备份主服务器的数据,当主服务器宕机时,与宕机的主服务器对应的其中一从服务器被所述Redis缓存控制系统切换为主服务器,而其他对应的服务器保留的主服务 器地址改为所述新的主服务器的地址。
优选地,所述方法还包括:
存储已接入的客户端的客户端标识符;
通过所述Redis缓存控制系统判断当前接入的客户端的当前客户端标识符与存储的客户端标识符一致时,断开当前接入的客户端。
例如,在正常情况下,所有接入的客户端,主服务器都会将接入的客户端的客服端标识符存储,当新接入的客户端接入时,Redis缓存控制系统会查找之前的客户端标识符与当前的客户端标识符进行比较,如果相同,则断开当前接入的客户端。
优选地,在判断前接入的客户端的当前客户端标识符与存储的客户端标识符是否一致之前所述方法还包括:
先判断存储的客户端标识符对应的客户端是否都正常连接;
如果是,则判断当前接入的客户端的当前客户端标识符与存储的客户端标识符一致时,断开当前接入的客户端;
如果不是,找出不是正常连接的客户端对应的客户端标识符,并与当前的客户端标识符进行对比判断是否相同,如果相同,则判断所述当前接入的客户端为断开重连,并连接所述当前客户端。
通过以上判断方法,可以有效地判断客户端是断开重连还是恶意连接,从而可以精确地判断客户端是否重连。
优选地,所述通过Redis缓存控制系统对主服务器进行监控的步骤包括:在预设时间内通过所述Redis缓存控制系统对所述主服务器发送Ping命令来监控主服务器是否宕机。例如,每隔为5秒、10秒或15秒等向主服务器发送Ping命令。
优选地,所述将存储在Redis缓存控制系统中的主从服务器配置信息加载到内存中的步骤包括:
在Redis缓存控制系统中创建配置信息表,所述配置信息表包含了主服务 器的配置信息及从服务器的配置信息;所述主服务器的配置信息包含主服务器的IP和端口信息,所述从服务器的配置信息包含从服务器的IP和端口信息;
将所述配置信息表发送加载至内存中。
此外,当判断出主服务器宕机时,Redis缓存控制系统可以判断从服务器的运行情况,并且在判断从服务器正常的情况下变更内存中保存的主从配置信息,否则发出报警指令给报警装置。
本实施例提出的基于Redis的mqtt集群的监控方法通过Redis缓存控制系统对所述主从服务器进行监控,当判断其中一主服务器宕机时,所述Redis缓存控制系统变更内存中保存的主从服务器配置信息,从而进一步对主从服务器进行切换,这样可以确保及时有效地进行主从服务器切换,从而提升了主从服务器切换的效率。另外,在本方案中,除了有效地监控主服务器及从服务器的运行情况,同时也能监控客户端是否有重连的情况,从而使监控效果更加全面而有效。
本申请还提供一种电子装置1。参照图2所示,为本申请一实施例提供的电子装置的内部结构示意图。
在本实施例中,电子装置1可以是电脑或服务器。所述电子装置1至少包括存储器11、处理器13,通信总线15,以及网络接口17。在本实施例中,所述电子装置1为服务端。
其中,存储器11至少包括一种类型的可读存储介质,所述可读存储介质包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、磁性存储器、磁盘、光盘等。存储器11在一些实施例中可以是电子装置的内部存储单元,例如所述电子装置的硬盘。存储器11在另一些实施例中也可以是电子装置的外部存储设备,例如电子装置上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。进一步地,存储器11还可以既包括电子装置的内部存储单元也包括外部存储设备。存储器11不仅可以用于存储安装于电子装置1的应用软件 及各类数据,例如基于Redis的mqtt集群的监控程序111的代码等,还可以用于暂时地存储已经输出或者将要输出的数据。
处理器13在一些实施例中可以是一中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器或其他数据处理芯片,用于运行存储器11中存储的程序代码或处理数据。
通信总线15用于实现这些组件之间的连接通信。
网络接口17可选的可以包括标准的有线接口、无线接口(如WI-FI接口),通常用于在电子装置1与其他电子设备之间建立通信连接。
可选地,电子装置1还可以包括用户接口,用户接口可以包括显示器(Display)、输入单元比如键盘(Keyboard),可选的用户接口还可以包括标准的有线接口、无线接口。可选地,在一些实施例中,显示器可以是LED显示器、液晶显示器、触控式液晶显示器以及OLED(Organic Light-Emitting Diode,有机发光二极管)触摸器等。其中,显示器也可以适当的称为显示屏或显示单元,用于显示在电子装置中处理的信息以及用于显示可视化的用户界面。
图2仅示出了具有组件11~17的电子装置1,本领域技术人员可以理解的是,图2示出的结构并不构成对电子装置的限定,可以包括比图示更少或者更多的部件,或者组合某些部件,或者不同的部件布置。
在图2所示的电子装置1的实施例中,存储器11中存储有基于Redis的mqtt集群的监控程序111;处理器13执行存储器11中存储的基于Redis的mqtt集群的监控程序111时实现如下步骤:
将存储在Redis缓存控制系统中的主从服务器配置信息加载到内存中;
通过Redis缓存控制系统对主服务器进行监控;
当判断其中一主服务器宕机时,通过所述Redis缓存控制系统变更内存中保存的主从服务器配置信息;
通过所述Redis缓存控制系统发送主从切换指令给其中一从服务器替代 所述主服务器作为新的主服务器,并将其它从服务器保留的所述主服务器地址改为所述新的主服务器的地址。
例如,在mqtt集群服务器中,有多个主服务器,每个主服务器对应多个从服务器,在正常运行中,主服务器连接客户端,从服务器用于备份主服务器的数据,当主服务器宕机时,与宕机的主服务器对应的其中一从服务器被所述Redis缓存控制系统切换为主服务器,而其他对应的服务器保留的主服务器地址改为所述新的主服务器的地址。
优选地,所述基于Redis的mqtt集群的监控程序被所述处理器执行时实现如下步骤:
存储已接入的客户端的客户端标识符;
通过所述Redis缓存控制系统判断当前接入的客户端的当前客户端标识符与存储的客户端标识符一致时,断开当前接入的客户端。
在正常情况下,所有接入的客户端,主服务器都会将接入的客户端的客服端标识符存储,当新接入的客户端接入时,Redis缓存控制系统会查找之前的客户端标识符与当前的客户端标识符进行比较,如果相同,则断开当前接入的客户端。
优选地,在判断前接入的客户端的当前客户端标识符与存储的客户端标识符是否一致之前所述基于Redis的mqtt集群的监控程序被所述处理器执行时实现如下步骤:
先判断存储的客户端标识符对应的客户端是否都正常连接;
如果是,则判断当前接入的客户端的当前客户端标识符与存储的客户端标识符一致时,断开当前接入的客户端;
如果不是,找出不是正常连接的客户端对应的客户端标识符,并与当前的客户端标识符进行对比判断是否相同,如果相同,则判断所述当前接入的客户端为断开重连,并连接所述当前客户端。
通过以上判断方法,可以有效地判断客户端是断开重连还是恶意连接, 从而可以精确地判断客户端是否重连。
优选地,所述通过Redis缓存控制系统对主服务器进行监控的步骤包括:在预设时间内通过所述Redis缓存控制系统对所述主服务器发送Ping命令来监控主服务器是否宕机。例如,每隔为5秒、10秒或15秒等向主服务器发送Ping命令。
优选地,所述将存储在Redis缓存控制系统中的主从服务器配置信息加载到内存中的步骤包括:
在Redis缓存控制系统中创建配置信息表,所述配置信息表包含了主服务器的配置信息及从服务器的配置信息;所述主服务器的配置信息包含主服务器的IP和端口信息,所述从服务器的配置信息包含从服务器的IP和端口信息;
将所述配置信息表发送加载至内存中。
此外,当判断出主服务器宕机时,Redis缓存控制系统可以判断从服务器的运行情况,并且在判断从服务器正常的情况下变更内存中保存的主从配置信息,否则发出报警指令给报警装置。
本实施例提出的电子装置通过Redis缓存控制系统对所述主从服务器进行监控,当判断其中一主服务器宕机时,所述Redis缓存控制系统变更内存中保存的主从服务器配置信息,从而进一步对主从服务器进行切换,这样可以确保及时有效地进行主从服务器切换,从而提升了主从服务器切换的效率。另外,在本方案中,除了有效地监控主服务器及从服务器的运行情况,同时也能监控客户端是否有重连的情况,从而使监控效果更加全面而有效。
此外,本申请实施例还提出一种计算机可读存储介质,所述计算机可读存储介质上存储有的基于Redis的mqtt集群的监控程序111,所述基于Redis的mqtt集群的监控程序111可被一个或多个处理器执行,以实现如下操作:将存储在Redis缓存控制系统中的主从服务器配置信息加载到内存中;
通过Redis缓存控制系统对主服务器进行监控;
当判断其中一主服务器宕机时,通过所述Redis缓存控制系统变更内存中保存 的主从服务器配置信息;
通过所述Redis缓存控制系统发送主从切换指令给其中一从服务器替代所述主服务器作为新的主服务器,并将其它从服务器保留的所述主服务器地址改为所述新的主服务器的地址。
例如,在mqtt集群服务器中,有多个主服务器,每个主服务器对应多个从服务器,在正常运行中,主服务器连接客户端,从服务器用于备份主服务器的数据,当主服务器宕机时,与宕机的主服务器对应的其中一从服务器被所述Redis缓存控制系统切换为主服务器,而其他对应的服务器保留的主服务器地址改为所述新的主服务器的地址。
本申请计算机可读存储介质具体实施方式与上述电子装置和方法各实施例基本相同,在此不作累述。
可选地,在其他实施例中,所述基于Redis的mqtt集群的监控程序111还可以被分割为一个或者多个模块,一个或者多个模块被存储于存储器11中,并由一个或多个处理器(本实施例为处理器13)所执行以完成本申请,本申请所称的模块是指能够完成特定功能的一系列计算机程序指令段,用于描述基于Redis的mqtt集群的监控程序111在电子装置中的执行过程。
例如,参照图3所示,为本申请电子装置一实施例中的基于Redis的mqtt集群的监控程序111的程序模块示意图,该实施例中,基于Redis的mqtt集群的监控程序111可以被分割为加载模块10、监控模块20、变更模块30、切换模块40,示例性地:
所述加载模块10,用于将存储在Redis缓存控制系统中的主从服务器配置信息加载到内存中;
所述监控模块20,用于通过Redis缓存控制系统对主服务器进行监控;
所述变更模块30,用于当判断其中一主服务器宕机时,通过所述Redis缓存控制系统变更内存中保存的主从服务器配置信息。
所述切换模块40,用于通过所述Redis缓存控制系统发送主从切换指令 给其中一从服务器一替代所述主服务器作为新的主服务器,并将其它从服务器保留的所述主服务器地址改为所述新的主服务器的地址。
例如,在mqtt集群服务器中,有多个主服务器,每个主服务器对应多个从服务器,在正常运行中,主服务器连接客户端,从服务器用于备份主服务器的数据,当主服务器宕机时,与宕机的主服务器对应的其中一从服务器被所述Redis缓存控制系统切换为主服务器,而其他对应的服务器保留的主服务器地址改为所述新的主服务器的地址。
所述加载模块10、所述监控模块20、所述变更模块30、所述切换模块40等程序模块被执行时所实现的功能或操作步骤与上述实施例大体相同,在此不再赘述。
需要说明的是,上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。并且本文中的术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、装置、物品或者方法不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、装置、物品或者方法所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、装置、物品或者方法中还存在另外的相同要素。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在如上所述的一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本申请各个实施例所述的方法。
以上仅为本申请的优选实施例,并非因此限制本申请的专利范围,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间 接运用在其他相关的技术领域,均同理包括在本申请的专利保护范围内。

Claims (20)

  1. 一种基于Redis的mqtt集群的监控方法,应用于电子装置,其特征在于,所述方法包括:
    将存储在Redis缓存控制系统中的主从服务器配置信息加载到内存中;
    通过Redis缓存控制系统对主服务器进行监控;
    当判断其中一主服务器宕机时,通过所述Redis缓存控制系统变更内存中保存的主从服务器配置信息;
    通过所述Redis缓存控制系统发送主从切换指令给其中一从服务器替代所述主服务器作为新的主服务器,并将其它从服务器保留的所述主服务器地址改为所述新的主服务器的地址。
  2. 如权利要求1所述的基于Redis的mqtt集群的监控方法,其特征在于,所述方法还包括:
    存储已接入的客户端的客户端标识符;
    通过所述Redis缓存控制系统判断当前接入的客户端的当前客户端标识符与存储的客户端标识符一致时,断开当前接入的客户端。
  3. 如权利要求2所述的基于Redis的mqtt集群的监控方法,其特征在于,在判断前接入的客户端的当前客户端标识符与存储的客户端标识符是否一致之前,所述方法还包括:
    先判断存储的客户端标识符对应的客户端是否都正常连接;
    如果是,则判断当前接入的客户端的当前客户端标识符与存储的客户端标识符一致时,断开当前接入的客户端;
    如果不是,找出不是正常连接的客户端对应的客户端标识符,并与当前的客户端标识符进行对比判断是否相同,如果相同,则判断所述当前接入的客户端为断开重连,并连接所述当前客户端。
  4. 如权利要求1所述的基于Redis的mqtt集群的监控方法,其特征在于, 所述通过Redis缓存控制系统对主服务器进行监控的步骤包括:
    在预设时间内通过所述Redis缓存控制系统对所述主服务器发送Ping命令来监控主服务器是否宕机。
  5. 如权利要求2所述的基于Redis的mqtt集群的监控方法,其特征在于,所述通过Redis缓存控制系统对主服务器进行监控的步骤包括:
    在预设时间内通过所述Redis缓存控制系统对所述主服务器发送Ping命令来监控主服务器是否宕机。
  6. 如权利要求3所述的基于Redis的mqtt集群的监控方法,其特征在于,所述通过Redis缓存控制系统对主服务器进行监控的步骤包括:
    在预设时间内通过所述Redis缓存控制系统对所述主服务器发送Ping命令来监控主服务器是否宕机。
  7. 如权利要求1-6任一项所述的基于Redis的mqtt集群的监控方法,其特征在于,所述将存储在Redis缓存控制系统中的主从服务器配置信息加载到内存中的步骤包括:
    在Redis缓存控制系统中创建配置信息表,所述配置信息表包含了主服务器的配置信息及从服务器的配置信息;所述主服务器的配置信息包含主服务器的IP和端口信息,所述从服务器的配置信息包含从服务器的IP和端口信息;
    将所述配置信息表发送加载至内存中。
  8. 一种电子装置,其特征在于,所述电子装置包括存储器和处理器,所述存储器上存储有可在所述处理器上运行的基于Redis的mqtt集群的监控程序,所述基于Redis的mqtt集群的监控程序被所述处理器执行时实现如下步骤:
    将存储在Redis缓存控制系统中的主从服务器配置信息加载到内存中;
    通过Redis缓存控制系统对主服务器进行监控;
    当判断其中一主服务器宕机时,通过所述Redis缓存控制系统变更内存中保存的主从服务器配置信息;
    通过所述Redis缓存控制系统发送主从切换指令给其中一从服务器一替代所述主服务器作为新的主服务器,并将其它从服务器保留的所述主服务器地址改为所述新的主服务器的地址。
  9. 如权利要求8所述的电子装置,其特征在于,还包括:
    存储已接入的客户端的客户端标识符;
    通过所述Redis缓存控制系统判断当前接入的客户端的当前客户端标识符与存储的客户端标识符一致时,断开当前接入的客户端。
  10. 如权利要求9所述的电子装置,其特征在于,在判断前接入的客户端的当前客户端标识符与存储的客户端标识符是否一致之前,还包括:
    先判断存储的客户端标识符对应的客户端是否都正常连接;
    如果是,则判断当前接入的客户端的当前客户端标识符与存储的客户端标识符一致时,断开当前接入的客户端;
    如果不是,找出不是正常连接的客户端对应的客户端标识符,并与当前的客户端标识符进行对比判断是否相同,如果相同,则判断所述当前接入的客户端为断开重连,并连接所述当前客户端。
  11. 如权利要求8所述的电子装置,其特征在于,所述通过Redis缓存控制系统对主服务器进行监控的步骤包括:
    在预设时间内通过所述Redis缓存控制系统对所述主服务器发送Ping命令来监控主服务器是否宕机。
  12. 如权利要求9所述的电子装置,其特征在于,所述通过Redis缓存控制系统对主服务器进行监控的步骤包括:
    在预设时间内通过所述Redis缓存控制系统对所述主服务器发送Ping命令来监控主服务器是否宕机。
  13. 如权利要求10所述的电子装置,其特征在于,所述通过Redis缓存控制系统对主服务器进行监控的步骤包括:
    在预设时间内通过所述Redis缓存控制系统对所述主服务器发送Ping命 令来监控主服务器是否宕机。
  14. 如权利要求8-13任一项所述的电子装置,其特征在于,所述将存储在Redis缓存控制系统中的主从服务器配置信息加载到内存中的步骤包括:
    在Redis缓存控制系统中创建配置信息表,所述配置信息表包含了主服务器的配置信息及从服务器的配置信息;所述主服务器的配置信息包含主服务器的IP和端口信息,所述从服务器的配置信息包含从服务器的IP和端口信息;
    将所述配置信息表发送加载至内存中。
  15. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质上存储有基于Redis的mqtt集群的监控程序,所述基于Redis的mqtt集群的监控程序可被一个或者多个处理器执行,以实现如下步骤:
    将存储在Redis缓存控制系统中的主从服务器配置信息加载到内存中;
    通过Redis缓存控制系统对主服务器进行监控;
    当判断其中一主服务器宕机时,通过所述Redis缓存控制系统变更内存中保存的主从服务器配置信息;
    通过所述Redis缓存控制系统发送主从切换指令给其中一从服务器一替代所述主服务器作为新的主服务器,并将其它从服务器保留的所述主服务器地址改为所述新的主服务器的地址。
  16. 如权利要求15所述的计算机可读存储介质,其特征在于,还包括:
    存储已接入的客户端的客户端标识符;
    通过所述Redis缓存控制系统判断当前接入的客户端的当前客户端标识符与存储的客户端标识符一致时,断开当前接入的客户端。
  17. 如权利要求16所述的计算机可读存储介质,其特征在于,在判断前接入的客户端的当前客户端标识符与存储的客户端标识符是否一致之前,还包括:
    先判断存储的客户端标识符对应的客户端是否都正常连接;
    如果是,则判断当前接入的客户端的当前客户端标识符与存储的客户端 标识符一致时,断开当前接入的客户端;
    如果不是,找出不是正常连接的客户端对应的客户端标识符,并与当前的客户端标识符进行对比判断是否相同,如果相同,则判断所述当前接入的客户端为断开重连,并连接所述当前客户端。
  18. 如权利要求15所述的计算机可读存储介质,其特征在于,所述通过Redis缓存控制系统对主服务器进行监控的步骤包括:
    在预设时间内通过所述Redis缓存控制系统对所述主服务器发送Ping命令来监控主服务器是否宕机。
  19. 如权利要求16所述的计算机可读存储介质,其特征在于,所述通过Redis缓存控制系统对主服务器进行监控的步骤包括:
    在预设时间内通过所述Redis缓存控制系统对所述主服务器发送Ping命令来监控主服务器是否宕机。
  20. 如权利要求15-19任一项所述的计算机可读存储介质,其特征在于,所述将存储在Redis缓存控制系统中的主从服务器配置信息加载到内存中的步骤包括:
    在Redis缓存控制系统中创建配置信息表,所述配置信息表包含了主服务器的配置信息及从服务器的配置信息;所述主服务器的配置信息包含主服务器的IP和端口信息,所述从服务器的配置信息包含从服务器的IP和端口信息;
    将所述配置信息表发送加载至内存中。
PCT/CN2019/118006 2019-05-29 2019-11-13 基于Redis的mqtt集群的监控方法、装置及存储介质 WO2020238057A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910460725.1 2019-05-29
CN201910460725.1A CN110324176A (zh) 2019-05-29 2019-05-29 基于Redis的mqtt集群的监控方法、装置及存储介质

Publications (1)

Publication Number Publication Date
WO2020238057A1 true WO2020238057A1 (zh) 2020-12-03

Family

ID=68119198

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/118006 WO2020238057A1 (zh) 2019-05-29 2019-11-13 基于Redis的mqtt集群的监控方法、装置及存储介质

Country Status (2)

Country Link
CN (1) CN110324176A (zh)
WO (1) WO2020238057A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110324176A (zh) * 2019-05-29 2019-10-11 平安科技(深圳)有限公司 基于Redis的mqtt集群的监控方法、装置及存储介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102682043A (zh) * 2011-04-14 2012-09-19 天脉聚源(北京)传媒科技有限公司 一种分布式数据库连接方法
CN102880475A (zh) * 2012-10-23 2013-01-16 上海普元信息技术股份有限公司 计算机软件系统中基于云计算的实时事件处理系统及方法
US20170286527A1 (en) * 2015-11-06 2017-10-05 Wangsu Science & Technology Co., Ltd. Redis key management method and system
CN109739686A (zh) * 2018-11-27 2019-05-10 无锡天脉聚源传媒科技有限公司 一种多服务器热备份方法、系统、装置和存储介质
CN110324176A (zh) * 2019-05-29 2019-10-11 平安科技(深圳)有限公司 基于Redis的mqtt集群的监控方法、装置及存储介质

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104394142B (zh) * 2014-11-24 2018-02-16 北京京东尚科信息技术有限公司 用于实现Redis自动主从切换的方法和系统
CN106559267A (zh) * 2016-11-25 2017-04-05 聚好看科技股份有限公司 Redis的主从切换方法、装置及redis系统
CN106534328B (zh) * 2016-11-28 2020-01-31 网宿科技股份有限公司 节点连接方法及分布式计算系统
CN106657394B (zh) * 2017-02-10 2020-06-05 浪潮软件科技有限公司 一种基于物联网大数据的设备信息采集系统及方法
CN109257387A (zh) * 2018-11-20 2019-01-22 郑州云海信息技术有限公司 用于断线重连的方法和装置

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102682043A (zh) * 2011-04-14 2012-09-19 天脉聚源(北京)传媒科技有限公司 一种分布式数据库连接方法
CN102880475A (zh) * 2012-10-23 2013-01-16 上海普元信息技术股份有限公司 计算机软件系统中基于云计算的实时事件处理系统及方法
US20170286527A1 (en) * 2015-11-06 2017-10-05 Wangsu Science & Technology Co., Ltd. Redis key management method and system
CN109739686A (zh) * 2018-11-27 2019-05-10 无锡天脉聚源传媒科技有限公司 一种多服务器热备份方法、系统、装置和存储介质
CN110324176A (zh) * 2019-05-29 2019-10-11 平安科技(深圳)有限公司 基于Redis的mqtt集群的监控方法、装置及存储介质

Also Published As

Publication number Publication date
CN110324176A (zh) 2019-10-11

Similar Documents

Publication Publication Date Title
US20210329493A1 (en) Method and system for group communication, group server, and group member device
US11003639B2 (en) Database data migration method, apparatus, terminal, system, and storage medium
US10397120B2 (en) Service link selection control method and device
US10110671B2 (en) Method, system, and device for managing server hardware resources in a cloud scheduling environment
WO2019100921A1 (zh) 消息推送方法及装置
US11743097B2 (en) Method and system for sharing state between network elements
US11432137B2 (en) Service notification method for mobile edge host and apparatus
WO2022127504A1 (zh) 网元管理方法、装置及存储介质
WO2020147301A1 (zh) 多租户业务接入实现方法、装置及电子设备
WO2018121334A1 (zh) 一种提供网页应用服务的方法、装置、电子设备及系统
CN103763121A (zh) 一种网络配置信息快速下发的方法及装置
CN103188098B (zh) 一种容灾切换方法、系统以及装置
WO2019104974A1 (zh) 基于dubbo平台的服务自动启停方法、服务器及存储介质
CN110719311A (zh) 分布式协调服务方法、系统及计算机可读存储介质
CN112187903A (zh) 一种消息推送方法、装置及消息服务系统
WO2019062019A1 (zh) 一种数据列表的导出方法及其终端
US20150019955A1 (en) Method and system for displaying literal contents, mobile terminal, cloud typesetting server, and storage medium
WO2020238057A1 (zh) 基于Redis的mqtt集群的监控方法、装置及存储介质
CN104253792A (zh) 基板管理控制器虚拟系统及方法
WO2022062390A1 (zh) 一种多路径连接方法、装置及电子设备和存储介质
US10659320B2 (en) Device management system
CN112788585A (zh) 一种5g核心网中nf切换方法、装置及存储介质
CN109739868B (zh) 一种数据处理方法及其相关设备
WO2023159956A1 (zh) 一种裸金属服务器检查及部署方法、装置、设备、介质
WO2023029485A1 (zh) 数据处理方法、装置、计算机设备及计算机可读存储介质

Legal Events

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

Ref document number: 19930202

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

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 (EPO FORM 1205A DATED 07.06.2022)

122 Ep: pct application non-entry in european phase

Ref document number: 19930202

Country of ref document: EP

Kind code of ref document: A1