CN107547160A - A kind of method for synchronizing time and device - Google Patents

A kind of method for synchronizing time and device Download PDF

Info

Publication number
CN107547160A
CN107547160A CN201710511525.5A CN201710511525A CN107547160A CN 107547160 A CN107547160 A CN 107547160A CN 201710511525 A CN201710511525 A CN 201710511525A CN 107547160 A CN107547160 A CN 107547160A
Authority
CN
China
Prior art keywords
clock
sts
server
servers
main
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.)
Granted
Application number
CN201710511525.5A
Other languages
Chinese (zh)
Other versions
CN107547160B (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.)
New H3C Technologies Co Ltd
Original Assignee
New H3C Technologies 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 New H3C Technologies Co Ltd filed Critical New H3C Technologies Co Ltd
Priority to CN201710511525.5A priority Critical patent/CN107547160B/en
Publication of CN107547160A publication Critical patent/CN107547160A/en
Application granted granted Critical
Publication of CN107547160B publication Critical patent/CN107547160B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Computer And Data Communications (AREA)

Abstract

The present invention, which provides a kind of method for synchronizing time and device, methods described, to be included:When target STS server initiations are run, determined according to the secure clock of setting and preserve the difference of server security clock and server system clock;When receiving the time synchronized request message that client timing is sent, according to the difference of current server system clock and the server security clock of preservation and server system clock, it is determined that current server security clock;Identified current server security clock is sent to the client, so that the client determines the difference of the rwo according to the local client system clocks of the current server security clock received and the client, and real time client secure clock is determined according to the real time client system clock of the rwo difference and the client.It can avoid specific transactions caused by time synchronized change client local system clock can not normal operation using the embodiment of the present invention.

Description

