CN107547160B - 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
CN107547160B
CN107547160B CN201710511525.5A CN201710511525A CN107547160B CN 107547160 B CN107547160 B CN 107547160B CN 201710511525 A CN201710511525 A CN 201710511525A CN 107547160 B CN107547160 B CN 107547160B
Authority
CN
China
Prior art keywords
server
sts
clock
main
client
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
CN201710511525.5A
Other languages
Chinese (zh)
Other versions
CN107547160A (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 provides a kind of method for synchronizing time and device, which comprises determining according to the secure clock of setting and save the difference of server security clock Yu server system clock when the operation of target STS server initiation;When receiving the time synchronization request message that client is regularly sent, according to the difference of current server system clock and the server security clock of preservation and server system clock, current server security clock is determined;Identified current server security clock is sent to the client, so that the client determines the difference of the rwo according to the client system clocks of the current server security clock and client local that receive, and real time client secure clock is determined according to the real time client system clock of the rwo difference and the client.Specific transactions caused by client local system clock can be changed using the embodiment of the present invention to avoid time synchronization to be unable to operate normally.

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 technique
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 writes more for WORM Secondary reading) application of the technology in distributed memory system, the efficient clock system for being related to the timestamp of electronic document is then The key element that WORM technology is realized.
Currently, realizing internet usually using NTP (Network Time Protocol, Network Time Protocol) agreement In time synchronization, with GPS (Global Positioning System, global positioning system) time code transmission when Between message be reference standard, use Client/Server (client/server) structure, have quite high flexibility.
However practice discovery, in above-mentioned Time Synchronizing, the synchronization of NTP clock can change local system clock, from And lead to the exception of the certain applications of local system.
Summary of the invention
The present invention provides a kind of method for synchronizing time and device, and to solve in existing Time Synchronizing, time synchronization can be more Change local system clock, so as to cause the problem that the certain applications of local system are abnormal.
According to a first aspect of the embodiments of the present invention, a kind of method for synchronizing time is provided, targeted security clock system is applied to System STS server, this method comprises:
When target STS server initiation operation, 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 saved;
When receiving the time synchronization request message that client is regularly sent, according to current server system clock with And the difference of the server security clock and server system clock itself saved, determine current server security clock;
Identified current server security clock is sent to the client, so that the client is according to reception To the current server security clock and the client system clocks of client local determine the rwo difference, And real time client secure clock is determined according to the real time client system clock of the rwo difference and the client.
According to a second aspect of the embodiments of the present invention, a kind of time synchronism apparatus is provided, targeted security clock system is applied to System STS server, the device include:
First determination unit is used for when target STS server initiation operation, true according to the secure clock of setting Determine the difference of server security clock Yu server system clock;
Storage unit, for saving the difference of the server security clock and server system clock;
Receiving unit, the time synchronization request message regularly sent for receiving client;
Second determination unit, for receiving the time synchronization request message that client is regularly sent when the receiving unit When, according to the difference of current server system clock and the server security clock and server system clock that itself save Value, determines current server security clock;
Transmission unit, for identified current server security clock to be sent to the client, so that described Client is true according to the client system clocks of the current server security clock and client local that receive Determine the 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.
It is determined and is taken according to the secure clock of setting when the operation of target STS server initiation using the embodiment of the present invention The difference of business device secure clock and server system clock, and save the difference of the server security clock and server system clock Value;When receiving the time synchronization request message that client is regularly sent, according to current server system clock and certainly The difference of server security clock and server system clock that body saves, determines current server security clock;By really Fixed current server security clock is sent to client, when 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 synchronization change client and is locally Specific transactions caused by system clock are unable to operate normally.
Detailed description of the invention
Fig. 1 is a kind of flow diagram 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 schematic diagram of time synchronism apparatus provided in an embodiment of the present invention;
Fig. 4 is the structural schematic diagram of another time synchronism apparatus provided in an embodiment of the present invention;
Fig. 5 is the structural schematic diagram of another time synchronism apparatus provided in an embodiment of the present invention;
Fig. 6 is the structural schematic diagram of another time synchronism apparatus provided in an embodiment of the present invention.
Specific embodiment
Technical solution in embodiment in order to enable those skilled in the art to better understand the present invention, and make of the invention real The above objects, features, and advantages for applying example can be more obvious and easy to understand, with reference to the accompanying drawing to technical side in the embodiment of the present invention Case is described in further detail.
Referring to Figure 1, be a kind of flow diagram of method for synchronizing time provided in an embodiment of the present invention, wherein this when Between synchronous method can be applied to target STS (Security Time System, secure clock system) server, wherein STS Server is the server that operation has STS, as shown in Figure 1, the method for synchronizing time may comprise steps of:
Step 101, when target STS server initiation operation when, server security is determined according to the secure clock of setting The difference of clock and server system clock, and save the difference of the server security clock and server system clock.
In the embodiment of the present invention, when the operation of target STS server initiation, user (such as STS administrator) can be in mesh It marks and secure clock (referred to herein as server security clock) is set on STS server.Target STS server gets user and sets After the server security clock set, it can determine that server security clock (is referred to herein as serviced with local system clock Device system clock) difference, and save the difference of the server security clock and server system clock.
Step 102, when receiving the time synchronization request message that client is regularly sent, according to current server system The difference of system clock and the server security clock itself saved and server system clock, determines current server security Clock.
In the embodiment of the present invention, the client for needing to carry out time synchronization can be sent out by timing to target STS server Time synchronization request message is sent, to obtain secure clock.For example, client can periodically (the specific period can be according to reality Scene settings) to target STS server sending time synchronization request message.
When target STS server receives the time synchronization request message that client is regularly sent, target STS server The difference of available the server security clock itself saved and server system clock, and according to the difference and currently Server system clock determines current server security clock.
Identified current server security clock is sent to client by step 103, so that client is according to reception To current server security clock and the client system clocks of client local determine the rwo difference, 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 server receives the time synchronization request message of client transmission, and determines When current server security clock, identified server security clock can be sent to client.
It, can be according to the server security when client receives the server security clock of target STS server transmission Clock and the system clock (referred to herein as client system clocks) of client local determine that the rwo (is received The client system clocks of current server security clock and client local) difference, and save the rwo difference. Hereafter, client can determine real according to the real time client system clock of itself and the difference of the rwo itself saved When client secure clock.
It is worth noting that in embodiments of the present invention, client timing is synchronized to target STS server sending time asks Message is sought, to obtain newest server security clock, to guarantee the accuracy of secure clock;Client receives target every time When the server security clock that STS server is sent, require to recalculate the server security clock received and client The difference of local client system clocks, and update the difference of the rwo of itself preservation.
As it can be seen that after client gets secure clock, can't directly change this in method flow shown in Fig. 1 Ground system clock, but the difference of secure clock and system clock is calculated and saves, and then according to the difference and local system Clock determines corresponding secure clock, avoids specific transactions caused by change local system clock and is unable to operate normally.
Further, the present invention in one embodiment, in order to improve scheme reliability, STS can be run to To form distribution STS server cluster in distributed server cluster, above-mentioned target STS server can be distribution STS Any STS server in server cluster.
In this embodiment, each STS server needs to carry out main STS Server election in distributed STS server cluster, To elect main STS server, and time synchronization service is provided by main STS server.
Correspondingly, in this embodiment, when target takes the operation of STS server initiation, the above-mentioned safety according to setting Before clock determines the difference of server security clock and server system clock, can also include:
Other STS servers in target STS server and distribution STS server cluster carry out main STS server and select It lifts;
When target STS server is elected as main STS server, determine that execution is above-mentioned true according to the secure clock of setting The step of determining difference of the server security clock with server system clock.
In this embodiment, when STS is operated in distributed server cluster, STS administrator only needs to take in main STS Secure clock is set on business device.
Correspondingly, when operation has the distributed server cluster (referred to herein as distribution STS server cluster) of STS just When beginningization is run, need to carry out main STS Server election between each STS server cluster.After electing main STS server, Secure clock can be arranged on main STS server in STS administrator.
Wherein, when target STS server is elected as main STS server, STS administrator can service in target STS Secure clock is set on device, thus, target STS server can be true according to set secure clock and local system clock Determine the difference of server security clock Yu server system clock.
Further, in this embodiment, since STS server main in distributed STS server cluster needs externally mention For secure clock, and standby STS server does not need externally to provide secure clock, and in order to avoid main STS server exception standby STS server can not learn secure clock value, cause client that can not get secure clock again, therefore, main STS server Need timing that secure clock is saved in distributed storage cluster, so that main STS server cluster occurs abnormal and can not provide When service, main STS server that remaining standby STS server re-elects new main STS server, and newly elects 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 server and the distribution STS are taken It is engaged in after other STS servers progress STS Server election in device cluster, can also include:
When target STS server is standby STS server, and when main STS server exception, target STS server and distribution Other standby STS servers in formula STS server cluster re-elect new main STS server;
When target STS server is elected as new main STS server, target STS server obtains distributed storage The server security clock saved in cluster determines and saves the difference of the server security clock and server system clock.
In this embodiment, standby STS server can be taken in distributed STS server cluster with timed maintenance and main STS The heartbeat of business device, to be monitored to main STS server state.
When target STS server is standby STS server, and when main STS server exception, target STS server can be with Other standby STS servers in distributed STS server cluster re-elect new main STS server.
When target STS server is elected as new main STS server, target STS server can be deposited from distribution The server security clock saved 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 Yu server system clock, saves the server security clock and service The difference of device system clock, and secure clock is externally provided according to the difference.
It is worth noting that in embodiments of the present invention, each STS server uses phase in distributed STS server cluster With work IP (Internet Protocol, Internet protocol) address, client can be by the work IP address from master Secure clock is obtained in STS server.When main STS server exception, and standby STS server re-elects out new main STS clothes When business device, the work IP address of former main STS server can move to new main STS server, thus, client can continue to lead to It crosses the work IP address and obtains secure clock from new main STS server.
Further, in this embodiment, main in order to avoid the secure clock saved in distributed storage cluster is tampered When secure clock is saved in distributed storage cluster by STS server, need to guarantee that secure clock is not repaired by non-STS administrator Change.
Correspondingly, above-mentioned when target STS server is elected as leading in a kind of optional embodiment of the embodiment When STS server, 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 server, and STS administrator is 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 value is calculated, and secure clock is protected In the presence of using the MD5 value as the file (referred to herein as specified file) of filename, and the specified file is saved in distribution and is deposited Under the collapse directories of accumulation, to guarantee that secure clock is not distorted by non-STS administrator.
It is worth noting that in this embodiment, the text of the specified file due to saving secure clock under collapse directories Part name needs are calculated according to the value of the secure clock of STS administrator's initial setting up, therefore, in order to guarantee main STS server After exception, standby STS server can calculate the filename of the specified file, and main STS server is in addition to needing timing will be safe Clock is saved in except the specified file under collapse directories, it is also necessary to the secure clock of initial setting up are saved in standby STS and serviced The place that device can be got, when so as to main STS server exception, the new main STS server re-elected out can be obtained The secure clock of the initial setting up, and according to the value of the secure clock, specified file is calculated using the algorithm negotiated in advance Filename.
Further, in this embodiment, when distributed STS server cluster entirety delay machine and when restarting, distributed STS Each STS server needs to re-elect new main STS server in server cluster, and new main STS server can from point Secure clock is obtained in cloth cluster, and externally provides secure clock according to the secure clock.
When distributed STS server cluster entirety downtime is too long, distributed STS server cluster 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 cluster entirety delay machine and when restarting, target STS server and distribution STS server Other STS servers in cluster re-elect main STS server;
When target STS server is elected by main STS server, the server saved 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 third preset duration, the server security clock that will acquire is adjusted to consistent with server system clock.
In this embodiment, when distributed STS server cluster entirety delay machine and after restart, distributed STS server set Each STS server needs to re-elect main STS server in group.
When target STS server is elected by for main STS server, the available distribution of target STS server is deposited The server security clock saved in accumulation, and compare the server security clock and local system clock got.
If the server security clock that the discovery of target STS server is got is got earlier than server system clock Secure clock be less than server system clock, then target STS server can (can be according to reality every the first preset duration Scene settings, such as 1 hour) additional second preset duration of the server security clock got (can be set according to actual scene It is fixed, such as 120 seconds).
For example, the second preset duration is for 120 seconds, it is assumed that target STS server with the first preset duration for 1 hour The server security clock got be 9:00:00, and current server system clock be 9:10:00 (9:00:00 is earlier than 9: 10:00), then after one hour, server security clock can be adjusted to 10:02:00 (current service by target STS server Device system time be 10:10:00), then after an hour after, server security clock can be adjusted to by target STS server 11:04:00 (current server system time is 11:10:00), and so on, until server security time and server system System time consistency.
If the server security clock that the discovery of target STS server is got is later than server system clock, i.e. server Secure clock is greater than server system clock, then target STS server can be pre- in the third for obtaining the server security clock If the server security clock that will acquire is adjusted to and services after duration (can be set according to actual scene, such as 1 hour) Device system clock is consistent.
In a kind of optional embodiment of the embodiment, in above-mentioned destination server and distribution STS server cluster Other STS servers carry out main STS Server election, may include:
Other STS servers into distributed server cluster send main STS Server election message, and receive distribution The main STS Server election message that other STS servers in formula STS server cluster are sent;Wherein, main STS server choosing It lifts in message and carries the secure clock and the system timestamp for obtaining the secure clock that message sender is got;
The earliest STS Server election of system timestamp that will acquire secure clock is main STS server;
When target STS server determines that the system timestamp for itself getting secure clock is earliest, and receive other STS When the first notification message that server is sent, determines and itself be elected as main STS server;Wherein, the first notification message is used for Show that message sender agrees to that target STS server is main STS server;
When target STS server determines 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 server, for example, distribution STS server cluster initializes When restarting after operation or former main STS server exception or distribution STS server cluster entirety delay machine, distributed STS server Each STS server (the STS server of normal operation) can obtain secure clock from distributed storage cluster in cluster, to point Other main STS Server election message of STS server broadcast in cloth STS server cluster, and receive distributed STS server The main STS Server election message of other STS server broadcasts in cluster;Wherein, it is carried in the main STS Server election message There is secure clock that message sender is got and obtains the system timestamp of the secure clock (i.e. message sender is got Local system time when 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 server carry out main STS server choosing as the principle of main STS server It lifts, and when the non-earliest STS server of system timestamp for getting secure clock can be to the system for getting secure clock Between stab earliest STS server and send for agreeing to that this gets the earliest STS server of the system timestamp of secure clock and be The notification message (referred to herein as the first notification message) of main STS server.
Correspondingly, target STS server receives the master that other STS servers are sent in distributed STS server cluster 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 server determines that the system timestamp for itself getting secure clock is earliest, and receive other STS When the first notification message that server is sent, target STS server, which can determine, itself is elected as main STS server.
When target STS server determine the secure clock itself got system timestamp it is non-earliest when, 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 server.
As an example it is assumed that include in distribution STS server cluster three STS servers (respectively STS0, STS1 and STS2, wherein STS0 is target STS server), 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, and the system timestamp that STS2 gets secure clock is 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 server.
It is worth noting that in embodiments of the present invention, main STS server is elected in distributed STS server cluster When, which can also broadcast in distributed STS server cluster for notifying other STS servers to be completed The notification message (referred to herein as second notification message) of main STS Server election, it is other in distributed STS server cluster After STS server receives second notification message, it can determine that message sender is main STS server, and determination itself is Standby STS server.
In order to make those skilled in the art more fully understand technical solution provided in an embodiment of the present invention, below with reference to specific Application scenarios are illustrated technical solution 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:
1, when distribution STS server cluster initialization operation, STS0, STS1 and STS2 carry out main STS Server election;
By taking the side STS0 as an example, other STS servers (i.e. STS1 and STS2) of the STS0 into distributed STS server cluster Broadcast main STS Server election 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 when secure clock) of clock.
It is worth noting that when distributed STS server cluster is initialized and run, peace that each STS server is got The initial value of full clock is 0.
Meanwhile STS0 receives the main STS Server election 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 It unites timestamp, and the earliest STS server of the system timestamp that will acquire secure clock is main STS server.
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 server.
Wherein, STS0 is elected as after main STS server, and STS1 and STS2 can keep the timing heart with STS0 respectively It jumps, is monitored with the state to STS0.
2, secure clock (initial safe clock) is arranged in STS administrator on STS0;
3, on the one hand STS0 guarantees initial safe clock to (STS1 and STS2 energy under a certain particular category of storage cluster The catalogue got), on the other hand, initial safe clock and STS0 system clock are calculated (when system when setting secure clock Clock) difference, the difference of the secure clock and system clock is saved, so as to obtain according to the difference and STS0 system clock Actual time safety clock (server security clock) out, and secure clock is saved in the finger under the collapse directories of storage cluster by timing Determine in file;Wherein, the filename of the specified file is calculated by STS0 according to the value of initial safe clock using particular algorithm It arrives;
4, the client for needing to carry out time synchronization can be periodically to STS0 sending time synchronization request message;STS0 is received It, can be and current according to the difference of the secure clock and STS0 system clock that itself save when to time synchronization request message STS0 system clock, current secure clock is calculated, and send it to client;Client receives STS0 transmission Secure clock, calculate the difference of the secure clock Yu active client system time, save the secure clock and existing customer The difference of end system clock, so as to it is subsequent can calculate actual time safety according to the difference and real time client system clock when Clock (client secure clock);
5, when STS0 is abnormal, STS1 and STS2 re-elect new main STS server;
In this embodiment it is assumed that STS1 is elected as new main STS server, at this point, the work IP of STS0 can be direct STS1 is moved to, STS1 directly externally can provide secure clock using work IP.
In this embodiment, when STS1 is elected as new main STS server, 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 negotiated in advance Filename finds specified file in turn from the collapse directories of storage cluster, and obtains the safety saved in the specified file Clock.
After STS1 gets secure clock, the difference of the secure clock Yu STS1 system clock can be calculated, saving should The difference of secure clock and STS1 system clock, when to obtain actual time safety according to the difference and STS1 real time system clock Clock, and secure clock is saved in the above-mentioned specified file under the collapse directories of storage cluster by timing.
6, when distributed STS server cluster entirety delay machine and after restart, STS0, STS1 and STS2 re-elect master STS server.
Assuming that the main STS server re-elected is 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, earlier than local system clock, the every mistake of STS0 1 hour 120 seconds additional to secure clock;
If the secure clock is later than local system clock, a hour of the STS0 after getting secure clock will pacify Full clock is adjusted to consistent with local system clock.
Through above description as can be seen that in technical solution provided in an embodiment of the present invention, at the beginning of target STS server When beginningization is run, the difference of server security clock Yu server system clock is determined according to the secure clock of setting, and save The difference of the server security clock and server system clock;Disappear when receiving the time synchronization request that client is regularly sent When breath, according to the difference of current server system clock and the server security clock and server system clock that itself save Value, determines current server security clock;Identified current server security clock is sent to client, so that objective Family end according to the client system clocks of the current server security clock and client local that receive 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 avoids specific transactions caused by time synchronization change client local system clock and is unable to operate normally.
Fig. 3 is referred to, is a kind of structural schematic diagram of time synchronism apparatus provided in an embodiment of the present invention, wherein described Device can be applied to the target STS server in above method embodiment, as shown in figure 3, the time synchronism apparatus can wrap It includes:
First determination unit 310, for when the target STS server initiation operation when, according to setting it is safe when Clock determines the difference of server security clock Yu server system clock;
Storage unit 320, for saving the difference of the server security clock and server system clock;
Receiving unit 330, the time synchronization request message regularly sent for receiving client;
Second determination unit 340, for receiving the time synchronization request that client is regularly sent when the receiving unit When message, according to current server system clock and the server security clock itself saved and server system clock Difference determines current server security clock;
Transmission unit 350, for identified current server security clock to be sent to the client, so that institute Client is stated according to the current server security clock received and the client system clocks of client local It determines the difference of the rwo, 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 server is the STS server in distribution STS server cluster;
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 shown in Fig. 4 further include:
Unit 360 is elected, for carrying out main STS clothes with other STS servers in the distribution STS server cluster Business device election;
First determination unit 310, specifically for when the target STS server is elected as main STS server, The difference of server security clock Yu server system clock is determined according to the secure clock of setting.
In an alternative embodiment, the election unit 360 is also used to when the target STS server be that standby STS is serviced Device, and when main STS server exception, it is re-elected newly with other standby STS servers in the distribution STS server cluster Main STS server;
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 shown in Fig. 5 further include:
First acquisition unit 370, for obtaining when the target STS server is elected as new main STS server The server security clock saved in distributed storage cluster;
First determination unit 310, is also used to determine the difference of the server security clock and server system clock;
The storage unit 320, is also used to save the difference of the server security clock and server system clock.
In an alternative embodiment, the storage unit 320 is also used to be elected as main STS when the target STS server When server, periodically 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 also used to integrally delay when the distribution STS server cluster Machine and when restarting, re-elects main STS server with other STS servers in the distribution STS server cluster;
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 shown in Fig. 6 further include:
Second acquisition unit 380, for when the target STS server is elected as main STS server, described in acquisition The server security clock saved in distributed storage cluster;
Comparing unit 390, for comparing the server security clock got and server system clock;
Calibration unit 400, if the server security clock for getting earlier than server system clock, every first Preset duration is to additional second preset duration of the server security clock got;If the server security clock got is later than Server system clock, then after the third preset duration for obtaining the server security clock, the server that will acquire is pacified Full clock is adjusted to consistent with server system clock.
In an alternative embodiment, the election unit 360, specifically for into the distribution STS server cluster Other STS servers send main STS Server election message, and receive other STS in the distribution STS server cluster The main STS Server election message that server is sent;Wherein, message transmission is carried in the main STS Server election message The secure clock that just gets and the system timestamp for obtaining the secure clock;It will acquire the system timestamp of secure clock most Early STS Server election is main STS server;When the target STS server determine itself get secure clock be Timestamp of uniting is earliest, and when receiving the first notification message that other STS servers are sent, determines and itself be elected as main STS Server;Wherein, first notification message is for showing that message sender agrees to the target STS server for main STS clothes Business device;When the target STS server determines 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 each unit and the realization process of effect are specifically detailed in the above method and correspond to step in above-mentioned apparatus Realization process, details are not described herein.
For device embodiment, since it corresponds essentially to embodiment of the method, so related place is referring to method reality Apply the part explanation of example.The apparatus embodiments described above are merely exemplary, wherein described be used as separation unit The unit of explanation may or may not be physically separated, and component shown as a unit can be or can also be with It is not physical unit, it can it is in one place, or may be distributed over multiple network units.It can be according to actual The purpose for needing to select some or all of the modules therein to realize the present invention program.Those of ordinary skill in the art are not paying Out in the case where creative work, it can understand and implement.
As seen from the above-described embodiment, it when target STS server initiation is run, is determined and is taken according to the secure clock of setting The difference of business device secure clock and server system clock, and save the difference of the server security clock and server system clock Value;When receiving the time synchronization request message that client is regularly sent, according to current server system clock and certainly The difference of server security clock and server system clock that body saves, determines current server security clock;By really Fixed current server security clock is sent to client, when 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 synchronization change client and is locally Specific transactions caused by system clock are unable to operate normally.
Those skilled in the art after considering the specification and implementing the invention disclosed here, will readily occur to of the invention its Its embodiment.This application is intended to cover any variations, uses, or adaptations of the invention, these modifications, purposes or Person's adaptive change follows general principle of the invention and including the undocumented common knowledge in the art of the present invention Or conventional techniques.The description and examples are only to be considered as illustrative, and true scope and spirit of the invention are by following Claim is pointed out.
It should be understood that the present invention is not limited to the precise structure already described above and shown in the accompanying drawings, and And various modifications and changes may be made without departing from the scope thereof.The scope of the present invention is limited only by the attached claims.

