首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ntpd -g不同步时钟。

ntpd -g不同步时钟。
EN

Server Fault用户
提问于 2021-07-17 04:51:53
回答 1查看 2.4K关注 0票数 0

来自ntpd手册页

If time is more than 1000s from the server time, ntpd assumes something must be terribly wrong and the only reliable action is for the operator to intervene and set the clock by hand. This causes ntpd to exit with a panic message to the system log. The -g option overrides this check and the clock will be set to the server time regardless of the chip time

我做了一些小实验,用ntpd测试-g选项。首先,我使用日期命令将系统时钟时间更改为旧时间。

date -s 2021.06.15-19:10:21

之后,我创建了包含以下信息的小型/etc/ntp.conf文件

代码语言:javascript
复制
driftfile  /etc/ntp.drift
logconfig =syncstatus
server time.google.com minpoll 3 maxpoll 4

之后,我使用以下命令运行ntpd

ntpd -g -n -4 -c /etc/ntp.conf &

请注意,我的ntp.drift文件是空的。

我看到系统时间没有变化,事实上ntp状态显示时钟不是同步的。

代码语言:javascript
复制
GW:/# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
  ==============================================================================
    time2.google.co .GOOG.           1 u    -   64    1    0.000   +0.000   0.000


Clock is not synchronized, stratum 16, reference is INIT
frequency is +0.000 Hz, precision is -19
reference time is (no time),
clock offset is +0.000000 msec, root delay is 0.000 msec
root dispersion is N/A

有人能帮帮我吗。我有没有漏掉任何配置或其他数据。

除此之外,我还有一个小问题

ntp时钟是否需要同步以进行ntp身份验证?如果ntp时钟没有同步,那么在这种情况下,ntp服务器身份验证将通过。

编辑:

下面是我开始ntpd时的日志

代码语言:javascript
复制
GW:~/var/log# cat ntpd.log
15 Jun 19:21:03 ntpd[14560]: Listen and drop on 0 v4wildcard 0.0.0.0:123
15 Jun 19:21:03 ntpd[14560]: Listen normally on 1 lo 127.0.0.1:123
15 Jun 19:21:03 ntpd[14560]: Listen normally on 2 srcr2 192.168.0.2:123
15 Jun 19:21:03 ntpd[14560]: Listen normally on 3 log0 1.0.0.1:123
15 Jun 19:21:03 ntpd[14560]: Listening on routing socket on fd #20 for interface updates
15 Jun 19:21:03 ntpd[14560]: kernel reports TIME_ERROR: 0x2041: Clock Unsynchronized
15 Jun 19:21:03 ntpd[14560]: kernel reports TIME_ERROR: 0x2041: Clock Unsynchronized

更新

约翰,我做了你建议的事,但我还是看到了同样的问题

代码语言:javascript
复制
GW:~/var/log# systemctl status ntpd
ntpd.service - NTPD daemon


Loaded: loaded (/etc/systemd/system/ntpd.service; disabled;   vendor  preset: enabled)
Active: active (running) since Fri 2021-07-09 08:17:46 UTC; 6min ago
Process: 21151 ExecStart=/bin/sh -c /sbin/ntpd -g  >> /var/log  /ntpd.log 2>&1  (code=exited, status=0/SUCCESS)
Main PID: 21153 (ntpd)
CGroup: /system.slice/ntpd.service
       └─21153 /sbin/ntpd -g
       

cat /etc/ntp.conf 
 # use a random selection of 4 public stratum 2 servers
 # see http://twiki.ntp.org/bin/view/Servers/NTPPoolServers
 #restrict default nomodify notrap noquery
 #restrict default noquery

logfile /var/log/ntpd.log
driftfile  /etc/ntp.drift
logconfig =syncstatus

server time1.google.com iburst
server time2.google.com iburst
server time3.google.com iburst
server time4.google.com iburst
#tried pool time.google.com also


GW:~/var/log# ntpq -c as
ind assid status  conf reach auth condition  last_event cnt
===========================================================
1  8426  9014   yes   yes  none    reject   reachable  1
2  8427  9014   yes   yes  none    reject   reachable  1
3  8428  9014   yes   yes  none    reject   reachable  1
4  8429  9014   yes   yes  none    reject   reachable  1

GW:~/var/log# ntpq -c lpeer
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 time1.google.co .GOOG.           1 u    -   64  377    0.000   +0.000   0.000
 time2.google.co .GOOG.           1 u    -   64  377    0.000   +0.000   0.000
 time3.google.co .GOOG.           1 u    -   64  377    0.000   +0.000   0.000
 time4.google.co .GOOG.           1 u    -   64  377    0.000   +0.000   0.000


GW:~/var/log# cat ntpd.log
9 Jul 08:17:46 ntpd[21153]: Listen and drop on 0 v6wildcard [::]:123
9 Jul 08:17:46 ntpd[21153]: Listen and drop on 1 v4wildcard 0.0.0.0:123
9 Jul 08:17:46 ntpd[21153]: Listen normally on 2 lo 127.0.0.1:123
9 Jul 08:17:46 ntpd[21153]: Listen normally on 3 srcr2 192.168.0.2:123
9 Jul 08:17:46 ntpd[21153]: Listen normally on 4 log0 1.0.0.1:123
9 Jul 08:17:46 ntpd[21153]: Listening on routing socket on fd #21 for interface updates
9 Jul 08:17:46 ntpd[21153]: kernel reports TIME_ERROR: 0x41: Clock Unsynchronized
9 Jul 08:17:46 ntpd[21153]: kernel reports TIME_ERROR: 0x41: Clock Unsynchronized