A kind of method for synchronizing time and device
Technical field
The present invention relates to Internet technical field, more particularly to a kind of method for synchronizing time and device.
Background technology
In Internet technical field, the time is in very important status, many applications pair in Internet technical field The uniformity and accuracy requirement of time is high in the extreme, for example, (Write Once Read Many, once write more for WORM Secondary reading) application of the technology in distributed memory system, being related to the efficient clock system of the timestamp of electronic document is then The key element that WORM technologies are realized.
At present, internet is realized usually using NTP (Network Time Protocol, NTP) agreements In time synchronized, its with GPS (Global Positioning System, global positioning system) time code transmit when Between message be normative reference, employ Client/Server (client/server) structure, there is at a relatively high flexibility.
But practice finds that in above-mentioned Time Synchronizing, NTP clocks can synchronously change local system clock, from And cause the exception of some applications of local system.
The content of the invention
The present invention provides a kind of method for synchronizing time and device, and to solve in existing Time Synchronizing, time synchronized can be more Change local system clock, so as to cause local system is some to apply the problem of abnormal.
First aspect according to embodiments of the present invention, there is provided a kind of method for synchronizing time, applied to targeted security clock system System STS servers, this method include:
When the target STS server initiations are run, server security clock is determined according to the secure clock of setting With the difference of server system clock, and the difference of the server security clock and server system clock is preserved;
When receive client timing send time synchronized request message when, according to current server system clock with And the difference of the server security clock itself preserved and server system clock, it is determined that current server security clock;
Identified current server security clock is sent to the client, so that the client is according to reception To the local client system clocks of the current server security clock and the client determine the difference of the rwo, And real time client secure clock is determined according to the real time client system clock of the rwo difference and the client.
Second aspect according to embodiments of the present invention, there is provided a kind of time synchronism apparatus, applied to targeted security clock system System STS servers, the device include:
First determining unit, it is true according to the secure clock of setting for when the target STS server initiations are run Determine the difference of server security clock and server system clock;
Storage unit, for preserving the difference of the server security clock and server system clock;
Receiving unit, the time synchronized request message sent for receiving client timing;
Second determining unit, for receiving the time synchronized request message of client timing transmission when the receiving unit When, according to the difference of current server system clock and the server security clock itself preserved and server system clock Value, it is determined that current server security clock;
Transmitting element, for identified current server security clock to be sent into the client, so that described Client is true according to the local client system clocks of the current server security clock received and the client The fixed difference of the rwo, and real-time customer is determined according to the real time client system clock of the rwo difference and the client Hold secure clock.
Using the embodiment of the present invention, when target STS server initiations are run, determine to take according to the secure clock of setting The difference of business device secure clock and server system clock, and preserve the difference of the server security clock and server system clock Value;When receiving the time synchronized request message that client timing is sent, according to current server system clock and certainly The difference of the server security clock that body preserves and server system clock, it is determined that current server security clock;By really Fixed current server security clock is sent to client, during so that client is according to the current server security received Clock and the client system clocks of client local determine the difference of the rwo, and according to the rwo difference and the visitor The real time client system clock at family end determines real time client secure clock, avoids time synchronized change client and is locally Uniting specific transactions caused by clock can not normal operation.
Brief description of the drawings
Fig. 1 is a kind of schematic flow sheet of method for synchronizing time provided in an embodiment of the present invention;
Fig. 2 is a kind of configuration diagram of concrete application scene provided in an embodiment of the present invention;
Fig. 3 is a kind of structural representation of time synchronism apparatus provided in an embodiment of the present invention;
Fig. 4 is the structural representation of another time synchronism apparatus provided in an embodiment of the present invention;
Fig. 5 is the structural representation of another time synchronism apparatus provided in an embodiment of the present invention;
Fig. 6 is the structural representation of another time synchronism apparatus provided in an embodiment of the present invention.
Embodiment
In order that those skilled in the art more fully understand the technical scheme in the embodiment of the present invention, and make of the invention real Apply the above-mentioned purpose of example, feature and advantage can be more obvious understandable, below in conjunction with the accompanying drawings to technical side in the embodiment of the present invention Case is described in further detail.
Refer to Fig. 1, be a kind of schematic flow sheet of method for synchronizing time provided in an embodiment of the present invention, wherein, this when Between synchronous method can apply to target STS (Security Time System, secure clock system) server, wherein, STS Server has STS server for operation, as shown in figure 1, the method for synchronizing time may comprise steps of:
Step 101, when target STS server initiations are run, server security is determined according to the secure clock of setting The difference of clock and server system clock, and preserve the difference of the server security clock and server system clock.
In the embodiment of the present invention, when target STS server initiations are run, user (such as STS keepers) can be in mesh Mark and secure clock (referred to herein as server security clock) is set on STS servers.Target STS servers get user and set After the server security clock put, it may be determined that server security clock and the system clock of local (referred to herein as service Device system clock) difference, and preserve the difference of the server security clock and server system clock.
Step 102, when receive client timing send time synchronized request message when, according to current server system The difference of system clock and the server security clock and server system clock that itself preserve, it is determined that current server security Clock.
, it is necessary to which the client for carrying out time synchronized can be sent out by timing to target STS servers in the embodiment of the present invention Time synchronized request message is sent, to obtain secure clock.For example, client can periodically (the specific cycle can be according to reality Scene settings) to target STS servers send time synchronized request message.
When target STS servers receive the time synchronized request message that client timing is sent, target STS servers It can obtain the difference of server security clock and the server system clock of itself preservation, and according to the difference and current Server system clock determines current server security clock.
Step 103, identified current server security clock is sent to client, so that client is according to reception To the local client system clocks of current server security clock and the client determine the difference of the rwo, and root Real time client secure clock is determined according to the real time client system clock of the rwo difference and the client.
In the embodiment of the present invention, target STS servers receive the time synchronized request message of client transmission, and determine During current server security clock, identified server security clock can be sent to client.
, can be according to the server security when client receives the server security clock of target STS servers transmission Clock and the system clock of client local (referred to herein as client system clocks) determine that the rwo (is received The current server security clock client system clocks local with the client) difference, and preserve the difference of the rwo. Hereafter, client can be according to the real time client system clock of itself, and the difference of the rwo itself preserved, it is determined that real When client secure clock.
What deserves to be explained is in embodiments of the present invention, client timing sends time synchronized to target STS servers please Message is sought, to obtain newest server security clock, to ensure the accuracy of secure clock;Client receives target every time During the server security clock that STS servers are sent, it is required for recalculating the server security clock received and client The difference of local client system clocks, and update the difference of the rwo of itself preservation.
It can be seen that in the method flow shown in Fig. 1, after client gets secure clock, this can't be directly changed Ground system clock, but calculate and preserve secure clock and the difference of system clock, and then according to the difference and local system Secure clock corresponding to clock determination, specific transactions caused by avoiding change local system clock can not normal operation.
Further, in the one of embodiment of the present invention, in order to improve scheme reliability, STS can be run to To form distributed STS server clusters in distributed server cluster, above-mentioned target STS servers can be distributed STS Any STS servers in server cluster.
In this embodiment, each STS servers need to carry out main STS Server elections in distributed STS server clusters, To elect main STS servers, and time synchronized service is provided by main STS servers.
Correspondingly, in this embodiment, when target takes the operation of STS server initiations, the above-mentioned safety according to setting Clock determines server security clock with that before the difference of server system clock, can also include:
Target STS servers carry out main STS servers with other STS servers in distributed STS server clusters and selected Lift;
When target STS servers are elected as main STS servers, it is determined that it is true to perform the above-mentioned secure clock according to setting The step of determining the difference of server security clock and server system clock.
In this embodiment, when STS is operated in distributed server cluster, STS keepers only need to take in main STS Secure clock is set on business device.
Correspondingly, when operation has STS distributed server cluster (referred to herein as distributed STS server clusters) just When beginningization is run, need to carry out main STS Server elections between each STS server clusters.After main STS servers are elected, STS keepers can set secure clock on main STS servers.
Wherein, when target STS servers are elected as main STS servers, STS keepers can service in target STS Secure clock is set on device, so as to which target STS servers can be true according to set secure clock and local system clock Determine the difference of server security clock and server system clock.
Further, in this embodiment, due in distributed STS server clusters main STS servers need externally to carry For secure clock, and standby STS servers need not externally provide secure clock, and in order to avoid main STS server exceptions standby STS servers can not learn secure clock value, cause client can not get secure clock again, therefore, main STS servers Need timing that secure clock is saved in into distributed storage cluster, so that main STS server clusters occur abnormal and can not provide During service, remaining standby STS servers re-elect new main STS servers, and the main STS servers newly elected can be from Secure clock value is obtained in distributed storage cluster, and secure clock is externally provided.
Correspondingly, in a kind of optional embodiment of the embodiment, target STS servers take with the distributed STS It is engaged in after other STS servers progress STS Server elections in device cluster, can also includes:
When target STS servers are standby STS servers, and during main STS server exceptions, target STS servers and distribution Other standby STS servers in formula STS server clusters re-elect new main STS servers;
When target STS servers are elected as new main STS servers, target STS servers obtain distributed storage The server security clock preserved in cluster, it is determined that and preserving the difference of the server security clock and server system clock.
In this embodiment, standby STS servers can be taken with timed maintenance and main STS in distributed STS server clusters The heartbeat of business device, to be monitored to main STS server states.
When target STS servers are standby STS servers, and during main STS server exceptions, target STS servers can be with Other standby STS servers in distributed STS server clusters re-elect new main STS servers.
When target STS servers are elected as new main STS servers, target STS servers can be deposited from distribution The server security clock preserved in distributed storage cluster is obtained in accumulation, and according to the secure clock got and originally Ground system clock determines the difference of server security clock and server system clock, preserves the server security clock and service The difference of device system clock, and externally provide secure clock according to the difference.
What deserves to be explained is in embodiments of the present invention, each STS servers use phase in distributed STS server clusters With work IP (Internet Protocol, Internet protocol) address, client can be by the work IP address from master Secure clock is obtained in STS servers.When main STS server exceptions, and standby STS servers re-elect out new main STS clothes During business device, the work IP address of former main STS servers can move to new main STS servers, so as to which client can continue to lead to Cross the work IP address and obtain secure clock from new main STS servers.
Further, in this embodiment, it is main in order to avoid the secure clock preserved in distributed storage cluster is tampered , it is necessary to ensure that secure clock is not repaiied by non-STS keepers when secure clock is saved in distributed storage cluster by STS servers Change.
Correspondingly, it is above-mentioned when target STS servers are elected as leading in a kind of optional embodiment of the embodiment During STS servers, it can also include:
Server security clock is saved in the specified file under the collapse directories of distributed storage cluster by timing;Its In, the filename of the specified file is calculated by the value of set secure clock according to preset algorithm.
In this embodiment, destination server is elected as main STS servers, and STS keepers are in destination server When being above provided with secure clock, destination server can utilize preset algorithm (such as MD5 according to the value of set secure clock (Message Digest Algorithm 5, Message Digest Algorithm 5)) MD5 values are calculated, and secure clock is protected In the presence of the file (referred to herein as specified file) using the MD5 values as filename, and the specified file is saved in distribution and deposited Under the collapse directories of accumulation, so as to ensure that secure clock is not distorted by non-STS keepers.
What deserves to be explained is in this embodiment, the text of the specified file due to preserving secure clock under collapse directories Part name needs to be calculated according to the value of the secure clock of STS keeper's initial setting up, therefore, in order to ensure main STS servers After exception, standby STS servers can calculate the filename of the specified file, and main STS servers are except needing timing will safety Clock is saved in outside the specified file under collapse directories, it is also necessary to the secure clock of initial setting up is saved in into standby STS and serviced The place that device can be got, during so as to main STS server exceptions, the new main STS servers re-elected out can obtain The secure clock of the initial setting up, and according to the value of the secure clock, specified file is calculated using the algorithm consulted in advance Filename.
Further, in this embodiment, when distributed STS server clusters are integrally delayed machine and when restarting, distributed STS Each STS servers need to re-elect new main STS servers in server cluster, and new main STS servers can from point Secure clock is obtained in cloth cluster, and secure clock is externally provided according to the secure clock.
When distributed STS server clusters entirety downtime is long, distributed STS server clusters restart after from point The secure clock got in cloth storage cluster can be larger with actual standard clock jitter, at this time, it may be necessary to the peace got Full clock is calibrated.
Correspondingly, in this embodiment, above-mentioned method for synchronizing time can also include:
When distributed STS server clusters are integrally delayed machine and when restarting, target STS servers and distributed STS servers Other STS servers in cluster re-elect main STS servers;
When target STS servers are elected by main STS servers, the server preserved in distributed storage cluster is obtained Secure clock;
If the server security clock that obtains is earlier than server system clock, every the first preset duration to getting Server security clock adds the second preset duration;
If the server security clock got is obtaining the server security clock earlier than server system clock After 3rd preset duration, the server security clock got is adjusted to consistent with server system clock.
In this embodiment, when distributed STS server clusters are integrally delayed machine and after restart, distributed STS server sets Each STS servers need to re-elect main STS servers in group.
When target STS servers elected by for main STS servers when, target STS servers can obtain distribution and deposit The server security clock preserved in accumulation, and compare the server security clock and local system clock got.
If the server security clock that target STS servers find to get is got earlier than server system clock Secure clock be less than server system clock, then target STS servers can (can be according to reality every the first preset duration Scene settings, such as 1 hour) the second preset duration of server security clock addition got (can be set according to actual scene It is fixed, such as 120 seconds).
For example, using the first preset duration as 1 hour, the second preset duration is exemplified by 120 seconds, it is assumed that target STS servers The server security clock got is 9:00:00, and current server system clock is 9:10:00(9:00:00 earlier than 9: 10:00), then after one hour, server security clock can be adjusted to 10 by target STS servers:02:00 (current service Device system time is 10:10:00) after, then after an hour, server security clock can be adjusted to by target STS servers 11:04:00 (current server system time be 11:10:00), by that analogy, until server security time and server system System time consistency.
If the server security clock that target STS servers find to get is later than server system clock, i.e. server Secure clock is more than server system clock, then target STS servers can be pre- in obtain the server security clock the 3rd If after duration (can be set according to actual scene, such as 1 hour), the server security clock got is adjusted to and serviced Device system clock is consistent.
In a kind of optional embodiment of the embodiment, in above-mentioned destination server and distributed STS server clusters Other STS servers carry out main STS Server elections, can include:
Other STS servers into distributed server cluster send main STS Server elections message, and receive distribution The main STS Server elections message that other STS servers in formula STS server clusters are sent;Wherein, main STS servers choosing Lift the system timestamp that secure clock that message sender gets is carried in message and obtains the secure clock;
It is main STS servers by the earliest STS Server elections of the system timestamp for obtaining secure clock;
When target STS servers determine that the system timestamp for itself getting secure clock is earliest, and receive other STS During the first notification message that server is sent, determine itself to be elected as main STS servers;Wherein, the first notification message is used for Show that message sender agrees to that target STS servers are main STS servers;
When target STS servers determine that the system timestamp for itself getting secure clock is non-earliest, pacify to getting The earliest other STS servers of the system timestamp of full clock send the first notification message.
In this embodiment, when needing to elect main STS servers, for example, distributed STS server clusters initialize Operation or former main STS server exceptions or distributed STS server clusters are integrally delayed when restarting after machine, distributed STS servers Each STS servers (the STS servers of normal operation) can obtain secure clock from distributed storage cluster in cluster, to point Other main STS Server elections message of STS server broadcasts in cloth STS server clusters, and receive distributed STS servers The main STS Server elections message of other STS server broadcasts in cluster;Wherein, carried in the main STS Server elections message There is secure clock that message sender is got and obtain the system timestamp of the secure clock (i.e. message sender is got Local system time during the secure clock).
Wherein, in this embodiment, (peace can be got earliest according to the system timestamp for getting secure clock The value of the system timestamp of full clock is minimum) STS servers carry out main STS servers choosing as the principle of main STS servers Lift, and when the non-earliest STS servers of system timestamp for getting secure clock can be to the system for getting secure clock Between stab earliest STS servers and send and be for agreeing to that this gets the earliest STS servers of the system timestamp of secure clock The notification message (referred to herein as the first notification message) of main STS servers.
Correspondingly, target STS servers receive the master that other STS servers are sent in distributed STS server clusters After STS Server election message, the system timestamp for itself getting secure clock can be compared and received main STS What is carried in Server election message gets the system timestamp of secure clock.
When target STS servers determine that the system timestamp for itself getting secure clock is earliest, and receive other STS During the first notification message that server is sent, target STS servers can determine itself to be elected as main STS servers.
When target STS servers determine that the system timestamp of secure clock that itself gets is non-earliest, target STS clothes Business device can send the first notification message to the earliest other STS servers of the system timestamp for getting secure clock, with table It is bright to agree to that this gets the earliest other STS servers of the system time of secure clock as main STS servers.
As an example it is assumed that distributed STS server clusters include three STS servers (be respectively STS0, STS1 and STS2, wherein STS0 are target STS servers), if the system timestamp that STS0 gets secure clock is 8:00:00, STS1 The system timestamp for getting secure clock is 8:00:10, the STS2 system timestamps for getting secure clock are 8:00:40, Then due to STS0 get secure clock system timestamp earliest (i.e. STS0 gets the value of the system timestamp of secure clock It is minimum), therefore, STS0 is elected as main STS servers.
What deserves to be explained is in embodiments of the present invention, main STS servers are elected in distributed STS server clusters When, the main STS servers can also be broadcasted in distributed STS server clusters for notifying other STS servers to complete The notification message (referred to herein as second notification message) of main STS Server elections, it is other in distributed STS server clusters STS servers are received after second notification message, it may be determined that message sender is main STS servers, and determines that itself is Standby STS servers.
In order that those skilled in the art more fully understand technical scheme provided in an embodiment of the present invention, with reference to specific Application scenarios illustrate to technical scheme provided in an embodiment of the present invention.
Fig. 2 is referred to, is a kind of configuration diagram of concrete application scene provided in an embodiment of the present invention.As shown in Fig. 2 In the application scenarios, Distributed Services cluster includes 3 servers altogether, and operation has STS (to claim respectively in this embodiment For STS0, STS1 and STS2).
Based on application scenarios shown in Fig. 2, the specific implementation flow of Time Synchronizing provided in an embodiment of the present invention is as follows:
1st, during distributed STS server clusters initialization operation, STS0, STS1 and STS2 carry out main STS Server elections;
By taking STS0 sides as an example, other STS servers (i.e. STS1 and STS2) of the STS0 into distributed STS server clusters Broadcast main STS Server elections message, the secure clock that STS0 is got carried in the message, and get this it is safe when The system timestamp (getting the system time during secure clock) of clock.
What deserves to be explained is when distributed STS server clusters are initialized and run, peace that each STS servers are got The initial value of full clock is 0.
Meanwhile STS0 receives the main STS Server elections message that STS1 and STS2 is sent.
STS0 compares the system timestamp for itself getting secure clock and what STS1, STS2 got secure clock is System timestamp, and be main STS servers by the earliest STS servers of the system timestamp for getting secure clock.
In this embodiment it is assumed that STS0 has found that the system timestamp for itself getting secure clock is earliest, and receive The first notification message that STS1 and STS2 is sent, i.e. STS0 are elected as main STS servers.
Wherein, STS0 is elected as after main STS servers, and STS1 and STS2 can keep the timing heart with STS0 respectively Jump, be monitored with the state to STS0.
2nd, STS keepers set secure clock (initial safe clock) on STS0;
3rd, (STS1 and STS2 energy under on the one hand STS0 ensures initial safe clock to a certain particular category of storage cluster The catalogue got), on the other hand, initial safe clock and STS0 system clocks are calculated (during system when secure clock is set Clock) difference, the difference of the secure clock and system clock is preserved, so as to be obtained according to the difference and STS0 system clocks Go out actual time safety clock (server security clock), and secure clock is saved in the finger under the collapse directories of storage cluster by timing Determine in file;Wherein, value of the filename of the specified file by STS0 according to initial safe clock, is calculated using particular algorithm Arrive;
4th, the client for carrying out time synchronized is needed regularly to send time synchronized request message to STS0;STS0 is received During to time synchronization request message, the difference of secure clock and the STS0 system clocks that can be preserved according to itself, and currently STS0 system clocks, current secure clock is calculated, and send it to client;Client receives STS0 transmissions Secure clock, calculate the difference of the secure clock and active client system time, preserve the secure clock and existing customer The difference of end system clock, during so as to which subsequently actual time safety can be calculated according to the difference and real time client system clock Clock (client secure clock);
5th, when STS0 occurs abnormal, STS1 and STS2 re-elect new main STS servers;
In this embodiment it is assumed that STS1 is elected as new main STS servers, now, STS0 work IP can be direct STS1 is moved to, STS1 directly can externally provide secure clock using work IP.
In this embodiment, when STS1 is elected as new main STS servers, STS1 can be obtained just from storage cluster Beginning secure clock, and according to the value of the initial safe clock, specified file is calculated using the particular algorithm consulted in advance Filename, and then, specified file is found from the collapse directories of storage cluster, and obtain the safety preserved in the specified file Clock.
After STS1 gets secure clock, the difference of the secure clock and STS1 system clocks can be calculated, preserving should The difference of secure clock and STS1 system clocks, during to draw actual time safety according to the difference and STS1 real time system clocks Clock, and secure clock is saved in the above-mentioned specified file under the collapse directories of storage cluster by timing.
6th, when distributed STS server clusters are integrally delayed machine and after restart, STS0, STS1 and STS2 re-elect master STS servers.
Assuming that the main STS servers re-elected are STS0, then STS0 can be from the finger under the collapse directories of storage cluster Determine to read secure clock in file.
When STS0 reads secure clock, secure clock and local system clock can be compared;
If the secure clock often spends 1 hour and secure clock is added 120 seconds earlier than local system clock, STS0;
If the secure clock is later than local system clock, a hours of the STS0 after secure clock is got will pacify Full clock is adjusted to consistent with local system clock.
By above description as can be seen that in technical scheme provided in an embodiment of the present invention, at the beginning of target STS servers When beginningization is run, the difference of server security clock and server system clock is determined according to the secure clock of setting, and preserve The difference of the server security clock and server system clock;When the time synchronized request for receiving client timing transmission disappears During breath, according to the difference of current server system clock and the server security clock itself preserved and server system clock Value, it is determined that current server security clock;Identified current server security clock is sent to client, so that objective Family end according to the local client system clocks of the current server security clock received and the client determine this two The difference of person, and real time client safety is determined according to the real time client system clock of the rwo difference and the client Clock, specific transactions caused by avoiding time synchronized change client local system clock can not normal operation.
Fig. 3 is referred to, is a kind of structural representation of time synchronism apparatus provided in an embodiment of the present invention, wherein, it is described The target STS servers that device can apply in above method embodiment, as shown in figure 3, the time synchronism apparatus can wrap Include:
First determining unit 310, for when the target STS server initiations are run, according to setting it is safe when Clock determines the difference of server security clock and server system clock;
Storage unit 320, for preserving the difference of the server security clock and server system clock;
Receiving unit 330, the time synchronized request message sent for receiving client timing;
Second determining unit 340, for receiving the time synchronized request of client timing transmission when the receiving unit During message, according to current server system clock and the server security clock itself preserved and server system clock Difference, it is determined that current server security clock;
Transmitting element 350, for identified current server security clock to be sent into the client, so that institute Client is stated according to the local client system clocks of the current server security clock received and the client The difference of the rwo is determined, and visitor in real time is determined according to the real time client system clock of the rwo difference and the client Family end secure clock.
In an alternative embodiment, the target STS servers are the STS servers in distributed STS server clusters;
Correspondingly, please also refer to Fig. 4, for the structural representation of another time synchronism apparatus provided in an embodiment of the present invention Figure, as shown in figure 4, on the basis of time synchronism apparatus shown in Fig. 3, time synchronism apparatus also includes shown in Fig. 4:
Unit 360 is elected, for carrying out main STS clothes with other STS servers in the distributed STS server clusters Business device election;
First determining unit 310, specifically for when the target STS servers are elected as main STS servers, The difference of server security clock and server system clock is determined according to the secure clock of setting.
In an alternative embodiment, the election unit 360, it is additionally operable to when the target STS servers are that standby STS is serviced Device, and during main STS server exceptions, re-elected newly with other standby STS servers in the distributed STS server clusters Main STS servers;
Correspondingly, please also refer to Fig. 5, for the structural representation of another time synchronism apparatus provided in an embodiment of the present invention Figure, as shown in figure 5, on the basis of time synchronism apparatus shown in Fig. 4, time synchronism apparatus also includes shown in Fig. 5:
First acquisition unit 370, for when the target STS servers are elected as new main STS servers, obtaining The server security clock preserved in distributed storage cluster;
First determining unit 310, it is additionally operable to determine the difference of the server security clock and server system clock;
The storage unit 320, it is additionally operable to preserve the difference of the server security clock and server system clock.
In an alternative embodiment, the storage unit 320, it is additionally operable to when the target STS servers are elected as main STS During server, regularly server security clock is saved in the specified file under the collapse directories of distributed storage cluster;Its In, the filename of the specified file is calculated by the value of set secure clock according to preset algorithm.
In an alternative embodiment, the election unit 360, is additionally operable to when the distributed STS server clusters are integrally delayed Machine and when restarting, main STS servers are re-elected with other STS servers in the distributed STS server clusters;
Correspondingly, please also refer to Fig. 6, for the structural representation of another time synchronism apparatus provided in an embodiment of the present invention Figure, as shown in fig. 6, on the basis of time synchronism apparatus shown in Fig. 4, time synchronism apparatus also includes shown in Fig. 6:
Second acquisition unit 380, for when the target STS servers are elected as main STS servers, described in acquisition The server security clock preserved in distributed storage cluster;
Comparing unit 390, for comparing the server security clock got and server system clock;
Alignment unit 400, if for the server security clock that gets earlier than server system clock, every first Preset duration adds the second preset duration to the server security clock got;If the server security clock got is later than Server system clock, then after the 3rd preset duration of the server security clock is obtained, the server got is pacified Full clock is adjusted to consistent with server system clock.
In an alternative embodiment, the election unit 360, specifically for into the distributed STS server clusters Other STS servers send main STS Server elections message, and receive other STS in the distributed STS server clusters The main STS Server elections message that server is sent;Wherein, message transmission is carried in the main STS Server elections message The secure clock that just gets and the system timestamp for obtaining the secure clock;The system timestamp of secure clock will be obtained most Early STS Server elections are main STS servers;When what the target STS servers determined itself to get secure clock is Timestamp of uniting is earliest, and when receiving the first notification message that other STS servers are sent, determines itself to be elected as main STS Server;Wherein, first notification message is used to show that message sender agrees to that the target STS servers take for main STS Business device;When the target STS servers determine that the system timestamp for itself getting secure clock is non-earliest, pacify to getting The earliest other STS servers of the system timestamp of full clock send the first notification message.
The function of unit and the implementation process of effect specifically refer to and step are corresponded in the above method in said apparatus Implementation process, it will not be repeated here.
For device embodiment, because it corresponds essentially to embodiment of the method, so related part is real referring to method Apply the part explanation of example.Device embodiment described above is only schematical, wherein described be used as separating component The unit of explanation can be or may not be physically separate, can be as the part that unit is shown or can also It is not physical location, you can with positioned at a place, or can also be distributed on multiple NEs.Can be according to reality Need to select some or all of module therein to realize the purpose of the present invention program.Those of ordinary skill in the art are not paying In the case of going out creative work, you can to understand and implement.
As seen from the above-described embodiment, when target STS server initiations are run, determine to take according to the secure clock of setting The difference of business device secure clock and server system clock, and preserve the difference of the server security clock and server system clock Value;When receiving the time synchronized request message that client timing is sent, according to current server system clock and certainly The difference of the server security clock that body preserves and server system clock, it is determined that current server security clock;By really Fixed current server security clock is sent to client, during so that client is according to the current server security received Clock and the client system clocks of client local determine the difference of the rwo, and according to the rwo difference and the visitor The real time client system clock at family end determines real time client secure clock, avoids time synchronized change client and is locally Uniting specific transactions caused by clock can not normal operation.
Those skilled in the art will readily occur to the present invention its after considering specification and putting into practice invention disclosed herein Its embodiment.The application be intended to the present invention any modification, purposes or adaptations, these modifications, purposes or Person's adaptations follow the general principle of the present invention and including undocumented common knowledges in the art of the invention Or conventional techniques.Description and embodiments are considered only as exemplary, and true scope and spirit of the invention are by following Claim is pointed out.
It should be appreciated that the invention is not limited in the precision architecture for being described above and being shown in the drawings, and And various modifications and changes can be being carried out without departing from the scope.The scope of the present invention is only limited by appended claim.

Claims (12)

1. a kind of method for synchronizing time, it is characterised in that applied to targeted security clock system STS servers, this method includes:
When the target STS server initiations are run, server security clock and clothes are determined according to the secure clock of setting The difference of business device system clock, and preserve the difference of the server security clock and server system clock;
When receiving the time synchronized request message that client timing is sent, according to current server system clock and certainly The difference of the server security clock that body preserves and server system clock, it is determined that current server security clock;
Identified current server security clock is sent to the client, so that the client is according to receiving The current server security clock and the client system clocks of client local determine the difference of the rwo, and root Real time client secure clock is determined according to the real time client system clock of the difference of the rwo and the client.
2. according to the method for claim 1, it is characterised in that the target STS servers are distributed STS server sets STS servers in group;
When the target STS server initiations are run, the secure clock according to setting determines server security clock Before the difference of server system clock, in addition to:
Main STS Server elections are carried out with other STS servers in the distributed STS server clusters;
When the target STS servers are elected as main STS servers, it is determined that it is true to perform the secure clock according to setting The step of determining the difference of server security clock and server system clock.
3. according to the method for claim 2, it is characterised in that methods described also includes:
When the target STS servers are standby STS servers, and during main STS server exceptions, serviced with the distributed STS Other standby STS servers in device cluster re-elect new main STS servers;
When the target STS servers are elected as new main STS servers, the clothes preserved in distributed storage cluster are obtained It is engaged in device secure clock, it is determined that and preserving the difference of the server security clock and server system clock.
4. according to the method for claim 2, it is characterised in that when the target STS servers are elected as main STS services During device, methods described also includes:
Server security clock is saved in the specified file under the collapse directories of distributed storage cluster by timing;Wherein, institute The filename for stating specified file is calculated by the value of set secure clock according to preset algorithm.
5. according to the method for claim 2, it is characterised in that methods described also includes:
It is and other in the distributed STS server clusters when the distributed STS server clusters are integrally delayed machine and when restarting STS servers re-elect main STS servers;
When the target STS servers are elected as main STS servers, the clothes preserved in the distributed storage cluster are obtained Business device secure clock;
If the server security clock got is earlier than server system clock, every the first preset duration to the clothes that get Business device secure clock adds the second preset duration;
If the server security clock got is later than server system clock, the 3rd of the server security clock is being obtained After preset duration, the server security clock got is adjusted to consistent with server system clock.
6. according to the method described in claim any one of 2-5, it is characterised in that the destination server and the distribution Other STS servers in STS server clusters carry out main STS Server elections, including:
Other STS servers into the distributed STS server clusters send main STS Server elections message, and receive The main STS Server elections message that other STS servers in the distributed STS server clusters are sent;Wherein, the master When secure clock that message sender gets is carried in STS Server election message and obtaining the system of the secure clock Between stab;
It is main STS servers by the earliest STS Server elections of the system timestamp for obtaining secure clock;
When the target STS servers determine that the system timestamp for itself getting secure clock is earliest, and receive other STS During the first notification message that server is sent, determine itself to be elected as main STS servers;Wherein, first notification message For showing that message sender agrees to that the target STS servers are main STS servers;
When the target STS servers determine that the system timestamp for itself getting secure clock is non-earliest, pacify to getting The earliest other STS servers of the system timestamp of full clock send the first notification message.
7. a kind of time synchronism apparatus, it is characterised in that applied to targeted security clock system STS servers, the device includes:
First determining unit, for when the target STS server initiations are run, determining to take according to the secure clock of setting The difference of business device secure clock and server system clock;
Storage unit, for preserving the difference of the server security clock and server system clock;
Receiving unit, the time synchronized request message sent for receiving client timing;
Second determining unit, for when the receiving unit receive client timing send time synchronized request message when, According to the difference of current server system clock and the server security clock and the server system clock that itself preserve, really Server security clock before settled;
Transmitting element, for identified current server security clock to be sent into the client, so that the client End determines according to the local client system clocks of the current server security clock and the client that receive should Both differences, and determine that real time client is pacified according to the real time client system clock of the rwo difference and the client Full clock.
8. device according to claim 7, it is characterised in that the target STS servers are distributed STS server sets STS servers in group;
Described device also includes:
Unit is elected, is selected for carrying out main STS servers with other STS servers in the distributed STS server clusters Lift;
First determining unit, specifically for when the target STS servers are elected as main STS servers, according to setting The secure clock put determines the difference of server security clock and server system clock.
9. device according to claim 8, it is characterised in that
The election unit, it is standby STS servers to be additionally operable to work as the target STS servers, and during main STS server exceptions, New main STS servers are re-elected with other standby STS servers in the distributed STS server clusters;
Described device also includes:
First acquisition unit, it is distributed for when the target STS servers are elected as new main STS servers, obtaining The server security clock preserved in storage cluster;
First determining unit, it is additionally operable to determine the difference of the server security clock and server system clock;
The storage unit, it is additionally operable to preserve the difference of the server security clock and server system clock.
10. device according to claim 8, it is characterised in that
The storage unit, it is additionally operable to when the target STS servers are elected as main STS servers, regularly by server Secure clock is saved in the specified file under the collapse directories of distributed storage cluster;Wherein, the file of the specified file Name is calculated by the value of set secure clock according to preset algorithm.
11. device according to claim 8, it is characterised in that
The election unit, it is additionally operable to when the distributed STS server clusters are integrally delayed machine and when restarting, with the distribution Other STS servers re-elect main STS servers in STS server clusters;
Described device also includes:
Second acquisition unit, for when the target STS servers are elected as main STS servers, obtaining the distribution The server security clock preserved in storage cluster;
Comparing unit, for comparing the server security clock got and server system clock;
Alignment unit, if for the server security clock that gets earlier than server system clock, when first is default The long server security clock to getting adds the second preset duration;If the server security clock got is later than server System clock, then after the 3rd preset duration of the server security clock is obtained, the server security clock that will get It is adjusted to consistent with server system clock.
12. according to the device described in any one of claim 8~11, it is characterised in that
The election unit, main STS is sent specifically for other STS servers into the distributed STS server clusters Server election message, and receive the main STS services of the transmission of other STS servers in the distributed STS server clusters Device elects message;Wherein, carried in the main STS Server elections message secure clock that message sender gets and Obtain the system timestamp of the secure clock;Based on the earliest STS Server elections of the system timestamp for obtaining secure clock STS servers;When the target STS servers determine that the system timestamp for itself getting secure clock is earliest, and receive During the first notification message that other STS servers are sent, determine itself to be elected as main STS servers;Wherein, described first is logical Know that message is used to show that message sender agrees to that the target STS servers are main STS servers;When the target STS is serviced It is earliest to the system timestamp for getting secure clock when device determines that the system timestamp for itself getting secure clock is non-earliest Other STS servers send the first notification message.
CN201710511525.5A 2017-06-28 2017-06-28 A kind of method for synchronizing time and device Active CN107547160B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710511525.5A CN107547160B (en) 2017-06-28 2017-06-28 A kind of method for synchronizing time and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710511525.5A CN107547160B (en) 2017-06-28 2017-06-28 A kind of method for synchronizing time and device