Claims (12)

1. a kind of method for synchronizing time, which is characterized in that it is applied to targeted security clock system STS server, this method comprises:
When target STS server initiation operation, server security clock and clothes are determined according to the secure clock of setting The difference of business device system clock, and save the difference of the server security clock and server system clock;
When receiving the time synchronization request message that client is regularly sent, according to current server system clock and certainly The difference of server security clock and server system clock that body saves, determines 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. the method according to claim 1, wherein the target STS server is distribution STS server set STS server in group;
When target STS server initiation operation, the secure clock according to setting determines server security clock Before the difference of server system clock, further includes:
Main STS Server election is carried out with other STS servers in the distribution STS server cluster;
When the target STS server is elected as main STS server, determine that execution is described true according to the secure clock of setting The step of determining difference of the server security clock with server system clock.
3. according to the method described in claim 2, it is characterized in that, the method also includes:
When the target STS server is standby STS server, and when main STS server exception, with distribution STS service Other standby STS servers in device cluster re-elect new main STS server;
When the target STS server is elected as new main STS server, the clothes saved in distributed storage cluster are obtained Business device secure clock, determines and saves the difference of the server security clock and server system clock.
4. according to the method described in claim 2, it is characterized in that, when the target STS server is elected as main STS service When device, the method 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 described in claim 2, it is characterized in that, the method also includes:
It is and other in the distribution STS server cluster when the distribution STS server cluster entirety delay machine and when restarting STS server re-elects main STS server;
When the target STS server is elected as main STS server, the clothes saved 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 got Additional second preset duration of business device secure clock;
If the server security clock got is later than server system clock, in the third for obtaining the server security clock After preset duration, the server security clock that will acquire is adjusted to consistent with server system clock.
6. according to the described in any item methods of claim 2-5, which is characterized in that the destination server and the distribution Other STS servers in STS server cluster carry out main STS Server election, comprising:
Other STS servers into the distribution STS server cluster send main STS Server election message, and receive The main STS Server election message that other STS servers in the distribution STS server cluster are sent;Wherein, the master When carrying secure clock that message sender is got in STS Server election message and obtaining the system of the secure clock Between stab;
The earliest STS Server election of system timestamp that will acquire secure clock is main STS server;
When the target STS server determines that the system timestamp for itself getting secure clock is earliest, and receive other STS When the first notification message that server is sent, determines and itself be elected as main STS server;Wherein, first notification message For showing that message sender agrees to that the target STS server is main STS server;
When the target STS server determines 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, which is characterized in that be applied to targeted security clock system STS server, which includes:
First determination unit, for being determined and being taken according to the secure clock of setting when target STS server initiation operation The difference of business device secure clock and server system clock;
Storage unit, for saving the difference of the server security clock and server system clock;
Receiving unit, the time synchronization request message regularly sent for receiving client;
Second determination unit, for when the receiving unit receives the time synchronization request message that client is regularly sent, According to the difference of current server system clock and the server security clock and server system clock that itself save, really Server security clock before settled;
Transmission unit, for identified current server security clock to be sent to the client, so that the client End is determined according to the client system clocks of the current server security clock and client local received should The difference of the two, 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, which is characterized in that the target STS server is distribution STS server set STS server in group;
Described device further include:
Unit is elected, is selected for carrying out main STS server with other STS servers in the distribution STS server cluster It lifts;
First determination unit, specifically for when the target STS server is elected as main STS server, according to setting The secure clock set determines the difference of server security clock Yu server system clock.
9. device according to claim 8, which is characterized in that
The election unit is also used to when the target STS server be standby STS server, and when main STS server exception, New main STS server is re-elected with other standby STS servers in the distribution STS server cluster;
Described device further include:
First acquisition unit, it is distributed for obtaining when the target STS server is elected as new main STS server The server security clock saved in storage cluster;
First determination unit, is also used to determine the difference of the server security clock and server system clock;
The storage unit is also used to save the difference of the server security clock and server system clock.
10. device according to claim 8, which is characterized in that
The storage unit is also used to when the target STS server is elected as main STS server, periodically 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, which is characterized in that
The election unit is also used to when the distribution STS server cluster entirety delay machine and when restarting, with the distribution Other STS servers re-elect main STS server in STS server cluster;
Described device further include:
Second acquisition unit, for obtaining the distribution when the target STS server is elected as main STS server The server security clock saved in storage cluster;
Comparing unit, for comparing the server security clock got and server system clock;
Calibration unit, if the server security clock for getting earlier than server system clock, when first is default It is long that second preset duration is added to the server security clock got;If the server security clock got is later than server System clock, then after the third preset duration for obtaining the server security clock, the server security clock that will acquire It is adjusted to consistent with server system clock.
12. according to the described in any item devices of claim 8~11, which is characterized in that
The election unit sends main STS specifically for other STS servers into the distribution STS server cluster Server election message, and receive the main STS service of the transmission of other STS servers in the distribution STS server cluster Device elects message;Wherein, carried in the main STS Server election message secure clock that message sender is got and Obtain the system timestamp of the secure clock;Based on the earliest STS Server election of system timestamp that will acquire secure clock STS server;When the target STS server determines that the system timestamp for itself getting secure clock is earliest, and receive When the first notification message that other STS servers are sent, determines and itself be elected as main STS server;Wherein, described first is logical Know message for showing that message sender agrees to that the target STS server is main STS server;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 CN107547160A (en) 2018-01-05
CN107547160B true 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)