GW:~/var/log#

你能检查一次吗。我错过了什么吗?

更新

代码语言:javascript
复制
Pasting ntpd association output

GW:/# ntpq -c as
ind assid status  conf reach auth condition  last_event cnt
===========================================================
  1 47211  9014   yes   yes  none    reject   reachable  1
  2 47212  9014   yes   yes  none    reject   reachable  1
  3 47213  9014   yes   yes  none    reject   reachable  1
  4 47214  9014   yes   yes  none    reject   reachable  1

GW:/# GW:/#

代码语言:javascript
复制
 GW:/# ntpq -c "rv 47211"
 associd=47211 status=9014 conf, reach, sel_reject, 1 event,   reachable, 
srcadr=time1.google.com, srcport=123, dstadr=192.168.0.2,  dstport=123,
leap=00, stratum=1, precision=-20, rootdelay=0.000,   rootdisp=0.107,
refid=GOOG, reftime=e4a0073d.cba4777a  Mon, Jul 19 2021 14:14:21.795,
rec=e4a0073d.cba4777b  Mon, Jul 19 2021 14:14:21.795, reach=017,
unreach=0, hmode=3, pmode=4, hpoll=6, ppoll=6, headway=347,
flash=400 peer_dist, keyid=0, offset=+0.000, delay=0.000,
dispersion=15937.500, jitter=0.000, xleave=0.033,
filtdelay=  2833222 2833222 2833222 2833222 2833222 2833222 2833222 2833222,
filtoffset= +141661 +141661 +141661 +141661 +141661 +141661 +141661 +141661,
filtdisp=   16000.0 16000.0 16000.0 16000.0 16000.0 16000.0 16000.0 16000.0
EN

回答 1

Server Fault用户

发布于 2021-07-18 23:38:52

通常,在允许NTP通过任何防火墙后,首先处理几个数据包(增加访问范围),选择一个系统对等点,并且初始步骤确定时间。这个系统可以联系到对等方,但是拒绝了它们,这是很奇怪的。

在回顾了回流输出之后,rootdelay=0.000就没有意义了。互联网上的遥控器,不能是零。可能是为什么你得到了一个闪光灯字的距离阈值超过。

来自IRC的一种理论是,NTP数据包正在被某个中间盒破坏。如果是真的会很糟糕,因为它显然破坏了NTP。ntpd应用dscp到它的数据包,但是ntpdate没有。尝试dscp 0中的ntp.conf,询问是否有区分服务感知框在路径中。以NTP数据包的数据包捕获(tcpdump)为例,在Wireshark中查看它。查看它是否可以剖析任何DSCP字段,用NTP时间戳包装NTP数据包。

另外,在一个完全不同的网络中研究ntpd,以对比它在工作时的样子。ntpd可以在任何情况下运行,所以可能是工作站上的VM。

我最初的答案是对配置进行了评论。

你的到达记录只有1。在开始ntpd后3分钟。需要一段时间才能把第一批包拿回来。

关于您的配置:

代码语言:javascript
复制
server time.google.com minpoll 3 maxpoll 4

考虑将iburst添加到服务器和池行中。初始突发在启动时的几个数据包具有较短的延迟。

我不相信配置minpoolmaxpool是个好主意,红帽也不是。持续时间太频繁,公共NTP服务可能会阻碍您。ntpd已经擅长动态地选择池间隔。

需要更多的NTP服务器,理想情况下4用于检测带有n+1冗余的虚假代码。谷歌公共NTP有4个前端,可以与pool指令或多个服务器行一起使用。可以随意添加其他NTP服务作为第二种意见,比如2.pool.ntp.org。(但是,如果您的NTP服务器不同意这一点,您将有一个混乱的闰秒涂片。)

不,公共NTP服务不需要NTP身份验证。身份验证不是您的问题,允许大的步骤并调整投票率。

我建议的对服务器行的更改更像这样:

代码语言:javascript
复制
pool time.google.com iburst

至于你如何开始ntpd:

代码语言:javascript
复制
ntpd -g -n -4 -c /etc/ntp.conf &

-g选项是必要的,以修复如此大的偏移量的许多小时,保持它。允许无限的步骤,一旦开始。通常,较大的偏移量会引起ntpd的恐慌。在任何启动ntpd的脚本中使用-g,以便在启动时固定时间。

我看不出没有叉子加外壳搁浅的目的。从后台开始,我使用系统的服务管理器或init脚本。例如,带有systemd的Linux的ntpd.service单元。

删除-4。谷歌是IPv6的能手。

如果希望设置一次时间并退出,-q选项是有用的。为便于交互式使用,故障排除时,正常操作将保持ntpd运行。不要使用过期的ntpdate。

代码语言:javascript
复制
ntpd -g -q
票数 3
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1069878

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档