Publications (2)

Publication Number Publication Date
CN107547160A true CN107547160A (en) 2018-01-05
CN107547160B CN107547160B (en) 2019-06-04

Family

ID=60970964

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710511525.5A Active CN107547160B (en) 2017-06-28 2017-06-28 A kind of method for synchronizing time and device

Country Status (1)

Country Link
CN (1) CN107547160B (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108873668A (en) * 2018-08-30 2018-11-23 新华三技术有限公司 Time calibrating method, processor and time calibration system
CN111107169A (en) * 2020-02-10 2020-05-05 中国人民解放军32021部队 Time management method based on WEB browser
CN111835446A (en) * 2019-04-19 2020-10-27 杭州海康威视数字技术股份有限公司 Method, device and medium for determining master equipment

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1794855A (en) * 2005-06-27 2006-06-28 华为技术有限公司 Method and device synchronous operating time in equipment management
JP2006322788A (en) * 2005-05-18 2006-11-30 Fujitsu General Ltd Time synchronizing system
CN101945243A (en) * 2010-08-16 2011-01-12 中兴通讯股份有限公司 Computing method of safety clock and terminal
CN103841167A (en) * 2012-11-27 2014-06-04 ***通信集团公司 User data synchronizing method and device
CN103905135A (en) * 2012-12-24 2014-07-02 ***通信集团公司 Method, device and system for realizing time synchronization
CN104113386A (en) * 2014-07-09 2014-10-22 北京东土科技股份有限公司 Method and device for monitoring Ethernet clock synchronization
CN106301649A (en) * 2015-06-27 2017-01-04 维布络有限公司 Self-adaptation clock/clock synchronization system and method between equipment in network
CN106603665A (en) * 2016-12-16 2017-04-26 无锡华云数据技术服务有限公司 Cloud platform continuous data synchronization method and cloud platform continuous data synchronization device

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2006322788A (en) * 2005-05-18 2006-11-30 Fujitsu General Ltd Time synchronizing system
CN1794855A (en) * 2005-06-27 2006-06-28 华为技术有限公司 Method and device synchronous operating time in equipment management
CN101945243A (en) * 2010-08-16 2011-01-12 中兴通讯股份有限公司 Computing method of safety clock and terminal
CN103841167A (en) * 2012-11-27 2014-06-04 ***通信集团公司 User data synchronizing method and device
CN103905135A (en) * 2012-12-24 2014-07-02 ***通信集团公司 Method, device and system for realizing time synchronization
CN104113386A (en) * 2014-07-09 2014-10-22 北京东土科技股份有限公司 Method and device for monitoring Ethernet clock synchronization
CN106301649A (en) * 2015-06-27 2017-01-04 维布络有限公司 Self-adaptation clock/clock synchronization system and method between equipment in network
CN106603665A (en) * 2016-12-16 2017-04-26 无锡华云数据技术服务有限公司 Cloud platform continuous data synchronization method and cloud platform continuous data synchronization device

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108873668A (en) * 2018-08-30 2018-11-23 新华三技术有限公司 Time calibrating method, processor and time calibration system
CN111835446A (en) * 2019-04-19 2020-10-27 杭州海康威视数字技术股份有限公司 Method, device and medium for determining master equipment
CN111107169A (en) * 2020-02-10 2020-05-05 中国人民解放军32021部队 Time management method based on WEB browser

Also Published As

Publication number Publication date
CN107547160B (en) 2019-06-04

Similar Documents

Publication Publication Date Title
US11353917B1 (en) Generating globally coherent timestamps
US8169856B2 (en) Time synchronization in cluster systems
EP2378718B1 (en) Method, node and system for controlling version in distributed system
KR101157100B1 (en) Time synchronizing device and process and associated products
KR101109980B1 (en) Facilitating synchronization of servers in a coordinated timing network
JP7098007B2 (en) Remote data synchronization methods and equipment for databases
WO2008092781B1 (en) Defining a stratum-1 configuration in a coordinated timing network
US20100049717A1 (en) Method and systems for sychronization of process control servers
CN109753364A (en) A kind of implementation method, equipment and the medium of network-based distributed lock
US20150026125A1 (en) System and method for synchronizing data between communication devices in a networked environment without a central server
CN110061797A (en) Method for synchronizing time, device, storage medium and computer equipment
CN107547160A (en) A kind of method for synchronizing time and device
CN107947888B (en) A kind of task level synchronous method based on network communication
CN106452648B (en) A kind of method for synchronizing time and communication terminal
CN102231656A (en) Method, system and device for keeping clock synchronization of NTP (Network Time Protocol) server
CN106301953A (en) It is applicable to distributed fault-tolerant clock synchronous method and the system of Time Triggered Ethernet
CN110442591B (en) Global clock system and method of alliance chain
CN108134644B (en) Synchronous method, device, synchronizer and system
CN107786650A (en) A kind of synchronous method, the apparatus and system of storage medium and management strategy
CN105099650B (en) Sync client and its synchronous method and system
CN104993920B (en) A kind of lock in time method and SNTP clients based on SNTP
JP2009008444A (en) Time management server, time management program, and time management method
US7558292B2 (en) Redundant time synchronization
CN104699552B (en) A kind of data reconstruction method and cloud server
Li et al. A high-accuracy clock synchronization method in distributed real-time system

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