CN107181834B - Method and device for managing virtual IP address by redis and redis system - Google Patents

Method and device for managing virtual IP address by redis and redis system Download PDF

Info

Publication number
CN107181834B
CN107181834B CN201710576458.5A CN201710576458A CN107181834B CN 107181834 B CN107181834 B CN 107181834B CN 201710576458 A CN201710576458 A CN 201710576458A CN 107181834 B CN107181834 B CN 107181834B
Authority
CN
China
Prior art keywords
redis
address
redis node
virtual
node
Prior art date
Legal status (The legal status 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 status listed.)
Active
Application number
CN201710576458.5A
Other languages
Chinese (zh)
Other versions
CN107181834A (en
Inventor
刘先攀
吴连朋
夏章抓
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Qingdao Hisense Media Network Technology Co Ltd
Original Assignee
Qingdao Hisense Media Network Technology Co Ltd
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 Qingdao Hisense Media Network Technology Co Ltd filed Critical Qingdao Hisense Media Network Technology Co Ltd
Publication of CN107181834A publication Critical patent/CN107181834A/en
Application granted granted Critical
Publication of CN107181834B publication Critical patent/CN107181834B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/50Address allocation
    • H04L61/5046Resolving address allocation conflicts; Testing of addresses
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/50Address allocation
    • H04L61/5053Lease time; Renewal aspects
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/50Address allocation
    • H04L61/5007Internet protocol [IP] addresses

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Small-Scale Networks (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The invention provides a method, a device and a system for managing a virtual IP address by a redis, wherein a current redis node receives a main redis node identifier fed back by sentinel; when the main redis node identification is matched with the current redis node identification, detecting whether a virtual IP address is set in the current redis node or not, and if so, broadcasting the virtual IP address; if not, adding a virtual IP address in the current redis node and broadcasting the added virtual IP address; and when the main redis node identification is not matched with the current redis node identification, deleting the virtual IP address set in the current redis node. Therefore, the invention can ensure that the virtual IP address is switched along with the main redis node after the master-slave switching, and the virtual IP address is always only arranged on the main redis node, thereby avoiding the problem of business split caused by network flash or blockage and the like and improving the reliability of the redis system.

Description

Method and device for managing virtual IP address by redis and redis system
Technical Field
The present invention relates to the field of cache technologies, and in particular, to a method and an apparatus for managing a virtual IP address by a redis, and a redis system.
Background
Redis is a high-performance open-source key-value database, has high read-write performance, can store mapping (mapping) between keys (keys) and values (values) of 5 different types, and can persist key value pair data stored in a memory to a hard disk, and a user can configure different persistence modes according to actual use scenes. In order to improve reliability of the redis, a master-slave redis is generally set in a different server, and is managed by a management module. When the master redis fails, the management module switches the slave redis to the master redis, and sends a notification message to each service network element needing to access the redis, so that each service network element modifies the stored IP address of the redis, and the service network element can access the switched master redis according to the modified Internet Protocol (IP) address of the redis.
In the existing Redis high-availability scheme technology, the Redis-sentinel and keepalive are commonly used as a management module to realize the supervision of Redis master-slave switching, but under the condition that a network is unstable, communication abnormality occurs between keepalives in different rediss, so that virtual IP addresses exist in different rediss at the same time, for example, under the condition that the virtual IP addresses are not deleted on a Redis master node before switching, a master node after switching already starts to set the virtual IP addresses, so that the condition that a plurality of Redis nodes all set the virtual IP addresses is caused, and the problem that a plurality of Redis nodes can be accessed according to the virtual IP addresses is caused, and the problem is generally called as 'business split', so that the problems of data confusion, data loss and the like occur. Therefore, a new Redis high availability solution is needed to solve the above problems.
Disclosure of Invention
In view of this, the present invention provides a method and an apparatus for redis to manage a virtual IP address, and a redis system to solve the problem of business split caused by keepalived communication abnormality.
Specifically, the invention is realized by the following technical scheme:
in one aspect, the present invention provides a method for redis to manage a virtual IP address, where the method is applied to any one redis node in a redis system, and the method includes:
the current redis node receives a main redis node identifier fed back by sentinel;
when the main redis node identification is matched with the current redis node identification, detecting whether a virtual IP address is set in the current redis node or not, and if so, broadcasting the virtual IP address; if not, adding a virtual IP address in the current redis node and broadcasting the added virtual IP address;
and when the main redis node identification is not matched with the current redis node identification, deleting the virtual IP address set in the current redis node.
On the other hand, based on the same concept, the present invention further provides an apparatus for redis to manage a virtual IP address, where the apparatus is applied to any one of the redis nodes in a redis system, and the apparatus includes:
the identifier receiving unit is used for receiving the main redis node identifier fed back by the sentinel by the current redis node;
the address setting unit is used for detecting whether a virtual IP address is set in the current redis node or not when the main redis node identification is matched with the current redis node identification, and broadcasting the virtual IP address if the virtual IP address is set in the current redis node; if not, adding a virtual IP address in the current redis node and broadcasting the added virtual IP address;
and the address deleting unit is used for deleting the virtual IP address set in the current redis node when the main redis node identification is not matched with the current redis node identification.
In another aspect, based on the same concept, the present invention further provides a redis system, including a plurality of rediss and a device for managing virtual IP addresses by the redis corresponding to each of the rediss.
The technical scheme provided by the embodiment of the invention has the following beneficial effects:
the method can acquire the main redis node identification from sentinel through any redis node in the redis system; when the identification of the main node is matched with the identification of the current redis node, determining the current redis node as the main redis node, and setting a virtual IP address for the redis node and broadcasting; when the identification of the master node is not matched with the identification of the current redis node, the current redis node is not the master redis node, and therefore the virtual IP address of the current redis node is deleted. Compared with the prior art, the method and the device can utilize the sentinel to monitor the switching function of the master-slave redis nodes, determine the current master redis node by acquiring the master node identification from the sentinel, and set the virtual IP address for the current master redis node, thereby ensuring that the virtual IP address is switched along with the master redis node after the master-slave switching, always only having the virtual IP address on the master redis node, avoiding the business brain crack problem caused by network flash or blockage and the like, and improving the reliability of the redis system.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a diagram illustrating an application scenario in which a redis manages virtual IP addresses in an exemplary embodiment of the invention;
FIG. 2a is a process flow diagram of a method of a redis managing virtual IP addresses in an exemplary embodiment of the invention;
FIG. 2b is a graph illustrating the relationship of time lengths in an exemplary embodiment of the present invention;
FIG. 3 is a flowchart of another process for managing virtual IP addresses by a redis in an exemplary embodiment of the invention;
fig. 4 is a hardware structure diagram of a device in which a redis manages virtual IP addresses in an exemplary embodiment of the present invention;
fig. 5 is a logical structure diagram of an apparatus for managing a virtual IP address by a redis in an exemplary embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be described in detail with reference to the accompanying drawings.
Before explaining the embodiments of the present invention in detail, an application scenario of the embodiments of the present invention will be described. As shown in fig. 1, the method for managing virtual IP addresses by a redis according to the present invention is applied to a redis system, and the redis system includes: multiple sentinels, multiple redis nodes, specifically:
sentinel is the monitoring management instrument of the area certainly of redis, and the main function includes: monitoring, namely the sentinel can continuously check whether the master redis node and the slave redis node operate normally; reminding, namely when a monitored certain redis node has a problem, sending a notification to an administrator or other application programs by using sentinel; automatic fault migration, namely when one main redis node cannot work normally, sentinel starts one automatic fault migration operation to upgrade one redis node to a new main redis node, wherein the slave redis node represents the failed main redis node, and other slave redis nodes of the failed main redis node are reset according to the new main redis node.
Each redis node may be a physical machine, a virtual machine, etc. Each redis node is provided with a functional module with a redis management virtual IP address provided by the present invention, the functional module may be a redisHA network element in the redis node, and each redis node may communicate with a sentinel. At the same moment, one redis node in the redis system is a master redis node, and other redis nodes are slave redis nodes, wherein each redis node can become a master redis node, a virtual IP address is set in the master redis node, and the slave redis nodes do not set virtual IP addresses. In the actual application process, the service network element may access the main redis node in the redis system according to the virtual IP address.
Because the sentinel of the present invention can monitor the state of each redis node and determine the main redis node according to the state of the redis node, the redis node can maintain the corresponding virtual IP address according to the main redis node determined by the sentinel, so as to ensure that the service network element can access the main redis node in the redis system according to the virtual IP address.
In order to solve the problems in the prior art, the invention provides a method and a device for managing a virtual IP address by a redis, and a redis system, wherein the invention can acquire a main redis node identifier from sentinel through any one redis node in the redis system; when the identification of the main node is matched with the identification of the current redis node, determining the current redis node as the main redis node, and setting a virtual IP address for the redis node and broadcasting; when the identification of the master node is not matched with the identification of the current redis node, the current redis node is not the master redis node, and therefore the virtual IP address of the current redis node is deleted. Compared with the prior art, the method and the device can utilize the sentinel to monitor the switching function of the master-slave redis nodes, determine the current master redis node by acquiring the master node identification from the sentinel, and set the virtual IP address for the current master redis node, thereby ensuring that the virtual IP address is switched along with the master redis node after the master-slave switching, always only having the virtual IP address on the master redis node, avoiding the business brain crack problem caused by network flash or blockage and the like, and improving the reliability of the redis system.
Referring to fig. 2a, it is a process flow diagram of a method for a redis to manage virtual IP addresses in an exemplary embodiment of the present invention, where the method is applied to any one redis node in a redis system, and the method includes:
step 201, a current redis node receives a main redis node identifier fed back by sentinel;
in this embodiment, the current redis node may obtain the identifier of the main redis node from a sentinel in a manner of sending an identifier obtaining instruction to the sentinel in the redis system; the primary redis node identifier may specifically be an IP address of the primary redis node.
It should be noted that, because the sentinel also has a single point problem, that is, if a single sentinel is configured, the sentinel cannot work normally after the sentinel fails; in addition, in the present embodiment, most of the pie principles are adopted for communication between the sendiels, at least 3 sendiels are configured in the redis system in the present embodiment, so as to implement the technical solution of the present invention.
When a current redis node receives a redis node identifier fed back by a plurality of sentinels in the redis system, the same redis node identifier may be subjected to cumulative counting, and if an accumulated value obtained after the cumulative counting is greater than or equal to a preset threshold value, the redis node identifier corresponding to a maximum accumulated value in the accumulated values is used as an identifier of a main redis node. For example, when 3 sentinels are set in the redis system, the current redis node may send an identifier obtaining instruction to the three sentinels, and after each sentinels receives the identifier obtaining instruction, the self-recorded redis node identifiers, such as identifier 1, identifier 2, and identifier 3, are sent to the current redis node; after the current redis node receives identifier 1, identifier 2 and identifier 3 fed back by three sentinels respectively, the same identifier can be counted accumulatively, and then whether the accumulated value is not less than a preset threshold value is judged, wherein the preset threshold value can be set according to the actual number of the sentinels in the redis system, and in this embodiment, when the number of the sentinels is 3, the preset threshold value can be set to be 2. In an ideal state of normal operation of the system, the identifiers received by the current redis node should be the same, that is, the identifier 1, the identifier 2, and the identifier 3 are the same and are the identifiers of the master redis node after master-slave switching, and if the system is abnormal, a part of the identifiers received by the current redis node are the identifiers of the master redis node after master-slave switching; and the other part of identification is the identification of the master redis node before master-slave switching. In this embodiment, assuming that the identifiers 1 and 2 are the same and different from the identifiers 3, the cumulative value of the identifiers 1 is 2, and the cumulative value of the identifiers 3 is 1, and the cumulative values are respectively compared with the preset threshold, it is known that the cumulative value (2) of the identifiers 1 is equal to the preset threshold, and the cumulative value (1) of the identifiers 3 is smaller than the preset threshold. Therefore, whether the accumulated value of the identifier 1 is the largest accumulated value of all the accumulated values can be further determined, and if so, the identifier (identifier 1) of the redis node corresponding to the largest accumulated value is the identifier of the current main redis node. By the method for judging the identification of the main redis node, the accuracy of judging the main redis node by the redis node can not be influenced when the identification of the redis node fed back by a small part of sentinel in the system is wrong.
As an embodiment, if the accumulated value obtained by the redis node after the accumulation count is smaller than the preset threshold or the maximum accumulated value does not exist in the accumulated values, the current redis node may output a first warning message for indicating that determining the identifier of the main redis node fails, so as to stop the processing operation of the current step, and directly end the flow. For example, when the reis node receives an accumulated value of the reis node identifier that is smaller than a preset threshold, or although the accumulated value is greater than or equal to the preset threshold, there are two maximum accumulated values with the same number, and the two accumulated values are accumulated values of different reis node identifiers, it indicates that the current reis host node identifier is determined to be abnormal, and therefore a first alarm message for indicating that determining the host reis node identifier fails needs to be output to an administrator, and the current processing flow is stopped. The invention can stop processing in time and send the first warning message to the administrator when the judgment of the main redis node identification fails, thereby enabling the administrator to take corresponding processing measures to the abnormal state in time and avoiding long-time service abnormity.
As an embodiment, if the current redis node does not receive the redis node identifier fed back by the sentinel within a first set time length, outputting a second warning message indicating that receiving the redis node identifier for the sentinel fails, where the first set time length may be set according to a time length from a request of sending an identifier obtaining instruction by the redis node to a request of receiving the redis node identifier fed back by the sentinel, and considering an indeterminate factor of network transmission, the first set time length may be set by a method of monitoring a multiple time length averaging or according to an experience value of an actual user, which is not limited herein.
Specifically, when the current redis node sends an identifier obtaining instruction to each sentinel in the redis system, a timeout timer is started for each sentinel, and the duration of the timeout timer is the first set duration; when the timeout timer corresponding to the sendiel is overtime, and the redis node identifier fed back by the sendiel is still not received, the sendiel may be considered to be abnormal, so that the current redis node may output, to the administrator, a second alarm message indicating that receiving the redis node identifier for the sendiel fails, so that the administrator may take a processing measure for the abnormal sendiel, but the current redis node may not be affected to continue executing the operation flow of step 201, unless the current redis node is triggered to output the first alarm message due to the abnormal condition of the sendiel, the current operation flow may be stopped. And then, the current redis node can stop the overtime timer, reset the overtime timer, and restart the overtime timer until the next time the identifier acquisition instruction is sent to the sentinel.
When obtaining the redis node identifier from the sentinel, the server where the sentinel is located may have network disconnection and other abnormalities, which may result in that the redis node cannot obtain the redis node identifier for a long time, and further affect the processing of the system logic.
Step 202, when the main redis node identification is matched with the current redis node identification, detecting whether a virtual IP address is set in the current redis node, and if so, broadcasting the virtual IP address; if not, adding a virtual IP address in the current redis node and broadcasting the added virtual IP address;
in this embodiment, when the identifier of the master redis node matches the identifier of the current redis node, the current redis node may be considered as the master redis node, and then it may be further detected whether a virtual IP address is set in the current redis node, and if so, the current redis node may broadcast the virtual IP address through an ARP packet; if not, adding a virtual IP address in the current redis node and broadcasting the added virtual IP address so as to enable other service network elements to obtain the virtual IP address after receiving the APR message, and further accessing the redis host node according to the virtual IP address.
As an embodiment, when communication between different rediss is abnormal, a redis master-slave switching may be abnormal, the abnormality may cause that at least two master nodes exist after a slave node is switched to a master node, a virtual IP address set on the master redis node before switching is not deleted yet, and the master redis node after switching determines that the identifier thereof is the master redis node identifier, and the virtual IP address may be directly set, so that two identical virtual IP addresses exist in the redis system, thereby causing a business split. Therefore, in this embodiment, when it is detected that the virtual IP address is not set in the current redis node, the current redis node may further add the virtual IP address in the current redis node after waiting for a second set duration that is not less than the time length for deleting the virtual IP address. Specifically, when the current redis node determines that the current redis node is a main redis node and needs to set a virtual IP address, a coordinated timer is started locally, and the duration of the coordinated timer is not less than a second preset duration. When the coordinated timer expires, it may be considered that the virtual IP address has been deleted by other redis nodes, so the current redis node may add the virtual IP address. Then, the current redis node may reset the collaborative timer until the next time the redis node needs to set the virtual IP address, and restart the collaborative timer.
The second set duration is used for ensuring that the virtual IP address is added after the virtual IP address is deleted when the virtual IP address needs to be added to the current redis and the same virtual IP address needs to be deleted on other nodes different from the current redis node, so that the second set duration is greater than the time length required by other redis nodes to delete the virtual IP address, and the time length may be a time interval from the start of the main redis to the end of the virtual IP address deletion under the condition that synchronous processing is performed between different redis nodes, and the time length may be an empirical value determined by the time delay duration of the asynchronous processing and the time interval under the condition that asynchronous processing is performed between different redis nodes. In an alternative embodiment, the redis node may periodically perform the flow illustrated in fig. 2 a. Optionally, the period may be 1 second, 2 seconds, and the like, and in an actual application process, the period may be set according to actual needs. If the process described in fig. 2a is periodically executed, because the time length of each period may be enough for the redis node to complete the operation of deleting the virtual IP address, the current redis node may further set the second set time length to be the same as the period time length.
The relationship between the second set duration and the time length and the cycle time length required for deleting the virtual IP address may refer to fig. 2b, where the relationship includes time axes corresponding to the master redis node and the slave redis node shown in fig. 1, t1 is the time length required for deleting the virtual IP address from the redis node, t2 is the cycle time length for executing the flow shown in fig. 2a by the master redis node and the slave redis node, and the cycle time lengths of the master redis node and the slave redis node are the same; t is a second set time length that the master redis node needs to wait before setting the virtual IP address, and the set range of the second set time length T may be: t is more than or equal to T1 and less than or equal to T2; for example, when T1 is 1 second and T2 is 2 seconds, the setting range of the second set time period T is: t is more than or equal to 1 and less than or equal to 2 seconds. The invention can ensure that the master redis node can set the virtual IP address after other slave redis nodes with the set virtual IP address delete the virtual IP address by setting the second set duration, thereby avoiding business split.
And 203, deleting the virtual IP address set in the current redis node when the main redis node identification is not matched with the current redis node identification.
And on the current redis node, when the main redis node identifier is determined not to be matched with the current redis node identifier, indicating that the current redis node is not the main redis node, and deleting the virtual IP address set by the current redis node.
Compared with the prior art, the method and the device can utilize the function that the sentinel can monitor the switching of the master and slave redis nodes, and determine the master redis node by acquiring information from the sentinel, so that after master and slave switching, the virtual IP is ensured to be switched along with the redis master node, the virtual IP address is always kept on the redis master node, the problem of business brain fracture caused by network flash or blockage and the like is avoided, and the reliability of the redis system is improved.
In order to make the objects, technical solutions and advantages of the present invention more apparent, the solution of the present invention is further described in detail with reference to fig. 3.
Please refer to fig. 3, which is a processing flowchart of another method for a redis node to manage virtual IP addresses in an exemplary embodiment of the present invention, where the method is applied to any one redis node in a redis system, and the redis node may periodically execute the flow shown in fig. 3, in this embodiment, the identification of the master redis node takes a master redis node IP address as an example for description, and the method includes;
step 301, judging whether the IP address of the main redis node is successfully acquired from sentinel or not; if yes, go to step 302; if not, go to step 305;
specifically, when a current redis node receives redis node IP addresses fed back by a plurality of sentinels in the redis system, the same redis node IP addresses may be subjected to cumulative counting, and if a cumulative value obtained after the cumulative counting is greater than or equal to a preset threshold value, the redis node IP address corresponding to a maximum cumulative value in the cumulative value is taken as a main redis node IP address, which indicates that the main redis node IP address is successfully obtained from the sentinels; and if the accumulated value obtained after the accumulation counting is smaller than the preset threshold value or the maximum accumulated value is not found in the accumulated values, the fact that the main redis node IP address is successfully acquired from sentinel is indicated. As shown in the system of fig. 1, if 3 sentinels are deployed in the system, the preset number may be set to 2; when any redisHA, for example, redisHA-1, respectively acquires IP addresses from the three sentinels, assuming that IP1 is the same as IP2 and is different from IP3, it may be determined that the cumulative value of IP1 is 2 and is equal to the preset threshold, and since the cumulative value of IP1 is obtained to be the maximum, IP1 may be considered as the IP address of the main redis node in the current time period. Therefore, the redisHA-1 successfully acquires the IP address of the main redis node from the sentinel; on the contrary, if the redisHA receives less than 2 accumulated values, the reason that the accumulated values are less than 2 may be due to the timeout of the acquisition command, or may be due to the fact that most of the IP addresses sent by different sentinels are different, and for any reason, the redisHA considers that the acquisition of the IP address of the master redis node from the sentinels fails.
Step 302, judging whether the IP address of the main redis node is matched with the IP address of the redis node; if yes, go to step 303; if not, go to step 306;
step 303, judging whether a virtual IP address (VIP) is set in the current redis node; if yes, go to step 304; if not, go to step 307;
step 304, broadcasting the virtual IP address of the current redis node, and ending;
step 305, sending a first warning message, and ending;
step 306, judging whether the current node has a virtual IP address; if yes, go to step 308; if not, ending;
step 307, setting a virtual IP address for the current redis node, and turning to step 304;
and 308, deleting the virtual IP address of the current redis node when the IP address of the main redis node is not matched with the IP address of the current redis node.
The invention monitors master-slave switching of the redis node through the sentinel and acquires the IP address of the master redis node from the sentinel at regular time through the redisHA, so that the virtual IP address is switched along with the master redis node, thereby avoiding the split brain problem caused by network flash or blockage and the like and ensuring the reliability of the function.
Based on the same conception, the invention also provides a device for managing the virtual IP address by the redis, which can be realized by software or by a hardware or a combination of the software and the hardware. Taking software implementation as an example, the device for managing virtual IP addresses by redis of the present invention is a device in a logical sense, and is formed by reading and running a corresponding computer program instruction in a memory by a CPU of a redis node device in which the device is located.
Referring to fig. 4, a device 500 for redis to manage virtual IP addresses in an exemplary embodiment of the present invention, where the device is applied to any one redis node in a redis system, and a basic operating environment of the device includes a CPU, a memory, and other hardware, and from a logical level, a logical structure of the device 500 is as shown in fig. 5, where:
an identifier receiving unit 501, configured to receive, by a current redis node, a main redis node identifier fed back by sentinel;
an address setting unit 502, configured to detect whether a virtual IP address is set in a current redis node when the main redis node identifier matches the current redis node identifier, and if so, broadcast the virtual IP address; if not, adding a virtual IP address in the current redis node and broadcasting the added virtual IP address;
an address deleting unit 503, configured to delete the virtual IP address set in the current redis node when the master redis node identifier does not match the current redis node identifier.
As an embodiment, the identifier receiving unit 501 specifically includes:
the first subunit 5011, configured to receive, by the current redis node, a redis node identifier fed back by the plurality of sentinels;
the second subunit 5012 is configured to perform cumulative counting on the same redis node identifiers;
the third sub-unit 5013 is configured to, if the accumulated value obtained after the accumulation counting is greater than or equal to a preset threshold, use the identifier of the redis node corresponding to the largest accumulated value in the accumulated values as the identifier of the primary redis node.
As an embodiment, the identifier receiving unit 501 further includes:
the fourth sub-unit 5014 is configured to output a first warning message indicating that the determination of the primary redis node identification fails.
As an embodiment, the identifier receiving unit 501 further includes:
the fifth subunit 5015 is configured to, if the current redis node does not receive the redis node identifier fed back by the sentinel within the first set time period, output a second warning message indicating that receiving the redis node identifier for the sentinel fails.
As an embodiment, the address setting unit 502 is specifically configured to, when it is detected that a virtual IP address is not set in a current redis node, wait for a second set time length that is not less than a time length required for deleting the virtual IP address, and add the virtual IP address in the current redis node.
The implementation process of the functions and actions of each unit in the above device is specifically described in the implementation process of the corresponding step in the above method, and is not described herein again.
An embodiment of the present invention further provides a redis system, including a sentinel, a plurality of rediss, and a device for managing virtual IP addresses by the redis, which is corresponding to each of the rediss, and is described in the embodiment of fig. 4 or fig. 5. Fig. 1 may be referred to for a structure of a redis system, and details of an embodiment of the present invention are not repeated.
In summary, the present invention can obtain the main redis node identifier from sentinel through any one redis node in the redis system; when the identification of the main node is matched with the identification of the current redis node, determining the current redis node as the main redis node, and setting a virtual IP address for the redis node and broadcasting; when the identification of the master node is not matched with the identification of the current redis node, the current redis node is not the master redis node, and therefore the virtual IP address of the current redis node is deleted. Compared with the prior art, the method and the device can utilize the sentinel to monitor the switching function of the master-slave redis nodes, determine the current master redis node by acquiring the master node identification from the sentinel, and set the virtual IP address for the current master redis node, thereby ensuring that the virtual IP address is switched along with the master redis node after the master-slave switching, always only having the virtual IP address on the master redis node, avoiding the business brain crack problem caused by network flash or blockage and the like, and improving the reliability of the redis system.
For the device embodiments, since they substantially correspond to the method embodiments, reference may be made to the partial description of the method embodiments for relevant points. The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of the application. One of ordinary skill in the art can understand and implement it without inventive effort.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.

Claims (9)

1. A method for managing virtual IP addresses by a redis, which is applied to any one redis node in a redis system, and comprises the following steps:
the current redis node receives a redis node identifier fed back by a plurality of sentinels; performing accumulated counting for the same redis node identification; if the accumulated value obtained after the accumulated counting is larger than or equal to a preset threshold value, taking the identifier of the redis node corresponding to the largest accumulated value in the accumulated values as the identifier of the main redis node;
when the main redis node identification is matched with the current redis node identification, detecting whether a virtual IP address is set in the current redis node or not, and if so, broadcasting the virtual IP address; if not, adding a virtual IP address in the current redis node and broadcasting the added virtual IP address;
and when the main redis node identification is not matched with the current redis node identification, deleting the virtual IP address set in the current redis node.
2. The method of claim 1, wherein if the accumulated value obtained after the accumulated count is less than a predetermined threshold or the largest accumulated value does not exist in the accumulated values, the method further comprises:
and outputting a first alarm message for indicating that the primary redis node identification is determined to be failed.
3. The method of claim 1, further comprising:
and if the current redis node does not receive the redis node identifier fed back by the sentinel within the first set time length, outputting a second warning message for indicating that the receiving of the redis node identifier for the sentinel fails.
4. The method according to claim 1, wherein the current redis node is added with a virtual IP address, specifically:
and when detecting that the virtual IP address is not set in the current redis node, adding the virtual IP address in the current redis node after waiting for a second set time length which is not less than the time length required for deleting the virtual IP address.
5. An apparatus for managing virtual IP addresses by a redis, the apparatus being applied to any one redis node in a redis system, the apparatus comprising:
the identifier receiving unit specifically includes:
the first subunit is used for receiving the redis node identification fed back by the plurality of sentinels by the current redis node;
the second subunit is configured to perform cumulative counting on the same redis node identifier;
a third subunit, configured to, if an accumulated value obtained after the accumulation counting is greater than or equal to a preset threshold, use the identifier of the redis node corresponding to a largest accumulated value in the accumulated values as an identifier of a main redis node;
the address setting unit is used for detecting whether a virtual IP address is set in the current redis node or not when the main redis node identification is matched with the current redis node identification, and broadcasting the virtual IP address if the virtual IP address is set in the current redis node; if not, adding a virtual IP address in the current redis node and broadcasting the added virtual IP address;
and the address deleting unit is used for deleting the virtual IP address set in the current redis node when the main redis node identification is not matched with the current redis node identification.
6. The apparatus of claim 5, wherein the identity receiving unit further comprises:
and the fourth subunit is used for outputting the first alarm message used for indicating that the determination of the identification of the main redis node fails.
7. The apparatus of claim 5, wherein the identity receiving unit further comprises:
and the fifth subunit is configured to output a second warning message used for indicating that receiving the redis node identifier for the sentinel fails if the current redis node does not receive the redis node identifier fed back by the sentinel within the first set time duration.
8. The apparatus of claim 5,
the address setting unit is specifically configured to, when it is detected that the virtual IP address is not set in the current redis node, add the virtual IP address in the current redis node after waiting for a second set duration that is not less than a time length required for deleting the virtual IP address.
9. A redis system comprising a plurality of redis, and means for managing virtual IP addresses by the redis according to any of claims 5 to 8 for each of the redis.
CN201710576458.5A 2017-06-13 2017-07-14 Method and device for managing virtual IP address by redis and redis system Active CN107181834B (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN2017104440042 2017-06-13
CN201710444004 2017-06-13

Publications (2)

Publication Number Publication Date
CN107181834A CN107181834A (en) 2017-09-19
CN107181834B true CN107181834B (en) 2021-02-12

Family

ID=59837456

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710576458.5A Active CN107181834B (en) 2017-06-13 2017-07-14 Method and device for managing virtual IP address by redis and redis system

Country Status (1)

Country Link
CN (1) CN107181834B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107895253A (en) * 2017-10-25 2018-04-10 北京科东电力控制系统有限责任公司 A kind of method that electricity transaction function carries out micro services transformation
CN110290163B (en) * 2018-08-28 2022-03-25 新华三技术有限公司 Data processing method and device
CN109446178A (en) * 2018-11-13 2019-03-08 郑州云海信息技术有限公司 A kind of Hadoop object storage high availability method, system, device and readable storage medium storing program for executing
CN110737545B (en) * 2019-09-24 2021-12-17 华青融天(北京)软件股份有限公司 Data processing method and device, electronic equipment and storage medium
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
CN112087336B (en) * 2020-09-11 2022-09-02 杭州海康威视系统技术有限公司 Deployment and management method and device of virtual IP service system and electronic equipment

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102308559A (en) * 2011-07-26 2012-01-04 华为技术有限公司 Voting arbitration method and apparatus for cluster computer system
CN103593266A (en) * 2013-11-12 2014-02-19 浪潮(北京)电子信息产业有限公司 ot standby method based on arbitration disk mechanism
CN103780417A (en) * 2012-10-23 2014-05-07 上海盛大网络发展有限公司 Database failure transfer method based on cloud hard disk and device thereof
CN105069160A (en) * 2015-08-26 2015-11-18 国家电网公司 Autonomous controllable database based high-availability method and architecture
CN105515838A (en) * 2015-11-26 2016-04-20 青岛海信传媒网络技术有限公司 Service configuration method and HA (High Available) cluster system
CN106559267A (en) * 2016-11-25 2017-04-05 聚好看科技股份有限公司 The master-slave switching method of Redis, device and redis systems

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102308559A (en) * 2011-07-26 2012-01-04 华为技术有限公司 Voting arbitration method and apparatus for cluster computer system
CN103780417A (en) * 2012-10-23 2014-05-07 上海盛大网络发展有限公司 Database failure transfer method based on cloud hard disk and device thereof
CN103593266A (en) * 2013-11-12 2014-02-19 浪潮(北京)电子信息产业有限公司 ot standby method based on arbitration disk mechanism
CN105069160A (en) * 2015-08-26 2015-11-18 国家电网公司 Autonomous controllable database based high-availability method and architecture
CN105515838A (en) * 2015-11-26 2016-04-20 青岛海信传媒网络技术有限公司 Service configuration method and HA (High Available) cluster system
CN106559267A (en) * 2016-11-25 2017-04-05 聚好看科技股份有限公司 The master-slave switching method of Redis, device and redis systems

Also Published As

Publication number Publication date
CN107181834A (en) 2017-09-19

Similar Documents

Publication Publication Date Title
CN107181834B (en) Method and device for managing virtual IP address by redis and redis system
US10609159B2 (en) Providing higher workload resiliency in clustered systems based on health heuristics
CN110830283B (en) Fault detection method, device, equipment and system
US11463303B2 (en) Determining the health of other nodes in a same cluster based on physical link information
US9367261B2 (en) Computer system, data management method and data management program
CN109344014B (en) Main/standby switching method and device and communication equipment
US9135097B2 (en) Node death detection by querying
US9348706B2 (en) Maintaining a cluster of virtual machines
CN110535692B (en) Fault processing method and device, computer equipment, storage medium and storage system
US7653769B2 (en) Management of devices connected to infiniband ports
CN106411629B (en) Method and equipment for monitoring state of CDN node
CN109496401B (en) Service takeover method, storage device and service takeover device
US8943191B2 (en) Detection of an unresponsive application in a high availability system
JP5617304B2 (en) Switching device, information processing device, and fault notification control program
US7831686B1 (en) System and method for rapidly ending communication protocol connections in response to node failure
CN109586989B (en) State checking method, device and cluster system
US7676623B2 (en) Management of proprietary devices connected to infiniband ports
CN108512753B (en) Method and device for transmitting messages in cluster file system
US9430341B2 (en) Failover in a data center that includes a multi-density server
WO2017054734A1 (en) Locking file management method and device
CN111342986A (en) Distributed node management method and device, distributed system and storage medium
US20200296607A1 (en) Channel establishment method and base station
CN110752939B (en) Service process fault processing method, notification method and device
WO2017142786A1 (en) Methods for managing array luns in a storage network with a multi-path configuration and devices thereof
CN115145782A (en) Server switching method, mooseFS system and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant