(笔记)【NTP系列:02】NTP使用常见问题记录

 

一、ntpd & ntpdate

 NTP遇到的一些问题

 
我的两台虚拟机,使用135作为ntp服务器,138以135为准同步时间。
version:4.2.6p5
ntpd 服务是按照一定时间来同步,而ntpdate是立即同步,但是二者都要使用udp端口123,所以,不能同时运行,也就是在ntpd服务起动的时候,如果运行ntpdate,会有如下提示:
【the NTP socket is in use, exiting】
 NTP遇到的一些问题
所以,为了使用ntpdate立刻同步时间,需要关闭ntpd服务,之后再使用ntpdate命令同步时间就可以了,执行命令:
#systemctl stop ntpd
#ntpdate your-ntp-server
 
 
二、ntpdate同步失败
2.1 【no servers can be used, exiting】
ntpdate在同步时间的时候,需要指定你要同步时间的时间服务器,也就是ntpdate不会使用ntpd的配置文件/etc/ntpd.conf,这就是为什么虽然在配置文件中指定了ntp服务器,但是只执行ntpdate命令的时候,会提示
 
NTP遇到的一些问题
no servers can be used, exiting。
也就是提示:ntpdate未指定服务器,所以命令中补充NTP服务器IP即可,如"ntpdate 172.16.1.200"
 
2.2 【no server suitable for synchronization found】

这个问题的出现和你指定的ntp服务器的版本有关,我的版本是4.2。

下面是来自ntp官方网站的说明:

The behavior of notrust changed between versions 4.1 and 4.2.

In 4.1 (and earlier) notrust meant "Don't trust this host/subnet for time".

In 4.2 (and later) notrust means "Ignore all NTP packets that are not cryptographically authenticated." This forces remote time servers to authenticate themselves to your (client) ntpd

远程ntp是必须加密的,这一点有待研究,但是本地测试,先将这个关闭掉即可。

解决:

将你在ntp服务器配置文件指定访问客户ip的限制条件notrust去掉。

NTP遇到的一些问题

修改为:

NTP遇到的一些问题

 

 

说明:若ntpdate失败,此时可以使用ntpdate -d server_ip获取具体原因,如下:

root@AM437x-Droidsurg:~# ntpdate -d 172.16.1.200
 3 Feb 13:08:27 ntpdate[767]: ntpdate 4.2.8p9@1.3265-o Fri Nov  8 06:35:47 UTC 2019 (2)
Looking for host 172.16.1.200 and service ntp
host found : 172.16.1.200
transmit(172.16.1.200)
receive(172.16.1.200)
transmit(172.16.1.200)
receive(172.16.1.200)
transmit(172.16.1.200)
receive(172.16.1.200)
transmit(172.16.1.200)
receive(172.16.1.200)
172.16.1.200: Server dropped: Leap not in sync
server 172.16.1.200, port 123
stratum 4, precision -23, leap 11, trust 000
refid [172.16.1.200], delay 0.02621, dispersion 0.00005
transmitted 4, in filter 4
reference time:    e786fc57.694af343  Fri, Feb  3 2023 11:21:59.411
originate timestamp: e787158e.215b7216  Fri, Feb  3 2023 13:09:34.130
transmit timestamp:  e7871551.ba3fef9e  Fri, Feb  3 2023 13:08:33.727
filter delay:  0.02657  0.02635  0.02621  0.02664 
         0.00000  0.00000  0.00000  0.00000 
filter offset: 60.40218 60.40204 60.40203 60.40224
         0.000000 0.000000 0.000000 0.000000
delay 0.02621, dispersion 0.00005
offset 60.402032

 如“Server dropped: Leap not in sync”,此时基本上是ntp服务端有异常,可尝试重启ntp服务端。

 

 

三、ntpd同步失败

1. 首先一定先确保可以使用ntpdate校时,若ntpdate校时不成功,则需先排查ntpdate的错误信息。使用ntpdate -d server_ip获取具体原因,如“Server dropped: Leap not in sync”、“Server dropped: no data"、“Server dropped: strata oo high".

2. 然后查阅本博客园下方文章。

(笔记)NTP时间同步失败:Windows(W32Time)作为NTP时钟源服务端,Linux作为客户端 - tdyizhen1314 - 博客园 (cnblogs.com)

 

posted on 2023-02-02 13:42  tdyizhen1314  阅读(1711)  评论(0编辑  收藏  举报

导航