Families Citing this family (3)

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

Citations (6)

* 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
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

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101945243B (en) * 2010-08-16 2014-07-16 中兴通讯股份有限公司 Computing method of safety clock and terminal
CN106603665B (en) * 2016-12-16 2018-04-13 无锡华云数据技术服务有限公司 Cloud platform continuous data synchronous method and its device

Patent Citations (6)

* 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
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

Also Published As

Publication number Publication date
CN107547160A (en) 2018-01-05

Similar Documents

Publication Publication Date Title
US8169856B2 (en) Time synchronization in cluster systems
US11520808B2 (en) System and method for synchronizing data between communication devices in a networked environment without a central server
EP2378718B1 (en) Method, node and system for controlling version in distributed system
EP3490224B1 (en) Data synchronization method and system
US11520753B1 (en) Time reservations for ensuring consistent reads in a distributed database without logging
KR101109980B1 (en) Facilitating synchronization of servers in a coordinated timing network
CA2675644C (en) Facilitating recovery in a coordinated timing network
CN107547160B (en) A kind of method for synchronizing time and device
US9112626B2 (en) Employing configuration information to determine the role of a server in a coordinated timing network
CN105656590A (en) Time synchronization method, device and system
US7669080B2 (en) Reducing likelihood of data loss during failovers in high-availability systems
EP2902940B1 (en) Storage system and method for processing data operation request
CN110061797A (en) Method for synchronizing time, device, storage medium and computer equipment
JP2018510430A (en) Remote data synchronization method and apparatus for database
CN110442591B (en) Global clock system and method of alliance chain
CN107800529B (en) Clock frequency synchronization method of network node
CN107786650B (en) Storage medium and management strategy synchronization method, device and system
WO2016119362A1 (en) Clock synchronization method, router and cluster routing system
CN112769517A (en) T-BOX time synchronization method and device
KR101716583B1 (en) Time synchronization server, system and method
CN107005434B (en) Method, device and equipment for synchronizing Virtual Network Function (VNF) state
KR20150011685A (en) Time synchronization management system using independence type NTP management server
CN104993920B (en) A kind of lock in time method and SNTP clients based on SNTP
CN112019288B (en) Time synchronization method, service single board and network equipment
WO2017157459A1 (en) Configuration management in a communication network

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