Time synchronization method and device

文档序号:1314408 发布日期:2020-07-10 浏览:15次 中文

阅读说明:本技术 一种时间同步方法和装置 (Time synchronization method and device ) 是由 曹瑞 梁顺斌 于 2019-06-05 设计创作,主要内容包括:本公开提供了一种时间同步方法和装置,涉及计算机技术领域。所述方法包括:获取已配置用于获取基准时间的第一网络地址,通过所述虚拟服务器内的动态主机配置服务,将所述第一网络地址路由到第二网络地址,所述第二网络地址为第一物理服务器的网络地址,所述第一物理服务器为被同步时间的服务器,根据所述第二网络地址,向所述第一物理服务器发送第一时间同步请求,接收所述第一物理服务器返回的所述基准时间,根据所述基准时间进行时间同步,从而不需要虚拟服务器通过与其驻留的物理服务器之间打通网络来进行时间同步,保证了虚拟服务器的网络安全,且不会发生驻留服务器时间跳变影响虚拟服务器的情况。(The disclosure provides a time synchronization method and a time synchronization device, and relates to the technical field of computers. The method comprises the following steps: the method comprises the steps of obtaining a first network address configured for obtaining reference time, routing the first network address to a second network address through a dynamic host configuration service in a virtual server, wherein the second network address is the network address of a first physical server, the first physical server is a server of synchronized time, sending a first time synchronization request to the first physical server according to the second network address, receiving the reference time returned by the first physical server, and performing time synchronization according to the reference time, so that the virtual server is not required to perform time synchronization by opening a network with a resident physical server, the network security of the virtual server is ensured, and the condition that the virtual server is influenced by time jump of the resident server is avoided.)

1. A time synchronization method is applied to a virtual server, and comprises the following steps:

acquiring a first network address configured for acquiring a reference time;

routing the first network address to a second network address through a dynamic host configuration service within the virtual server, the second network address being a network address of a first physical server, the first physical server being a server of synchronized time;

sending a first time synchronization request to the first physical server according to the second network address;

and receiving the reference time returned by the first physical server, and performing time synchronization according to the reference time.

2. The method of claim 1, wherein routing the first network address to a second network address through a dynamic host configuration service within the virtual server comprises:

acquiring a configured first routing rule, wherein the first routing rule comprises a corresponding relation between the first network address and the second network address;

and acquiring a second network address corresponding to the first network address from the first routing rule through the dynamic host configuration service.

3. A time synchronization method applied to a first physical server, the method comprising:

creating a network namespace in the first physical server;

configuring a dynamic host configuration server in the network namespace, the dynamic host configuration server being configured to set the network address of the first physical server to a second network address;

configuring a network time protocol server in the name space, and monitoring a request receiving port corresponding to the second network address through the network time protocol server;

when a first time synchronization request sent by a virtual server is monitored, reference time is obtained;

and returning the reference time to the virtual server.

4. The method of claim 3, wherein returning the reference time to the virtual server comprises:

acquiring a configured second routing rule;

acquiring a third network address corresponding to the first network address from the second routing rule through the dynamic host configuration server, wherein the third network address is the network address of the virtual server;

and returning the reference time to the virtual server according to the third network address.

5. The method of claim 3, further comprising:

configuring a network time protocol server and a network time protocol client in the first physical server;

performing time synchronization with a time server via an external network through the network time protocol client;

and performing time synchronization with a second physical server in the first server cluster and a third physical server in the second server cluster through the network time protocol server via an internal network, wherein the second physical server is a redundant server of the first physical server, and the third physical server is a server for providing hardware resources for the virtual server.

6. The method of claim 5, wherein the time synchronization with the time server via the external network by the network time protocol client comprises:

periodically sending, by a network time protocol client, a second time synchronization request to a network time protocol server of the time synchronization server via the external network;

and receiving the reference time returned by the time synchronization server through the external network, and performing time synchronization according to the reference time.

7. The method of claim 5, wherein the time synchronizing with the second physical server of the first cluster of servers and the third physical server of the second cluster of servers via the internal network by the network time protocol server comprises:

receiving, by the network time protocol server, a third time synchronization request sent by a network time protocol client in the second physical server via an internal network, and returning, by the network time protocol server, the reference time to the second physical server;

and receiving a fourth time synchronization request sent by a network time protocol client in the third physical server through an internal network through the network time protocol server, and returning the reference time to the third physical server through the network time protocol server.

8. The method of claim 3, further comprising:

and periodically synchronizing the configuration information of the first physical server to a configuration server, wherein the configuration server is used for selecting a second physical server from the first server cluster when the first physical server fails, and synchronizing the configuration information to the selected second physical server.

9. A time synchronization apparatus applied to a virtual server, the apparatus comprising:

a first acquisition module configured to acquire a first network address configured to acquire a reference time;

a routing module configured to route the first network address to a second network address through a dynamic host configuration service within the virtual server, the second network address being a network address of a first physical server, the first physical server being a server of synchronized time;

