CN107087021B - Master-slave server determination method and device - Google Patents

Master-slave server determination method and device Download PDF

Info

Publication number
CN107087021B
CN107087021B CN201710204189.XA CN201710204189A CN107087021B CN 107087021 B CN107087021 B CN 107087021B CN 201710204189 A CN201710204189 A CN 201710204189A CN 107087021 B CN107087021 B CN 107087021B
Authority
CN
China
Prior art keywords
server
database
determining
master
slave
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
CN201710204189.XA
Other languages
Chinese (zh)
Other versions
CN107087021A (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
Priority to CN201710204189.XA priority Critical patent/CN107087021B/en
Publication of CN107087021A publication Critical patent/CN107087021A/en
Application granted granted Critical
Publication of CN107087021B publication Critical patent/CN107087021B/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
    • 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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/16Error detection or correction of the data by redundancy in hardware
    • G06F11/20Error detection or correction of the data by redundancy in hardware using active fault-masking, e.g. by switching out faulty elements or by switching in spare elements
    • G06F11/202Error detection or correction of the data by redundancy in hardware using active fault-masking, e.g. by switching out faulty elements or by switching in spare elements where processing functionality is redundant
    • G06F11/2023Failover techniques
    • G06F11/2033Failover techniques switching over of hardware resources
    • 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
    • H04L67/1001Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers
    • H04L67/1004Server selection for load balancing
    • H04L67/1008Server selection for load balancing based on parameters of servers, e.g. available memory or workload
    • 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
    • H04L67/1001Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers
    • H04L67/1029Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers using data related to the state of servers by a load balancer

Abstract

The embodiment of the invention provides a method and a device for determining a master server and a slave server, wherein the method comprises the following steps: acquiring a first initial score of a first server and a second initial score of a second server, wherein the initial state of the first server is a main server, the first initial score corresponds to the initial state of the first server, the initial state of the second server is a slave server, and the second initial score corresponds to the initial state of the second server; and determining a master server and a slave server in the first server and the second server according to the first initial score, the second initial score, the writability of the first database of the first server, the connection state of the first database and the second database of the second server, the writability of the second database and the state of the second server before the last master-slave server switching. For improving the reliability of the service system.

Description

Master-slave server determination method and device
Technical Field
The embodiment of the invention relates to the technical field of computers, in particular to a master-slave server determining method and device.
Background
At present, in order to improve reliability of providing a service to a client, a plurality of servers are generally provided in a service system, a main server is determined among the plurality of servers, the service is provided to the client by the main server, and the main server can be re-determined after the main server fails.
In an actual application process, a high availability component (MHA) is usually set in a service system, and the MHA monitors each server and switches between the Master server and the slave server, where the MHA includes an MHA management unit and MHA nodes, the MHA management unit is set outside the servers, and the MHA nodes are respectively set in each server. The MHA management unit may monitor the operation state of each server in real time, and if the current master server (first server) is down, the MHA management unit sends a first message to the MHA node in the first server, so that the MHA node in the first server configures the first server as a slave server according to the first message, and also sends a second message to the MHA node in the current slave server (second server), so that the MHA node in the second server configures the second server as the master server according to the second message.
However, when the first server is down due to a temporary network failure, the MHA node in the first server cannot receive the first message, so that the MHA node in the first server cannot configure the first server as a slave server, after the network failure of the first server is automatically recovered, the first server is still not a master server because the configuration of the first server is not changed, and the second server does not have a master server because the configuration of the second server is changed, so that when the first server and the second server provide services to the client at the same time, the service failure provided to the client is caused, and the reliability of the service system is low.
Disclosure of Invention
The embodiment of the invention provides a method and a device for determining a master server and a slave server, which improve the reliability of a service system.
In a first aspect, an embodiment of the present invention provides a method for determining a master server and a slave server, where the method includes:
acquiring a first initial score of a first server, wherein the initial state of the first server is a main server, and the first initial score corresponds to the initial state of the first server;
acquiring a second initial score of a second server, wherein the initial state of the second server is a slave server, and the second initial score corresponds to the initial state of the second server;
acquiring the writability of a first database in the first server and the connection state of the first database and a second database in the second server;
acquiring the writability of the second database and the state of the second server before the last master-slave server switching;
and determining a master server and a slave server in the first server and the second server according to the first initial score, the second initial score, the writability of the first database, the connection state of the first database and the second database, the writability of the second database and the state of the second server before the last master-slave server switching.
In a possible embodiment, determining a master server and a slave server in the first server and the second server according to the first initial score, the second initial score, the writeability of the first database, the connection status of the first database and the second database, the writeability of the second database, and the status of the second server before the last master-slave server switch includes:
determining a first incremental value of a first server according to the writability of the first database and the connection state of the first database and the second database;
determining a second incremental value of the second server according to the writability of the second database and the state of the second server before the last master-slave server switching;
determining a master server and a slave server among the first server and the second server according to the first initial score, the first incremental value, the second initial score, and the second incremental value.
In another possible embodiment, the first initial score is greater than the second initial score by a factor of N;
the maximum value of the second increment value is greater than the maximum value of the first increment value by M minutes, wherein M is greater than N.
In another possible embodiment, determining the first incremental value of the first server according to the writability of the first database and the connection status of the first database and the second database includes:
judging whether the first database is writable or not;
if so, judging whether the first database and the second database are connected, if so, determining that the first added value is divided into a writable added value and a sum of connected added values, and if not, determining that the first added value is divided into the writable added value;
if not, determining that the first increment value is a read-only increment value, wherein the read-only increment value is smaller than the writable increment value.
In another possible embodiment, determining the second incremental value of the second server according to the writeability of the second database and the state of the second server before the last master-slave server switch includes:
judging whether the second database is writable or not;
if so, judging whether the second server is a slave server before the last master-slave server switching, if so, determining that the second added value is divided into a writable added value and a mark added value, and if not, determining that the second added value is divided into the writable added value;
if not, judging whether the second server is a slave server before the last master-slave server switching, if so, determining that the second added value is divided into a read-only added value and the sum of the mark added value, and if not, determining that the second added value is divided into a read-only added value, wherein the read-only added value is smaller than the writable added value.
In another possible embodiment, determining a master server and a slave server among the first server and the second server according to the first initial score, the first incremental value, the second initial score and the second incremental value includes:
determining a first composite score for the first server based on the first initial score and the first incremental value;
determining a second composite score for the second server based on the second initial score and the second incremental value;
determining a master server and a slave server among the first server and the second server according to the first integration score and the second integration score.
In another possible embodiment, after determining the master server and the slave server in the first server and the second server,
setting the database of the master server as writable and setting the database of the slave server as read-only;
and determining the corresponding relation between a preset virtual Internet Protocol (IP) address and the main server so that the client acquires service from the main server through the preset virtual IP address.
In a second aspect, an embodiment of the present invention provides a master-slave server determining apparatus, including a first obtaining module, a second obtaining module, a third obtaining module, a fourth obtaining module, and a first determining module, where,
the first obtaining module is used for obtaining a first initial score of a first server, wherein the initial state of the first server is a main server, and the first initial score corresponds to the initial state of the first server;
the second obtaining module is configured to obtain a second initial score of a second server, where an initial state of the second server is a slave server, and the second initial score corresponds to an initial state of the second server;
the third obtaining module is configured to obtain writeability of a first database in the first server and a connection status between the first database and a second database in the second server;
the fourth obtaining module is configured to obtain the writeability of the second database and a state of the second server before the last master-slave server switching;
the first determining module is configured to determine a master server and a slave server in the first server and the second server according to the first initial score, the second initial score, the writeability of the first database, the connection state between the first database and the second database, the writeability of the second database, and a state of the second server before the last master-slave server switching.
In one possible embodiment, the first determination module comprises a first determination unit, a second determination unit and a third determination unit, wherein,
the first determining unit is used for determining a first incremental value of a first server according to the writability of the first database and the connection state of the first database and the second database;
the second determining unit is configured to determine a second incremental value of the second server according to the writeability of the second database and a state of the second server before the last master-slave server switching;
the third determining unit is configured to determine a master server and a slave server among the first server and the second server according to the first initial score, the first incremental value, the second initial score, and the second incremental value.
In another possible embodiment, the first initial score is greater than the second initial score by a factor of N;
the maximum value of the second increment value is greater than the maximum value of the first increment value by M minutes, wherein M is greater than N.
In another possible implementation manner, the first determining unit is specifically configured to:
judging whether the first database is writable or not;
if so, judging whether the first database and the second database are connected, if so, determining that the first added value is divided into a writable added value and a sum of connected added values, and if not, determining that the first added value is divided into the writable added value;
if not, determining that the first increment value is a read-only increment value, wherein the read-only increment value is smaller than the writable increment value.
In another possible implementation manner, the second determining unit is specifically configured to:
judging whether the second database is writable or not;
if so, judging whether the second server is a slave server before the last master-slave server switching, if so, determining that the second added value is divided into a writable added value and a mark added value, and if not, determining that the second added value is divided into the writable added value;
if not, judging whether the second server is a slave server before the last master-slave server switching, if so, determining that the second added value is divided into a read-only added value and the sum of the mark added value, and if not, determining that the second added value is divided into a read-only added value, wherein the read-only added value is smaller than the writable added value.
In another possible implementation manner, the third determining unit is specifically configured to:
determining a first composite score for the first server based on the first initial score and the first incremental value;
determining a second composite score for the second server based on the second initial score and the second incremental value;
determining a master server and a slave server among the first server and the second server according to the first integration score and the second integration score.
In another possible embodiment, the apparatus further comprises a setting module and a second determining module, wherein,
the setting module is configured to set the database of the master server as writable and set the database of the slave server as read-only after the first determining module determines the master server and the slave server from the first server and the second server;
the second determining module is configured to determine a corresponding relationship between a preset virtual internet protocol IP address and the host server, so that the client obtains a service from the host server through the preset virtual IP address.
In the method for determining the master server and the slave server provided by the embodiment of the invention, in the process that the master server and the slave server are determined in the first server and the second server by the master server and the slave server determining device, the master server and the slave server are determined in the first server and the second server according to the first initial score of the first server, the second initial score of the second server, the writability of the first database, the connection state of the first database and the second database, the writability of the second database and the state of the second server before the last master server and the slave server are switched, so that the master server and the slave server determining device can determine to obtain a unique server in the first server and the second server at the same time, the first server and the second server are prevented from providing services for a client at the same time, and the reliability of a service system is further improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
Fig. 1 is a schematic view of an application scenario of a master-slave server determination method according to an embodiment of the present invention;
fig. 2 is a first flowchart illustrating a master-slave server determining method according to an embodiment of the present invention;
fig. 3 is a flowchart illustrating a secondary server determining method according to an embodiment of the present invention;
fig. 4 is a first schematic structural diagram of a master-slave server determining apparatus according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of a master-slave server determining apparatus according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 is a schematic view of an application scenario of a master-slave server determination method according to an embodiment of the present invention. Referring to fig. 1, the MHA management system includes a server 101, a server 102, an MHA management unit 103, and a master-slave server determination device 104. A database and MHA nodes are provided in the server 101 and the server 102, respectively. In an actual application process, one of the server 101 and the server 102 is a master server, the other server is a slave server, and the MHA node may configure read-write characteristics of a database in the server, specifically, the MHA node configures the database of the master server to be readable and writable so that the master server can provide read-write services to the client, and the MHA node configures the database of the slave server to be read-only so that the slave server can only provide read services to the client.
The MHA management unit 103 may detect the server 101 and the server 102 in real time to determine whether the server 101 and the server 102 operate normally, and the MHA management unit 103 may send a detection result of the server to the MHA node of the server, so that the MHA node processes data in the database according to the detection result of the MHA management unit 103. For example, when MHA management unit 103 detects a failure of server 101, the detection result may be sent to MHA node 1 in server 101, so that MHA node 1 controls synchronization of data in database 1 to database 2.
The master-slave server determining means 104 may determine the composite score of each server based on the current attribute information (e.g., the writeability of the database, etc.) of the server 101 and the server 102, respectively, and determine the master-slave server based on the composite score of the server. Optionally, the master-slave server determining device may be Keepalived software, the Keepalived software may be respectively provided in the server 101 and the server 102, and the Keepalived software in the server 101 may communicate with the Keepalived software in the server 102.
In the application, the comprehensive scores of the first server and the second server can be ensured to be different all the time, so that only one server is taken as a main server at the same time, further, when the first server is failed, the main server is switched from the first server to the second server, when the first server is recovered to be normal, the comprehensive score of the second server can still be ensured to be larger than the comprehensive score of the first server, the situation that the main server is switched to the first server immediately after the first server is recovered to be normal is avoided, the defect that the first server cannot normally provide service for a client side due to the fact that data in a database of the second server cannot be synchronized to the database of the first server in time can be further avoided, and the reliability of a service system is further improved.
The technical means shown in the present application will be described in detail below with reference to specific examples. It should be noted that the following specific embodiments may be combined with each other, and description of the same or similar contents is not repeated in different embodiments.
Fig. 2 is a first flowchart illustrating a master-slave server determining method according to an embodiment of the present invention. Referring to fig. 2, the method may include:
s201, obtaining a first initial score of a first server, wherein the initial state of the first server is a main server, and the first initial score corresponds to the initial state of the first server.
The execution main body of the embodiment of the invention is a master-slave server determining device, the master-slave server determining device can be arranged outside the first server and the second server, and also can be arranged in the first server and/or the second server, when the master-slave server determining device is arranged in the first server and the second server, the master-slave server determining device arranged in the first server and the master-slave server determining device arranged in the second server can be communicated with each other to cooperatively determine the master-slave server. Optionally, the master-slave server determining apparatus may be implemented by software and/or hardware, and when the master-slave server determining apparatus is implemented by software, the master-slave server determining apparatus may be Keepalived software.
S202, acquiring a second initial point of the second server, wherein the initial state of the second server is a slave server, and the second initial point corresponds to the initial state of the second server.
In the embodiment of the present invention, the initial state of the first server is the master server, and the initial state of the second server is the slave server, that is, after the service system starts to operate (for example, power on), the first server is determined as the master server, and the second server is determined as the slave server. During the operation of the service system (including the first server and the second server), the master-slave server determining device may execute the technical solution shown in the embodiment of fig. 2 in real time or periodically to determine the master-slave server in the first server and the second server.
The first initial score of the first server corresponds to the initial state of the first server, the second initial score of the second server corresponds to the initial state of the second server, the first initial score and the second initial score are usually different, optionally, the first initial score is larger than the second initial score by N scores, and the size of N can be set according to actual needs. For example, the first initial score may be 100 scores, and the second initial score may be 90 scores, and of course, in an actual application process, the first initial score and the second initial score may be determined according to actual needs, which is not specifically limited in this embodiment of the present invention.
S203, acquiring the writability of a first database in the first server and the connection state of the first database and a second database in the second server.
In the embodiment of the invention, the database can be read-write or read-only, and the read-write characteristics of the database can be set according to actual requirements in the running process of the database.
The writeability of the first database is used to indicate whether the first database is writable, specifically, when the first server is set as a master server, the first database is set as writable, and when the first server is set as a slave server, the first database is set as read-only. The connection state of the first database and the second database refers to whether the first database and the second database can communicate to realize data synchronization.
And S204, acquiring the writability of the second database and the state of the second server before the last master-slave server switching.
The writability of the second database is used to indicate whether the second database is writable, specifically, when the second server is set as a master server, the second database is set as writable, and when the second server is set as a slave server, the second database is set as read-only. The state of the second server before the last master-slave server switching means that the second server is the master server or the slave server before the last master-slave server switching.
S205, determining a master server and a slave server in the first server and the second server according to the first initial score, the second initial score, the writability of the first database, the connection state of the first database and the second database, the writability of the second database and the state of the second server before the last master-slave server switching.
Optionally, the composite score of the first server may be calculated according to the first initial score, the writability of the first database, and the connection state of the first database and the second database; and calculating the comprehensive score of the second server according to the writability of the second initial score second database and the state of the second server before the last master-slave server switching, determining the server with the high comprehensive score as the master server, and determining the server with the low comprehensive score as the slave server.
In the method for determining the master server and the slave server provided by the embodiment of the invention, in the process that the master server and the slave server are determined in the first server and the second server by the master server and the slave server determining device, the master server and the slave server are determined in the first server and the second server according to the first initial score of the first server, the second initial score of the second server, the writability of the first database, the connection state of the first database and the second database, the writability of the second database and the state of the second server before the last master server and the slave server are switched, so that the master server and the slave server determining device can determine to obtain a unique server in the first server and the second server at the same time, the first server and the second server are prevented from providing services for a client at the same time, and the reliability of a service system is further improved.
Based on the embodiment shown in fig. 2, optionally, the master server and the slave server may be determined in the first server and the second server according to the first initial score, the second initial score, the writeability of the first database, the connection status of the first database and the second database, the writeability of the second database, and the status of the second server before the last master-slave server switch (S205 in the embodiment shown in fig. 2) in a feasible implementation manner, specifically, please refer to the embodiment shown in fig. 3.
Fig. 3 is a flowchart illustrating a secondary server determining method according to an embodiment of the present invention. On the basis of the embodiment shown in fig. 2, referring to fig. 3, the method may include:
s301, determining a first incremental value of the first server according to the writability of the first database and the connection state of the first database and the second database.
Alternatively, the first incremental value of the first server may be determined according to the following feasible implementation:
the master-slave server determining device judges whether the first database is writable or not;
if so, judging whether the first database and the second database are connected, if so, determining that the first added value is divided into a sum of the writable added value and the connection added value, and if not, determining that the first added value is divided into the writable added value;
if not, determining that the first increment is divided into a read-only increment value, wherein the read-only increment value is smaller than a writable increment value.
In the above process, the minimum value of the first increment value is a read-only increment value, and the maximum value of the first increment value is a sum of the writable increment value and the concatenated increment value. For example, the writable increment may be 50 points, the read-only increment may be 40 points, and the connection increment may be 20 points. Of course, in the actual application process, the read-only increment value, the writable increment value and the connection increment value may be set according to actual needs, which is not specifically limited in the embodiment of the present invention.
S302, determining a second incremental value of the second server according to the writability of the second database and the state of the second server before the last master-slave server switching.
Alternatively, the master-slave server determining means may determine the second incremental value of the second server according to the following feasible implementation manners:
the master-slave server determining device judges whether the second database is writable or not;
if yes, judging whether the second server is a slave server before the last master-slave server switching, if yes, determining that the second added value is divided into a writable added value and a mark added value, and if not, determining that the second added value is divided into a writable added value;
if not, judging whether the second server is the slave server before the last master-slave server switching, if so, determining that the second added value is divided into the sum of the read-only added value and the mark added value, and if not, determining that the second added value is divided into the read-only added value, wherein the read-only added value is smaller than the writable added value.
In the above process, the minimum value of the second increment value is a read-only increment value, and the maximum value of the first increment value is a sum of a writable increment value and a mark increment value. It should be noted that the read-only increment value in S302 is the same as the read-only increment value in S301, and the writable increment value in S302 is the same as the writable increment value in S301, which is not described herein again.
And S303, determining a master server and a slave server in the first server and the second server according to the first initial score, the first increment value, the second initial score and the second increment value.
Optionally, a first combined score of the first server may be determined according to the first initial score and the first incremental value, a second combined score of the second server may be determined according to the second initial score and the second incremental value, and the main server may be determined in the first server and the second server according to the first combined score and the second combined score.
For example, the sum of the first initial score and the first added score may be determined as a first composite score, the sum of the second initial score and the second added score may be determined as a second composite score, and a server with a larger composite score may be determined as a master server and a server with a smaller composite score may be determined as a slave server.
In the embodiment of the present invention, when the first server is the main server or after the first server is restarted from a state of the main server, the value of the first incremental value reaches the maximum (the sum of the writable incremental value and the connection incremental value), and when the second server is the main server, the value of the second incremental value reaches the maximum (the sum of the writable incremental value and the flag incremental value). The maximum value of the second increment value (sum of the writable increment value and the flag increment value) is greater than the maximum value of the first increment value (sum of the writable increment value and the connection increment value) by M minutes, and M is greater than N.
After the master-slave server determining device determines to obtain the master-slave server, the master-slave server determining device judges whether the database of the master server is writable or not, and if not, the database of the master server is set to be writable; further, the master-slave server determining means also determines whether the database of the slave server is writable, and sets the database of the slave server to be read-only if it is writable. Further, the master-slave server determining device determines a corresponding relationship between a preset virtual Internet Protocol (IP) address and the master server, so that the client obtains a service from the master server through the virtual IP address.
It should be noted that, when a server is a main server, a downtime occurs to cause switching between a main server and a slave server, and in the downtime process of the server, the server cannot be set (for example, a database in the server is set), and after the server is recovered to be normal, the server is no longer the main server, and the database of the server is still writable, so that it can be determined that the server is a server to be modified, and the database of the server is set to be read only.
In the method for determining the master server and the slave server provided by the embodiment of the invention, in the process that the master server and the slave server are determined in the first server and the second server by the master server and the slave server determining device, the master server and the slave server determining device determine the value added points of the first server and the second server in real time according to the states of the first server and the second server, and determine the master server and the slave server according to the initial points and the value added points of the first server and the second server. In the actual application process, the total score (the sum of the first initial score and the first added score) of the first server is different from the total score (the sum of the second initial score and the second added score) of the second server, so that only one server is taken as a main server at the same time. Further, when the first server is the main server, the first increment score of the first server reaches the maximum, and when the second server is the main server, the second increment score of the second server reaches the maximum. Thus, after the first server is down and restarted, the state of the database of the first server is not reset, so that the first database is still writable, and the first database can be quickly connected with the second database, so that the states of the first database and the second database are also in a connection state, the first incremental value of the first server in a short time after the first server is down and restarted also reaches the maximum value, but the first initial value is larger than the second initial value by N, the second incremental value is larger than the first incremental value by M and is larger than N, so that the second integrated value at the moment can be ensured to be still larger than the first integrated value, the second server can be ensured to be still the main server, and the main server is prevented from being switched to the first server immediately after the first server is recovered to be normal, and then the defect that the first server can not normally provide service for the client due to the fact that the data in the database of the second server can not be synchronized into the database of the first server in time can be avoided, and the reliability of the service system is improved.
The technical solutions shown in the embodiments of the present invention are described in detail below by specific examples.
For example, assume that the first initial score of the first server is 100 points and the second initial score of the second server is 90 points. The writable increment is divided into 50 points, the read-only increment is divided into 40 points, the connection increment is divided into 20 points, and the mark increment is divided into 40 points.
After the first server and the second server are started, the first initial score (100 points) of the first server is larger than the second initial score (90 points) of the second server, so that the first server is set as a master server, the second server is set as a slave server, and correspondingly, the first database of the first server is writable and the second database of the second server is read-only.
And in the normal operation process of the first server and the second server, the states of the first database and the second database are connection states. Since the state of the first database is writable and the states of the first database and the second database are connected, the first increment of the first server is divided into a sum of a writable increment and a connection increment: the 50+20 points are 70 points, and correspondingly, the first comprehensive point of the first server is as follows: 100+70 points to 170 points. At this time, the state of the second database is read-only, and since the first server and the second server are just started and the master-slave server switching has not been performed yet, the second added value of the second server is divided into a read-only added value: and the score is 40, and correspondingly, the second integration of the second server is as follows: and 130 points of 90+ 40. Since the first composite score (170 score) of the first server is greater than the second composite score (130 score) of the second server, it can be determined that the first server is the master server and the second server is the slave server.
After the first server fails (for example, network interruption), the readable and writable state of the first database and the connection state of the first database and the second database cannot be detected, so that the first added value of the first server is determined to be 0 points, and correspondingly, the first comprehensive value of the first server is determined to be 100 points. At this time, since the first composite score (100 points) of the first server is smaller than the second composite score (130 points) of the second server, the second server is determined as the master server and the first server is determined as the slave server.
After the second server is determined to be the master server, the second database of the second server is set to be writable, and since the second server was the slave server before the last master-slave server switch, the increment score of the second server becomes the sum of the writable increment score and the flag increment score: the score of 50+40 is 90, so the second aggregate of the second server is: and 90+50+40 is 180 points.
After the first service is recovered due to failure, because the state of the first database is still in a writable state and the first database can quickly establish connection with the second database, the first composite score of the first database is still 170 scores, at this time, the second composite score (180 scores) of the second server is still greater than the first composite score (170 scores) of the first server, and therefore the second server is still determined to be a master server and the first server is determined to be a slave server. After the master-slave server determining means determines that the first server is the slave server, the master-slave server determining means determines that the first database is writable, and sets the first database to be read-only. After setting the first database to read-only, the first composite score of the first server is 100+40 to 140. At this time, since the first composite score (140 points) of the first server is smaller than the second composite score (180 points) of the second server, it can still be determined that the second server is the master server and the first server is the slave server.
In the above process, it can be ensured that the first integration of the first server is different from the second integration of the second server in any case, so that only one of the first server and the second server is the main server at the same time. Further, after the first server is restarted due to a failure, although the database of the first server is a writable database, the first comprehensive score of the first server is still smaller than the second comprehensive score of the second server, so that the first server is ensured not to be switched between the master server and the slave server after the first server is restarted due to the failure.
It should be further noted that, in the above example, after the first server is recovered, if the user manually sets the second server as the master server and sets the first server as the slave server, the first integration of the first server is divided into: 100 (initial score) +40 (read only increment value) ═ 140 scores, and the second aggregate score for the second server is: 90 (initial score) +50 (writable increment) +20 (ligation increment) ═ 160 scores.
Fig. 4 is a first schematic structural diagram of a master-slave server determining apparatus according to an embodiment of the present invention. Referring to fig. 4, the apparatus may include a first obtaining module 11, a second obtaining module 12, a third obtaining module 13, a fourth obtaining module 14, and a first determining module 15, wherein,
the first obtaining module 11 is configured to obtain a first initial score of a first server, where an initial state of the first server is a main server, and the first initial score corresponds to an initial state of the first server;
the second obtaining module 12 is configured to obtain a second initial point of a second server, where an initial state of the second server is a slave server, and the second initial point corresponds to an initial state of the second server;
the third obtaining module 13 is configured to obtain the writeability of the first database in the first server and the connection status between the first database and the second database in the second server;
the fourth obtaining module 14 is configured to obtain the writeability of the second database and the state of the second server before the last master-slave server switching;
the first determining module 15 is configured to determine a master server and a slave server in the first server and the second server according to the first initial score, the second initial score, the writeability of the first database, the connection status between the first database and the second database, the writeability of the second database, and the status of the second server before the last master-slave server switching.
The master-slave server determining apparatus provided in the embodiment of the present invention may implement the technical solutions shown in the above method embodiments, and the implementation principles and beneficial effects thereof are similar and will not be described herein again.
Fig. 5 is a schematic structural diagram of a master-slave server determining apparatus according to an embodiment of the present invention. On the basis of the embodiment shown in fig. 4, please refer to fig. 5, the first determining module 15 includes a first determining unit 151, a second determining unit 152 and a third determining unit 153, wherein,
the first determining unit 151 is configured to determine a first incremental value of the first server according to the writability of the first database and the connection status of the first database and the second database;
the second determining unit 152 is configured to determine a second incremental value of the second server according to the writeability of the second database and a state of the second server before the last master-slave server switching;
the third determining unit 153 is configured to determine a master server and a slave server in the first server and the second server according to the first initial score, the first incremental value, the second initial score and the second incremental value.
In one possible embodiment, the first initial score is greater than the second initial score by a factor of N;
the maximum value of the second increment value is greater than the maximum value of the first increment value by M minutes, wherein M is greater than N.
In another possible implementation manner, the first determining unit 151 is specifically configured to:
judging whether the first database is writable or not;
if so, judging whether the first database and the second database are connected, if so, determining that the first added value is divided into a writable added value and a sum of connected added values, and if not, determining that the first added value is divided into the writable added value;
if not, determining that the first increment value is a read-only increment value, wherein the read-only increment value is smaller than the writable increment value.
In another possible implementation manner, the second determining unit 152 is specifically configured to:
judging whether the second database is writable or not;
if so, judging whether the second server is a slave server before the last master-slave server switching, if so, determining that the second added value is divided into a writable added value and a mark added value, and if not, determining that the second added value is divided into the writable added value;
if not, judging whether the second server is a slave server before the last master-slave server switching, if so, determining that the second added value is divided into a read-only added value and the sum of the mark added value, and if not, determining that the second added value is divided into a read-only added value, wherein the read-only added value is smaller than the writable added value.
In another possible implementation manner, the third determining unit 153 is specifically configured to:
determining a first composite score for the first server based on the first initial score and the first incremental value;
determining a second composite score for the second server based on the second initial score and the second incremental value;
determining a master server and a slave server among the first server and the second server according to the first integration score and the second integration score.
In another possible embodiment, the apparatus further comprises a setting module 16 and a second determining module 17, wherein,
the setting module 16 is configured to, after the first determining module 15 determines a master server and a slave server among the first server and the second server, set the database of the master server as writable and set the database of the slave server as read-only;
the second determining module 17 is configured to determine a corresponding relationship between a preset virtual internet protocol IP address and the host server, so that the client obtains a service from the host server through the preset virtual IP address.
The master-slave server determining apparatus provided in the embodiment of the present invention may implement the technical solutions shown in the above method embodiments, and the implementation principles and beneficial effects thereof are similar and will not be described herein again.
Those of ordinary skill in the art will understand that: all or a portion of the steps of implementing the above-described method embodiments may be performed by hardware associated with program instructions. The program may be stored in a computer-readable storage medium. When executed, the program performs steps comprising the method embodiments described above; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
Finally, it should be noted that: the above embodiments are only used for illustrating the technical solutions of the embodiments of the present invention, and are not limited thereto; although embodiments of the present invention have been described in detail with reference to the foregoing embodiments, those skilled in the art will understand that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the embodiments of the present invention.

Claims (10)

1. A master-slave server determining method is applied to a master-slave server determining device and comprises the following steps:
acquiring a first initial score of a first server, wherein the initial state of the first server is a main server, and the first initial score corresponds to the initial state of the first server;
acquiring a second initial score of a second server, wherein the initial state of the second server is a slave server, and the second initial score corresponds to the initial state of the second server;
acquiring the writability of a first database in the first server and the connection state of the first database and a second database in the second server;
acquiring the writability of a second database and the state of the second server before the last master-slave server switching;
and determining a master server and a slave server in the first server and the second server according to the first initial score, the second initial score, the writability of the first database, the connection state of the first database and the second database, the writability of the second database and the state of the second server before the last master-slave server switching.
2. The method of claim 1, wherein determining a master server and a slave server in the first server and the second server according to the first initial score, the second initial score, the writability of the first database, the connection status of the first database with the second database, the writability of the second database, and the status of the second server before the last master-slave server switch comprises:
determining a first incremental value of a first server according to the writability of the first database and the connection state of the first database and the second database;
determining a second incremental value of the second server according to the writability of the second database and the state of the second server before the last master-slave server switching;
determining a master server and a slave server among the first server and the second server according to the first initial score, the first incremental value, the second initial score, and the second incremental value.
3. The method of claim 2,
the first initial score is greater than the second initial score by N;
the maximum value of the second increment value is greater than the maximum value of the first increment value by M minutes, wherein M is greater than N.
4. The method of claim 2, wherein determining the first incremental value of the first server based on the writability of the first database and the connection status of the first database to the second database comprises:
judging whether the first database is writable or not;
if so, judging whether the first database and the second database are connected, if so, determining that the first added value is divided into a writable added value and a sum of connected added values, and if not, determining that the first added value is divided into the writable added value;
if not, determining that the first increment value is a read-only increment value, wherein the read-only increment value is smaller than the writable increment value.
5. The method of claim 2, wherein determining the second incremental value of the second server based on the writeability of the second database and the status of the second server prior to the last master-slave server switch comprises:
judging whether the second database is writable or not;
if so, judging whether the second server is a slave server before the last master-slave server switching, if so, determining that the second added value is divided into a writable added value and a mark added value, and if not, determining that the second added value is divided into the writable added value;
if not, judging whether the second server is a slave server before the last master-slave server switching, if so, determining that the second added value is divided into a read-only added value and the sum of the mark added value, and if not, determining that the second added value is divided into a read-only added value, wherein the read-only added value is smaller than the writable added value.
6. The method of any one of claims 2-5, wherein determining a master server and a slave server among the first server and the second server based on the first initial score, the first incremental value, the second initial score, and the second incremental value comprises:
determining a first composite score for the first server based on the first initial score and the first incremental value;
determining a second composite score for the second server based on the second initial score and the second incremental value;
determining a master server and a slave server among the first server and the second server according to the first integration score and the second integration score.
7. The method according to any of claims 1-5, wherein after determining a master server and a slave server in the first server and the second server,
setting the database of the master server as writable and setting the database of the slave server as read-only;
and determining the corresponding relation between a preset virtual Internet Protocol (IP) address and the main server so that the client acquires service from the main server through the preset virtual IP address.
8. A master-slave server determining device is characterized by comprising a first obtaining module, a second obtaining module, a third obtaining module, a fourth obtaining module and a first determining module, wherein,
the first obtaining module is used for obtaining a first initial score of a first server, wherein the initial state of the first server is a main server, and the first initial score corresponds to the initial state of the first server;
the second obtaining module is configured to obtain a second initial score of a second server, where an initial state of the second server is a slave server, and the second initial score corresponds to an initial state of the second server;
the third obtaining module is configured to obtain writeability of a first database in the first server and a connection status between the first database and a second database in the second server;
the fourth obtaining module is configured to obtain the writeability of the second database and a state of the second server before the last master-slave server switching;
the first determining module is configured to determine a master server and a slave server in the first server and the second server according to the first initial score, the second initial score, the writeability of the first database, the connection state between the first database and the second database, the writeability of the second database, and a state of the second server before the last master-slave server switching.
9. The apparatus of claim 8, wherein the first determination module comprises a first determination unit, a second determination unit, and a third determination unit, wherein,
the first determining unit is used for determining a first incremental value of a first server according to the writability of the first database and the connection state of the first database and the second database;
the second determining unit is configured to determine a second incremental value of the second server according to the writeability of the second database and a state of the second server before the last master-slave server switching;
the third determining unit is configured to determine a master server and a slave server among the first server and the second server according to the first initial score, the first incremental value, the second initial score, and the second incremental value.
10. The apparatus of claim 9,
the first initial score is greater than the second initial score by N;
the maximum value of the second increment value is greater than the maximum value of the first increment value by M minutes, wherein M is greater than N.
CN201710204189.XA 2017-03-30 2017-03-30 Master-slave server determination method and device Active CN107087021B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710204189.XA CN107087021B (en) 2017-03-30 2017-03-30 Master-slave server determination method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710204189.XA CN107087021B (en) 2017-03-30 2017-03-30 Master-slave server determination method and device

Publications (2)

Publication Number Publication Date
CN107087021A CN107087021A (en) 2017-08-22
CN107087021B true CN107087021B (en) 2020-10-16

Family

ID=59614913

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710204189.XA Active CN107087021B (en) 2017-03-30 2017-03-30 Master-slave server determination method and device

Country Status (1)

Country Link
CN (1) CN107087021B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109347679A (en) * 2018-11-06 2019-02-15 深圳市风云实业有限公司 Dual master control plate hot standby switch method, apparatus, access gateway and safety network system
CN110445639B (en) * 2019-07-05 2022-07-12 视联动力信息技术股份有限公司 Hot standby method and device for server

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102223250A (en) * 2011-06-14 2011-10-19 上海华创自动化工程有限公司 Method for switching industrial redundancy server
CN104252500A (en) * 2013-06-29 2014-12-31 北京新媒传信科技有限公司 Method and device for carrying out fault repairing on database management platform
CN104570721A (en) * 2014-12-31 2015-04-29 重庆川仪自动化股份有限公司 Master and slave state determining method of redundant controllers
CN105744290A (en) * 2016-01-27 2016-07-06 观止云(北京)信息技术有限公司 HLS hot standby method
CN106301823A (en) * 2015-05-19 2017-01-04 中兴通讯股份有限公司 The fault alarming method of a kind of key component, device and big data management system

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9465698B2 (en) * 2014-03-06 2016-10-11 Software Ag Systems and/or methods for data recovery in distributed, scalable multi-tenant environments

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102223250A (en) * 2011-06-14 2011-10-19 上海华创自动化工程有限公司 Method for switching industrial redundancy server
CN104252500A (en) * 2013-06-29 2014-12-31 北京新媒传信科技有限公司 Method and device for carrying out fault repairing on database management platform
CN104570721A (en) * 2014-12-31 2015-04-29 重庆川仪自动化股份有限公司 Master and slave state determining method of redundant controllers
CN106301823A (en) * 2015-05-19 2017-01-04 中兴通讯股份有限公司 The fault alarming method of a kind of key component, device and big data management system
CN105744290A (en) * 2016-01-27 2016-07-06 观止云(北京)信息技术有限公司 HLS hot standby method

Also Published As

Publication number Publication date
CN107087021A (en) 2017-08-22

Similar Documents

Publication Publication Date Title
CN106331098B (en) Server cluster system
US20220075698A1 (en) Method and Apparatus for Redundancy in Active-Active Cluster System
CN106330475B (en) Method and device for managing main and standby nodes in communication system and high-availability cluster
CN109344014B (en) Main/standby switching method and device and communication equipment
CN109565448B (en) Method, medium, computing unit and system for resolving link failure
CN111259072B (en) Data synchronization method, device, electronic equipment and computer readable storage medium
CN107666493B (en) Database configuration method and equipment thereof
CN109921942B (en) Cloud platform switching control method, device and system and electronic equipment
CN111225401B (en) Method and related equipment for realizing disaster tolerance
CN112769652B (en) Node service monitoring method, device, equipment and medium
CN111752488B (en) Management method and device of storage cluster, management node and storage medium
CN106230954B (en) Virtualization management platform
CN101262479B (en) A network file share method, server and network file share system
CN112527567A (en) System disaster tolerance method, device, equipment and storage medium
WO2017071384A1 (en) Message processing method and apparatus
CN107087021B (en) Master-slave server determination method and device
CN105306566A (en) Method and system for electing master control node in cloud storage system
CN113765690A (en) Cluster switching method, system, device, terminal, server and storage medium
CN111835684B (en) Network isolation monitoring method and system for haproxy equipment
CN109344202B (en) Data synchronization method and management node
US10951732B2 (en) Service processing method and device
CN114124803B (en) Device management method and device, electronic device and storage medium
CN114840495A (en) Database cluster split-brain prevention method, storage medium and device
CN111835544B (en) Monitoring method and system of virtual router based on user mode protocol stack
CN114422335A (en) Communication method, communication device, server 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