Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does the server synchronize network time

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How the server synchronizes the network time, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Network time synchronization Protocol (NTP) is the technical basis of time synchronization. Ntp components are installed by default in all Linux operating systems. If the server can access the external network and configure the DNS server address, direct ntpdate 0.cn.pool.ntp.org can synchronize the external network time. However, for security reasons, many servers do not configure DNS although they are connected to the external network, so it is necessary to synchronize time directly from the ip address of the time server. You can use ntp1.aliyun.com 's time server ip to synchronize directly, ntpdate 120.24.81.91, or Tsinghua's time server 84.16.73.33.

The first synchronization time of the server is shown as follows

[root@localhost] # ntpdate 120.24.81.9110 Aug 09:46:07 ntpdate [15071]: step time server 120.24.81.91 offset 1.423469 sec

After each execution of the synchronization time command, the display is different from the first time.

[root@localhost] # ntpdate 120.24.81.9110 Aug 14:16:14 ntpdate [12150]: adjust time server 120.24.81.91 offset-0.030012 sec

Suppose An and B have two Linux servers.

An is open to the public network. Although the DNS server is not configured, it can ping 120.24.81.91.

B did not open the public network, ping 120.24.81.91 will report connect: Network is unreachable, this certainly can not synchronize time from the public network server. If you execute ntpdate 120.24.81.91, you will report no server suitable for synchronization found, or no servers can be used, exiting.

The easiest way is to configure An as the ntp server (NTP server) after correcting the time from the external network, and B synchronizes the time from A. Configure the ntp server first modify the configuration file ntp.conf to ensure that everything is correct, then execute # / etc/init.d/ntpd start to start the ntp server, wait 5 minutes, execute # ntpdate AIP on B (AIP is the private network IP address of A), you can synchronize A's system time to B, indirectly synchronizing the external network time.

Configuration An is NTP server, first modify the configuration file, and after the modification of the configuration file / etc/ntp.conf, execute the following instructions, except 192.168.2.0 to change the network segment of your own local area network, the rest of the requirements must be the same as below, there are more statements than below will be commented out, no statements will be added.

# cat / etc/ntp.conf | awk'{if ($0! ~ / ^ $/ & & $0! ~ / ^ # /) {print $0}}'

Restrict default ignore / / # set the default policy to allow any host to synchronize time restrict 127.0.0.1 / / give all permissions to the local machine restrict 192.168.2.0 mask 255.255.255.0 nomodify notrap / / give the machine on the local network the permission to synchronize time server 0 .127.127.1.0 / / set the time server as the local machine Can be set to 120.24.81.91 public network server server 127.127.1.0 # local clockfudge 127.127.1.0 stratum 10driftfile / var/lib/ntp/driftbroadcastdelay 0.008keys / etc/ntp/keys

Then execute / etc/init.d/ntpd start, which displays OK, indicating success. If the configuration file is modified repeatedly, / etc/init.d/ntpd restart makes it easier to reload the configuration file.

Wait 5 minutes, which is for NTP server to synchronize native time. Then execute ntpdate 192.168.2.10 on 2.13

[root@DB1 ~] # ntpdate 192.168.2.10

10 Aug 13:35:59 ntpdate [10737]: adjust time server 192.168.2.10 offset 0.004937 sec

Indicates that the synchronization time is successful, and the execution of offset multiple times will become smaller. If the requirement is not high, the error of one execution will already be within a few thousandths of a second.

If ntpdate 192.168.2.10 returns an error no server suitable for synchronization found, it may be that the time of NTP server itself is not synchronized yet. You can view it using the ntpdate-d serverIP directive.

[root@DB1] # ntpdate-d 192.168.2.1010 Aug 13:28:07 ntpdate [10719]: ntpdate 4.2.0a@1.1190-r Thu Oct 5 04:11:32 EDT 2006 (1) Looking for host 192.168.2.10 and service ntphost found: 192.168.2.10transmit (192.168.2.10) receive (192.168.2.10) omitted 192.168.2.10: Server dropped: strata too highserver 192.168.2.10, port 123stratum 16, precision-20, leap 11 Trust 000refid [192.168.2.10], delay 0.02573, dispersion 0.00000 omitted

There is a prompt for "Server dropped: strata too high" and "stratum 16". The normal range of stratum is "0,15". This means that we don't have to do anything. If we try to execute the instructions for a while, it will become stratum 11, precision-20, leap 00000, trust 000000. Stratum 11 is in the normal range, and the execution of ntpdate 192.168.2.10 successfully corrects the time.

In addition, the firewalls of An and B are turned off, and the whole process is operated by root account. The reason that An is not configured to automatically synchronize the public network time is for security reasons. If B needs to correct the time frequently, the crontab configuration ntpdate instruction can achieve the purpose.

Crontab-e

9 7 * / usr/sbin/ntpdate 192.168.2.10

System time synchronization to hardware time can also be set as needed. The advantage of keeping the hardware time consistent with the system time is that it can avoid errors caused by the hardware time covering the system time after restarting the server.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report