a sending module configured to send a first time synchronization request to the first physical server according to the second network address;

and the receiving module is configured to receive the reference time returned by the first physical server and perform time synchronization according to the reference time.

10. The apparatus according to claim 9, wherein the routing module is further configured to obtain a configured first routing rule, where the first routing rule includes a correspondence between the first network address and the second network address; and acquiring a second network address corresponding to the first network address from the first routing rule through the dynamic host configuration service.

11. A time synchronization apparatus applied to a first physical server, the apparatus comprising:

a creation module configured to create a network namespace in the first physical server;

a first configuration module configured to configure a dynamic host configuration server in the network namespace, the dynamic host configuration server to set a network address of the first physical server to a second network address;

the second configuration module is configured to configure a network time protocol server in the namespace, and monitor a request receiving port corresponding to the second network address through the network time protocol server;

the second acquisition module is configured to acquire the reference time when monitoring the first time synchronization request sent by the virtual server;

a return module configured to return the reference time to the virtual server.

12. The apparatus of claim 11, wherein the return module is further configured to obtain a configured second routing rule; acquiring a third network address corresponding to the first network address from the second routing rule through the dynamic host configuration server, wherein the third network address is the network address of the virtual server; and returning the reference time to the virtual server according to the third network address.

13. The apparatus of claim 11, further comprising:

a third configuration module configured to configure a network time protocol server and a network time protocol client in the first physical server;

a first synchronization module configured to perform time synchronization with a time server via an external network through the network time protocol client;

a second synchronization module configured to perform time synchronization with a second physical server in the first server cluster and a third physical server in the second server cluster via the internal network through the network time protocol server, where the second physical server is a redundant server of the first physical server, and the third physical server is a server providing hardware resources for the virtual server.

14. The apparatus of claim 13, wherein the first synchronization module is further configured to periodically send a second time synchronization request to a network time protocol server of the time synchronization servers via the external network through a network time protocol client; and receiving the reference time returned by the time synchronization server through the external network, and performing time synchronization according to the reference time.

15. The apparatus of claim 13, wherein the second synchronization module is further configured to receive, by the network time protocol server, a third time synchronization request sent by a network time protocol client in the second physical server via an internal network, and return, by the network time protocol server, the reference time to the second physical server; and receiving a fourth time synchronization request sent by a network time protocol client in the third physical server through an internal network through the network time protocol server, and returning the reference time to the third physical server through the network time protocol server.

16. The apparatus of claim 11, further comprising:

and the third synchronization module is configured to periodically synchronize configuration information of the first physical server to a configuration server, and the configuration server is used for selecting a second physical server from the first server cluster when the first physical server fails and synchronizing the configuration information to the selected second physical server.

Technical Field

The present disclosure relates to the field of computer technologies, and in particular, to a time synchronization method and apparatus.

Background

The cloud computing platform comprises a physical layer and a virtual layer; the physical layer includes a plurality of physical machines, and the virtual layer includes a plurality of virtual machines. Each virtual machine can process the business in the cloud computing platform through the hardware resources in the physical machine. Because the service generally has timeliness, in order to ensure that the service in the virtual machine operates normally, time synchronization is performed between the virtual machine and the physical machine.

At present, before time synchronization is performed between a virtual machine and a physical machine, the physical machine performs time synchronization with a time server. The virtual machine then time synchronizes with the physical machine. When the virtual machine and the physical machine are time-synchronized, a communication network needs to be established between the virtual machine and the physical machine; the virtual machine acquires time from the physical machine through the communication network, thereby performing time synchronization.

In the method, a communication network between the virtual machine and the physical machine needs to be opened, however, when the communication network between the virtual machine and the physical machine is opened, other devices may intrude into the virtual machine through the communication network, which results in poor network security of the virtual machine.

Disclosure of Invention

The disclosure provides a time synchronization method and a time synchronization device, which are used for solving the problem that when a virtual machine and a physical machine are time synchronized, a communication network between the virtual machine and the physical machine needs to be opened, so that the network security of the virtual machine is poor.

According to a first aspect of the embodiments of the present disclosure, there is provided a time synchronization method applied to a virtual server, the method including:

acquiring a first network address configured for acquiring a reference time;

setting the first network address as a second network address through a dynamic host configuration service in the virtual server, wherein the second network address is a network address of a first physical server, and the first physical server is a server of synchronized time;

sending a first time synchronization request to the first physical server according to the second network address;

and receiving the reference time returned by the first physical server, and performing time synchronization according to the reference time.

In one possible implementation, the routing, by a dynamic host configuration service within the virtual server, the first network address to a second network address includes:

acquiring a configured first routing rule, wherein the first routing rule comprises a corresponding relation between the first network address and the second network address;

and acquiring a second network address corresponding to the first network address from the first routing rule through the dynamic host configuration service.

According to a second aspect of the embodiments of the present disclosure, there is provided a time synchronization method applied to a first physical server, the method including:

creating a network namespace in the first physical server;

configuring a dynamic host configuration server in the network namespace, the dynamic host configuration server being configured to set the network address of the first physical server to a second network address;

configuring a network time protocol server in the name space, and monitoring a request receiving port corresponding to the second network address through the network time protocol server;

when a first time synchronization request sent by a virtual server is monitored, reference time is obtained;

and returning the reference time to the virtual server.

In one possible implementation manner, the returning the reference time to the virtual server includes:

acquiring a configured second routing rule;

acquiring a third network address corresponding to the first network address from the second routing rule through the dynamic host configuration server, wherein the third network address is the network address of the virtual server;

and returning the reference time to the virtual server according to the third network address.

In another possible implementation manner, the method further includes:

configuring a network time protocol server and a network time protocol client in the first physical server;

performing time synchronization with a time server via an external network through the network time protocol client;

and performing time synchronization with a second physical server in the first server cluster and a third physical server in the second server cluster through the network time protocol server via an internal network, wherein the second physical server is a redundant server of the first physical server, and the third physical server is a server for providing hardware resources for the virtual server.

In another possible implementation manner, the time synchronization between the time server and the client through the network time protocol via an external network includes:

periodically sending, by a network time protocol client, a second time synchronization request to a network time protocol server of the time synchronization server via the external network;

and receiving the reference time returned by the time synchronization server through the external network, and performing time synchronization according to the reference time.

In another possible implementation manner, the time synchronization with the second physical server in the first server cluster and the third physical server in the second server cluster through the internal network by the network time protocol server includes:

receiving, by the network time protocol server, a third time synchronization request sent by a network time protocol client in the second physical server via an internal network, and returning, by the network time protocol server, the reference time to the second physical server;

and receiving a fourth time synchronization request sent by a network time protocol client in the third physical server through an internal network through the network time protocol server, and returning the reference time to the third physical server through the network time protocol server.

In another possible implementation manner, the method further includes:

and periodically synchronizing the configuration information of the first physical server to a configuration server, wherein the configuration server is used for selecting a second physical server from the first server cluster when the first physical server fails, and synchronizing the configuration information to the selected second physical server.

According to a third aspect of the embodiments of the present disclosure, there is provided a time synchronization apparatus applied to a virtual server, the apparatus including:

a first acquisition module configured to acquire a first network address configured to acquire a reference time;

a routing module configured to route the first network address to a second network address through a dynamic host configuration service within the virtual server, the second network address being a network address of a first physical server, the first physical server being a server of synchronized time;

a sending module configured to send a first time synchronization request to the first physical server according to the second network address;

and the receiving module is configured to receive the reference time returned by the first physical server and perform time synchronization according to the reference time.

In a possible implementation manner, the routing module is further configured to obtain a configured first routing rule, where the first routing rule includes a correspondence between the first network address and the second network address; and acquiring a second network address corresponding to the first network address from the first routing rule through the dynamic host configuration service.

According to a fourth aspect of the embodiments of the present disclosure, there is provided a time synchronization apparatus applied to a first physical server, the apparatus including:

a creation module configured to create a network namespace in the first physical server;

a first configuration module configured to configure a dynamic host configuration server in the network namespace, the dynamic host configuration server to set a network address of the first physical server to a second network address;

the second configuration module is configured to configure a network time protocol server in the namespace, and monitor a request receiving port corresponding to the second network address through the network time protocol server;

the second acquisition module is configured to acquire the reference time when monitoring the first time synchronization request sent by the virtual server;

a return module configured to return the reference time to the virtual server.

In a possible implementation manner, the return module is further configured to obtain a configured second routing rule; acquiring a third network address corresponding to the first network address from the second routing rule through the dynamic host configuration server, wherein the third network address is the network address of the virtual server; and returning the reference time to the virtual server according to the third network address.

In another possible implementation manner, the apparatus further includes:

a third configuration module configured to configure a network time protocol server and a network time protocol client in the first physical server;

a first synchronization module configured to perform time synchronization with a time server via an external network through the network time protocol client;

a second synchronization module configured to perform time synchronization with a second physical server in the first server cluster and a third physical server in the second server cluster via the internal network through the network time protocol server, where the second physical server is a redundant server of the first physical server, and the third physical server is a server providing hardware resources for the virtual server.

In another possible implementation manner, the first synchronization module is further configured to periodically send a second time synchronization request to a network time protocol server of the time synchronization servers through the external network by the network time protocol client; and receiving the reference time returned by the time synchronization server through the external network, and performing time synchronization according to the reference time.

In another possible implementation manner, the second synchronization module is further configured to receive, by the network time protocol server, a third time synchronization request sent by a network time protocol client in the second physical server via an internal network, and return, by the network time protocol server, the reference time to the second physical server; and receiving a fourth time synchronization request sent by a network time protocol client in the third physical server through an internal network through the network time protocol server, and returning the reference time to the third physical server through the network time protocol server.

In another possible implementation manner, the apparatus further includes:

and the third synchronization module is configured to periodically synchronize configuration information of the first physical server to a configuration server, and the configuration server is used for selecting a second physical server from the first server cluster when the first physical server fails and synchronizing the configuration information to the selected second physical server.

According to a fifth aspect of embodiments of the present disclosure, there is provided a server including:

at least one processor; and

at least one memory;

the at least one memory stores one or more programs configured to be executed by the at least one processor, the one or more programs including instructions for performing the time synchronization method of the first aspect and the time synchronization method of the second aspect.

According to a sixth aspect of the embodiments of the present disclosure, there is provided a computer-readable storage medium applied to the server, wherein at least one instruction, at least one program, a code set, or a set of instructions is stored in the computer-readable storage medium, and the instruction, the program, the code set, or the set of instructions is loaded and executed by a processor to implement the steps in the time synchronization method according to the first aspect and the time synchronization method according to the second aspect.

The technical scheme provided by the embodiment of the disclosure can have the following beneficial effects:

the method comprises the steps of obtaining a first network address configured for obtaining reference time, routing the first network address to a second network address through a dynamic host configuration service in a virtual server, sending a first time synchronization request to a first physical server according to the second network address, receiving the reference time returned by the first physical server, and carrying out time synchronization according to the reference time, wherein the second network address is the network address of the first physical server, and the first physical server is the server of synchronized time. The virtual server sends a time synchronization request to the first network address, the dynamic host configuration service routes the first network address to the second network address, and therefore the first network address reaches the first physical server, the virtual server and the first physical server do not need to be directly connected through a network, network safety of the virtual server is guaranteed, when the first physical server changes, the dynamic host configuration service is modified, configuration of the virtual server does not need to be modified, and efficiency is high.

It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.

Drawings

The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and together with the description, serve to explain the principles of the disclosure.

FIG. 1 is a schematic diagram of an application scenario illustrated in an exemplary embodiment of the present disclosure;

FIG. 2 is a flow chart illustrating a method of time synchronization according to an exemplary embodiment of the present disclosure;

FIG. 3 is a flow chart illustrating another method of time synchronization according to an exemplary embodiment of the present disclosure;

fig. 4 is a signaling interaction diagram illustrating a time synchronization method according to an exemplary embodiment of the present disclosure;

FIG. 5 is a block diagram illustrating a time synchronization apparatus according to an exemplary embodiment of the present disclosure;

fig. 6 is a block diagram illustrating another time synchronization apparatus according to an exemplary embodiment of the present disclosure;

fig. 7 is a block diagram illustrating a server according to an exemplary embodiment of a portion of the present disclosure.

Detailed Description

Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the exemplary embodiments below are not intended to represent all implementations consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure, as detailed in the appended claims.

The present disclosure provides a time synchronization method, and fig. 1 is a schematic diagram of an application scenario shown in an exemplary embodiment of the present disclosure. Referring to fig. 1, the time synchronization method may be applied to a physical server and a virtual server of an OpenStack cluster. The virtual server may be a virtual machine, and the physical server may be a physical machine.

In the embodiment of the present disclosure, a first physical server performs time synchronization with a time server, a second physical server in a first server cluster performs time synchronization with the first physical server, a third physical server in a second server cluster performs time synchronization with the first physical server, and a virtual server in the second server cluster performs time synchronization with the first physical server. For the sake of understanding, the description will be divided into two parts, that is, time synchronization between the virtual server and the physical machine and time synchronization between the physical machines. Before Time synchronization, a physical machine in an OpenStack cluster may be divided into two clusters, where a first server cluster may be an NTP (Network Time Protocol) cluster server, and a second server cluster may be an NTP node server. The NTP cluster server needs to synchronize time through an external network and a time server, and also needs to provide reference time for the NTP node server through an internal network, and the problem of time difference caused by inconsistent synchronization frequency when the NTP node directly synchronizes time with the time server is solved in a mode of isolating the internal network and the external network. The NTP cluster server includes a plurality of physical machines, one of the physical machines is selected as a node for performing time synchronization with an external clock server, other physical machines, and a Virtual server, and may be referred to as a VIP (Virtual IP) node, the other physical machines in the NTP cluster server may be used as redundant nodes of the VIP node, and when the VIP node fails, one of the redundant nodes is selected as a new VIP node.

When time synchronization is performed between the virtual server and the physical machine, the virtual server is actually time-synchronized with the VIP node. The VIP node may create a network name space, which may be a DHCP name space, create a DHCP server and an NTP server in the DHCP name space, and bind a fixed IP (Internet Protocol Address) Address to the DHCP name space through the DHCP server. When creating the virtual server, the virtual server is set up with a static route through option 121 in the DHCP protocol of the DHCP service, which can forward the clock source address of the virtual server to the IP of the DHCP namespace. When the virtual server is started, the clock source address of the virtual server can be dynamically configured through the cloud-init. The virtual server periodically sends a time synchronization request to the clock source address, the time synchronization request can be an NTP message, the NTP server in the DHCP namespace acquires the NTP message sent by the virtual server through a monitoring request port, then responds to the NTP message, returns a response, forwards the response to the IP of the virtual server through the previous route, and the virtual server performs time synchronization according to reference time carried in the returned response.

When time synchronization is carried out between the physical machines, the NTP node server and a non-VIP node in the NTP cluster server periodically send NTP messages to the VIP node, the VIP node responds to the received NTP messages through the NTP server, and the nodes receiving the responses carry out time synchronization according to reference time carried in the responses.

According to the time synchronization method, on one hand, the time difference problem caused by inconsistent synchronization frequency when a physical machine carries out time synchronization is avoided through network isolation, on the other hand, the time synchronization of the virtual server and the VIP node is completed through DHCP service, the network between the virtual server and a host machine does not need to be opened, the safety of the virtual server network is protected, the problem that the virtual server is invaded by the network is avoided, meanwhile, the problem that the service in the virtual server is influenced by the time jump of the host machine when the virtual server and the host machine carry out time synchronization is avoided, and the accuracy of the time synchronization of the virtual server is improved.

Fig. 2 is a flowchart illustrating a time synchronization method according to an exemplary embodiment of the present disclosure, applied to a virtual server, and referring to fig. 2, including the following steps:

in step 201, a first network address configured for acquiring a reference time is acquired.

In step 202, the first network address is routed to a second network address by a dynamic host configuration service within the virtual server, the second network address being a network address of a first physical server, the first physical server being a server of the synchronized time.

In step 203, a first time synchronization request is sent to the first physical server based on the second network address.

In step 204, the reference time returned by the first physical server is received, and time synchronization is performed according to the reference time.

In one possible implementation, routing the first network address to the second network address through a dynamic host configuration service within the virtual server includes:

acquiring a configured first routing rule, wherein the first routing rule comprises a corresponding relation between a first network address and a second network address;

and acquiring a second network address corresponding to the first network address from the first routing rule through the dynamic host configuration service.

In the embodiment of the disclosure, the time synchronization of the virtual server is performed through the dynamic host configuration server, the network connection between the virtual server and the physical server does not need to be opened, the time synchronization request is forwarded through the dynamic host configuration server, the reference time returned by the physical server can be obtained, and the time synchronization can be completed according to the returned reference time.

Fig. 3 is a flowchart illustrating another time synchronization method according to an exemplary embodiment of the present disclosure, applied to a physical server, and referring to fig. 3, including the following steps:

in step 301, a network namespace is created in a first physical server.

In step 302, a dynamic host configuration server is configured in a network namespace, the dynamic host configuration server configured to set a network address of the first physical server to the second network address.

In step 303, a network time protocol server is configured in the network namespace, and a request receiving port corresponding to the second network address is monitored through the network time protocol server.

In step 304, when a first time synchronization request sent by the virtual server is monitored, a reference time is obtained.

In step 305, the reference time is returned to the virtual server.

In one possible implementation, returning the reference time to the virtual server includes:

acquiring a configured second routing rule;

acquiring a third network address corresponding to the first network address from the second routing rule through the dynamic host configuration server, wherein the third network address is the network address of the virtual server;

and returning the reference time to the virtual server according to the third network address.

In another possible implementation manner, the method further includes:

configuring a network time protocol server and a network time protocol client in a first physical server;

performing time synchronization with a time server via an external network through a network time protocol client;

and performing time synchronization with a second physical server in the first server cluster and a third physical server in the second server cluster through the internal network by using the network time protocol server, wherein the second physical server is a redundant server of the first physical server, and the third physical server is a server for providing hardware resources for the virtual server.

In another possible implementation, time synchronization with a time server via an external network by a network time protocol client includes:

periodically sending a second time synchronization request to a network time protocol server of the time synchronization server through the external network by the network time protocol client;

and receiving the reference time returned by the time synchronization server through the external network, and performing time synchronization according to the reference time.

In another possible implementation manner, time synchronization with a second physical server in a first server cluster and a third physical server in a second server cluster through an internal network by a network time protocol server includes:

receiving a third time synchronization request sent by a network time protocol client in the second physical server through the internal network through the network time protocol server, and returning reference time to the second physical server through the network time protocol server;

and receiving a fourth time synchronization request sent by the network time protocol client in the third physical server through the internal network through the network time protocol server, and returning the reference time to the third physical server through the network time protocol server.

In another possible implementation manner, the method further includes:

the configuration information of the first physical server is periodically synchronized to the configuration server, and the configuration server is used for selecting a second physical server from the first server cluster when the first physical server fails and synchronizing the configuration information to the selected second physical server.

In the embodiment of the disclosure, a network namespace is established in a physical server, a dynamic host configuration server is configured in the network namespace to set a network address of the network namespace, a network time protocol server is configured in the network namespace to respond to a time synchronization request of a virtual server, and reference time is returned to the virtual server, so that the virtual server does not need to communicate with the physical server where the virtual server resides to perform time synchronization, the network security of the virtual server is ensured, and the situation that the virtual server is influenced by time jump of the resident server does not occur.

Fig. 4 is a signaling interaction diagram illustrating a time synchronization method according to an exemplary embodiment of the present disclosure.

In step 401, a first physical server configures a network time protocol client by which the client and a time server perform time synchronization via an external network.

The first physical server is provided with a network time protocol client, and the network time protocol client can be an NTP client. The first physical server can set the IP of the first physical server and the IP of the time server to be the IP of the same network segment, so that the first physical server can perform time synchronization with the time server through the NTP client.

When the first physical server and the time server are time-synchronizing, the first physical server sends a second time synchronization request to the time server to request time synchronization with the time server. The time server is provided with an NTP server, the first physical server sends a second time synchronization request to the NTP server arranged on the time server through an external network, the NTP server arranged on the time server responds to the second time synchronization request, the NTP server returns reference time to the first physical server through the external network through response information, and the first physical server carries out time synchronization according to the returned reference time.

Wherein the first physical server may periodically time synchronize with the time server. The external network may be the internet, i.e., a network that can communicate with a public network. The second time synchronization request may be an NTP message, and the response information may also be an NTP message. The time server is a server with reference time, and can be a time service provider or a standard time server.

It should be noted that, the first physical server inevitably fails, and in order to ensure normal operation of time synchronization, when the first physical server fails, one server may be selected from the redundant servers of the first physical server to replace the first physical server. In order to ensure that the newly selected server can provide the time synchronization server, the configuration information of the first physical server can be periodically synchronized to the configuration server, and the configuration server is used for selecting a second physical server from the first server cluster when the first physical server fails and synchronizing the configuration information to the selected second physical server. The configuration service may detect whether the first physical server fails through a Keep Alive mechanism.

In step 402, a network time protocol server is configured in the first physical server, and time synchronization is performed with a second physical server in the first server cluster and a third physical server in the second server cluster via the internal network.

Wherein, the network time server can be an NTP server. Accordingly, this step can be realized by the following steps (1) to (2), including:

(1) the first physical server is configured with a network time protocol server, and performs time synchronization with a second physical server in the first server cluster through an internal network.

The first server cluster may be the NTP cluster server, the NTP cluster server includes a plurality of second physical servers, each second physical server may be configured with an NTP client, the second physical server sends a third time synchronization request to the first physical server through the NTP client via an internal network, the first physical server receives the third time synchronization request through the NTP server, the first physical server returns a response message through the NTP server, the response message carries a reference time, and the second physical server performs time synchronization with the reference time after receiving the reference time in the response message.

The internal network may be a local area network, that is, a network that does not interwork with a public network. The third time synchronization request may be an NTP message, and the response information may also be an NTP message.

(2) And configuring a network time protocol server in the first physical server, and carrying out time synchronization with a third physical server in the second server cluster through the internal network.

The second server cluster may be the NTP node server, where the NTP node server includes a plurality of third physical servers, each third physical server may be configured with an NTP client, the third physical server sends a fourth time synchronization request to the first physical server through the internal network via the NTP client, the first physical server receives the fourth time synchronization request through the NTP server, the first physical server returns a response message through the NTP server, the response message carries a reference time, and the third physical server performs time synchronization with the reference time after receiving the reference time in the response message.

The internal network may be a local area network, that is, a network that does not interwork with a public network. The fourth time synchronization request may be an NTP message, and the response information may also be an NTP message. The third physical server is used for providing hardware resources for the virtual server.

In step 403, the first physical server creates a network namespace within the first physical server.

The first physical server may be configured with a network namespace, which may be a DHCP namespace, for time synchronization with the virtual machine. The DHCP server may obtain a time of the first physical server through a time obtaining function or a time obtaining service, where the time of the first physical server is a reference time after the time server performs synchronization.

In step 404, the first physical server configures a dynamic host configuration server in a network namespace.

The first physical server may configure a DHCP server in a DHCP namespace, the DHCP server to set a network address of the first physical server to a second network address, the second network address to time synchronize with the virtual server. The second network address is bound to the DHCP namespace, i.e., the second network address may also be considered as the network address of the DHCP namespace.

In step 405, the first physical server configures a network time protocol server in the namespace, and monitors a request receiving port corresponding to the second network address through the network time protocol server.

The first physical server may configure an NTP server in a DHCP namespace, the NTP server configured to listen on a request receiving port, which may be 123 ports. The request may be a time synchronization request, and the NTP server may respond to listening for the time synchronization request.

It should be noted that, the virtual network card in the DHCP namespace of the first physical server may set two IP addresses, one of the IP addresses is the second network address, the other IP address is the same network address as the first network address, that is, the virtual server sends the time synchronization request to the first network address, and routes the time synchronization request to the second network address through the first routing rule, the virtual network card of the second network address is bound with a network address which is the same as the first network address, so that the first network address does not have a one-to-one correspondence relationship with the second network address in practice, namely, after the first physical server is damaged, the newly configured physical server only needs to configure the virtual network card where the second network address is located with a first network address, that is, time synchronization requests sent by the virtual server can be received without modifying the configuration file of the NTP service in the namespace. Simple and convenient, good operability and high efficiency.

In step 406, the virtual server obtains a first network address that has been configured for obtaining the reference time.

The virtual server can periodically send a time synchronization request to acquire reference time to complete time synchronization, the virtual server acquires a configured first network address before sending the time synchronization request, and the virtual server can send an NTP message to the first network address through the NTP client to ask for the reference time.

The first network address may be a clock source address configured for the virtual server, may be set as a static address, and may also be injected through a script when the virtual server is started, so as to dynamically modify the clock source address.

In step 407, the virtual server routes the first network address to the second network address through the dynamic host configuration service.

The virtual server may obtain a configured first routing rule, which may be a static route set for the virtual server by the virtual server through an option 121 in the DHCP protocol in the DHCP service, the static route being used for routing the first network address to the second network address. The first routing rule may be stored in a DHCP service, and includes a correspondence between a first network address and a second network address, and the DHCP service may obtain the second network address corresponding to the first network address from the first routing rule.

For example, the first network address, i.e. the clock source address of the virtual server is 169.254.169.254, the second network address of the DHCP namespace is 10.33.46.62, and the static route set for the virtual server may be 169.254.169.254via 10.33.46.62 deveth 0 protostatic.

In step 408, the virtual server sends a first time synchronization request to the first physical server based on the second network address.

An NTP client in the virtual server can periodically send an NTP message to a first network address to ask for reference time, and the DHCP service forwards the NTP message sent to the first network address to a second network address, namely forwards the NTP message to a DHCP namespace of a first physical server according to the second network address.

In step 409, when the first physical server monitors the first time synchronization request sent by the virtual server, a reference time is obtained.

When the NTP server in the DHCP namespace of the first physical server monitors the first time synchronization request sent by the virtual server, the DHCP namespace may obtain the current time of the first physical server through a time obtaining function, and the time is used as the reference time.

In step 410, the first physical server returns the reference time to the virtual server.

The first physical server may obtain a configured second routing rule, where the second routing rule may be a static route, and is stored in a DHCP service, and may obtain, through the DHCP server, a third network address corresponding to the first network address from the second routing rule, where the third network address is a network address of the virtual server. The second network address of the namespace of the first physical server and the third network address of the virtual server are in the same network segment, when the virtual server communicates with the namespace of the first physical server for the first time, the first physical server can obtain the third network address of the virtual server through an Address Resolution Protocol (ARP), cache the third network address, and directly obtain the third network of the virtual server according to the second routing rule during subsequent time synchronization.

The first physical server may return response information through the NTP server in the DHCP namespace, where the response information carries the reference time.

In step 411, the virtual server receives the reference time returned by the first physical server, and performs time synchronization according to the reference time.

And the virtual server receives the response information returned by the first physical server, analyzes the response information to obtain the reference time carried in the corresponding information, and performs time synchronization according to the reference time.

In the disclosed embodiment, the first physical server and the time server are time-synchronized through an external network, the second physical server, the third physical server and the first physical server are time-synchronized through an internal network, the problem of time difference caused by inconsistent frequency of physical server synchronization is avoided through network isolation, meanwhile, a network name space is established in the first physical server, a dynamic host configuration server is configured in the network name space to set a network address of the network name space, a network time protocol server is configured in the network name space to respond to a time synchronization request of a virtual server, reference time is returned to the virtual server, the network connection between the virtual server and a resident physical server is not required to be opened, and the time synchronization request is forwarded through the dynamic host configuration server, the reference time returned by the first physical server can be obtained, and the time synchronization can be completed according to the returned reference time.

Fig. 5 is a block diagram illustrating a time synchronization apparatus according to an exemplary embodiment of the present disclosure. Applied to a virtual server, the device comprises: a first obtaining module 501, a routing module 502, a sending module 503 and a receiving module 504.

A first obtaining module 501 configured to obtain a first network address configured to obtain a reference time;

a routing module 502 configured to route the first network address to a second network address through a dynamic host configuration service within the virtual server, the second network address being a network address of a first physical server, the first physical server being a server of the synchronized time;

a sending module 503 configured to send a first time synchronization request to the first physical server according to the second network address;

and the receiving module 504 is configured to receive the reference time returned by the first physical server, and perform time synchronization according to the reference time.

In a possible implementation manner, the routing module 502 is further configured to obtain a configured first routing rule, where the first routing rule includes a correspondence between a first network address and a second network address; and acquiring a second network address corresponding to the first network address from the first routing rule through the dynamic host configuration service.

The first network address configured for acquiring the reference time is acquired through a first acquisition module 501, the routing module 502 routes the first network address to a second network address through a dynamic host configuration service in the virtual server, the sending module 503 sends a first time synchronization request to the first physical server according to the second network address, the receiving module 504 receives the reference time returned by the first physical server and performs time synchronization according to the reference time, the virtual server sends a time synchronization request to the first network address, the dynamic host configuration service routes the first network address to the second network address so as to reach the first physical server, the virtual server and the first physical server do not need to be directly connected through a network, the network security of the virtual server is ensured, and when the first physical server changes, the dynamic host configuration service is modified, the configuration of the virtual server does not need to be modified, and the efficiency is high.

Fig. 6 is a block diagram illustrating another time synchronization apparatus according to an exemplary embodiment of the present disclosure. Applied to a first physical server, the device comprises: a creation module 601, a first configuration module 602, a second configuration module 603, a second acquisition module 604, and a return module 605.

A creation module 601 configured to create a network namespace in a first physical server;

a first configuration module 602 configured to configure a dynamic host configuration server in a network namespace, the dynamic host configuration server configured to set a network address of a first physical server to a second network address;

a second configuration module 603 configured to configure a network time protocol server in the namespace, and monitor a request receiving port corresponding to a second network address through the network time protocol server;

a second obtaining module 604, configured to obtain the reference time when the first time synchronization request sent by the virtual server is monitored;

a return module 605 configured to return the reference time to the virtual server.

In a possible implementation, the returning module 605 is further configured to obtain the configured second routing rule; acquiring a third network address corresponding to the first network address from the second routing rule through the dynamic host configuration server, wherein the third network address is the network address of the virtual server; and returning the reference time to the virtual server according to the third network address.

In another possible implementation manner, the apparatus further includes:

a third configuration module configured to configure a network time protocol server and a network time protocol client in the first physical server;

a first synchronization module configured to perform time synchronization with a time server via an external network through a network time protocol client;

and the second synchronization module is configured to perform time synchronization with a second physical server in the first server cluster and a third physical server in the second server cluster through the internal network through the network time protocol server, wherein the second physical server is a redundant server of the first physical server, and the third physical server is a server for providing hardware resources for the virtual server.

In another possible implementation, the first synchronization module is further configured to periodically send, by the network time protocol client, a second time synchronization request to a network time protocol server of the time synchronization server via an external network; and receiving the reference time returned by the time synchronization server through the external network, and performing time synchronization according to the reference time.

In another possible implementation manner, the second synchronization module is further configured to receive, by the network time protocol server, a third time synchronization request sent by the network time protocol client in the second physical server via the internal network, and return, by the network time protocol server, the reference time to the second physical server; and receiving a fourth time synchronization request sent by the network time protocol client in the third physical server through the internal network through the network time protocol server, and returning the reference time to the third physical server through the network time protocol server.

In another possible implementation manner, the apparatus further includes:

and the third synchronization module is configured to periodically synchronize the configuration information of the first physical server to the configuration server, and the configuration server is used for selecting a second physical server from the first server cluster when the first physical server fails and synchronizing the configuration information to the selected second physical server.

The method comprises the steps that a network name space is created in a first physical server through a creating module 601, a dynamic host configuration server is configured in the network name space through a first configuration module 602, a network time protocol server is configured in the name space through a second configuration module 603, a request receiving port corresponding to a second network address is monitored through the network time protocol server, a reference time is acquired when a first time synchronization request sent by a virtual server is monitored through a second acquisition module 604, and a return module 605 returns the reference time to the virtual server, so that the virtual server does not need to communicate with a resident physical server to perform time synchronization, the network safety of the virtual server is ensured, and the phenomenon that the virtual server is influenced by time jump of the resident server does not occur.

Fig. 7 is a schematic structural diagram of a server 700 according to an embodiment of the present invention, where the server 700 may generate a relatively large difference due to different configurations or performances, and may include one or more processors (CPUs) 701 and one or more memories 702, where the memory 702 stores at least one instruction, and the at least one instruction is loaded and executed by the processors 701 to implement the methods provided by the foregoing method embodiments. Of course, the server may also have components such as a wired or wireless network interface, a keyboard, and an input/output interface, so as to perform input/output, and the server may also include other components for implementing the functions of the device, which are not described herein again.

The disclosed embodiments also provide a computer-readable storage medium, in which at least one instruction, at least one program, a code set, or a set of instructions is stored, and the instruction, the program, the code set, or the set of instructions is loaded and executed by a processor to implement the steps in the time synchronization method of the above-mentioned embodiments.

It will be understood by those skilled in the art that all or part of the steps of the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, and the program implementing the above time synchronization method may be stored in a computer-readable storage medium, which may be a read-only memory, a magnetic disk or an optical disk, etc.

With regard to the apparatus in the above-described embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment related to the method, and will not be described in detail here.

It is to be understood that the present disclosure is not limited to the precise arrangements described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

22页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种TDMA无线自组网时钟同步搜索的方法

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!