这是 RHEL 5.5 中的内容。
首先,ntpdate 到远程主机的工作原理:
$ ntpdate XXX.YYY.4.21
24 Oct 16:01:17 ntpdate[5276]: adjust time server XXX.YYY.4.21 offset 0.027291 sec
Run Code Online (Sandbox Code Playgroud)
其次,这是我的 /etc/ntp.conf 中的服务器行。所有restrict行均已被注释掉以供故障排除。
server 127.127.1.0
server XXX.YYY.4.21
Run Code Online (Sandbox Code Playgroud)
我执行service ntpd start并检查ntpq:
$ ntpq
ntpq> peer
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0) .LOCL. 5 l 36 64 377 0.000 0.000 0.001
timeserver.doma .LOCL. 1 u 39 128 377 0.489 51.261 58.975
ntpq> opeer
remote local st t when poll reach …Run Code Online (Sandbox Code Playgroud) 我有一台运行 32 位 Ubuntu 9.10(i686 2.6.31-20-generic kernel)的 AMD Athlon XP-2500+ 主机(Shuttle MN31 主板,nForce 2 IGP + MCP-T 芯片组)。不幸的是,它的时钟漂移似乎非常糟糕(它每分钟前进接近一秒),以至于 ntpd 无法保持机器同步。
我如何处理这个问题,以便让 ntpd 正常工作?
尝试将我的 Ubuntu 服务器配置为与 pool.ntp.org 同步。遵循本指南https://help.ubuntu.com/community/UbuntuTime。
我已经将我的 ntp.conf 配置如下
cat /etc/ntp.conf
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
driftfile /var/lib/ntp/ntp.drift
# Enable this if you want statistics to be logged.
statsdir /var/log/ntpstats/
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
# You do need to talk to an NTP server or two (or three).
server 0.north-america.pool.ntp.org
server 1.north-america.pool.ntp.org
server 2.north-america.pool.ntp.org …Run Code Online (Sandbox Code Playgroud) 我将默认的 iptables OUTPUT 链设置为 DROP 数据包。然后我创建了一个防火墙规则,只允许 ntp 用户发送 ntp 数据包:
iptables -A OUTPUT -m owner --uid-owner ntp -p udp --dport 123 -j ACCEPT
Run Code Online (Sandbox Code Playgroud)
但是,每 10-20 分钟我就会看到:
ntpd[27769]: sendto(<snip>) (fd=22): Operation not permitted
Run Code Online (Sandbox Code Playgroud)
然后我删除了-m owner --uid-owner ntp规则的一部分并在它之前添加了一个日志规则:
iptables -A OUTPUT -p udp --dport 123 -j LOG --log-level debug \
--log-prefix "Spotted a NTP packet: " --log-uid
Run Code Online (Sandbox Code Playgroud)
ntpd 再次开始工作,在内核环形缓冲区中,我看到:
Spotted a NTP packet: <snip> PROTO=UDP SPT=123 DPT=123 LEN=56 UID=0
Run Code Online (Sandbox Code Playgroud)
我正在使用--log-uid切换到LOG目标,并ntpd以 ntp 用户身份运行 (uid=38):
# …Run Code Online (Sandbox Code Playgroud) 我已经设置了 ntpd(Windows 7 客户端上的 Windows 的 Meinberg ntp-4.2.6p5@london 版本),并选择了一堆附近的服务器来降低 ping 时间(通常为 10-20ms ping)。然而,我的时钟似乎只能精确到 100 毫秒或更短,并且不会随着时间的推移而变得更好。我原以为它可以比 ping 时间更准确,这令人失望。如何让它更好地工作?
ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
+pool-test.ntp.o 216.218.254.202 2 u 259 1024 17 12.920 -106.39 111.972
+palpatine.steve 208.201.242.2 3 u 239 1024 17 16.959 -102.84 112.056
+grom.polpo.org 127.67.113.92 2 u 259 1024 17 17.362 -184.43 74.468
+paladin.latt.ne 204.123.2.72 2 u 378 1024 3 24.211 -106.97 61.825
+public-ntp1.iso 204.13.164.164 3 u 259 1024 17 33.080 …Run Code Online (Sandbox Code Playgroud) 我已经设置了一台 ntp 服务器和 5 个客户端。我想在启动时强制将客户端同步到服务器时钟。使用我当前的 ntp 设置,计算机正在同步,但几分钟后。我不能等待他们同步这么久。我没有使用 RTC/GPS,所有机器都在局域网中。我需要使用什么配置或命令来强制它们在启动时立即与无纪律的服务器时钟同步所有客户端*?
服务器ntp.conf
driftfile /var/lib/ntp/ntp.drift
leapfile /usr/share/zoneinfo/leap-seconds.list
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
server 127.127.1.0
fudge 127.127.1.0 stratum 8
# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited
# Local users may interrogate …Run Code Online (Sandbox Code Playgroud) 我正在使用以下命令在 Oracle Linux 6.5 上同步时间:
ntpd -gq
Run Code Online (Sandbox Code Playgroud)
不幸的是,当 Internet 连接不可用时,它不会超时。这是可能的还是应该实现我自己的超时机制?
我有一些带有公共 Internet IP 地址的服务器,例如A.B.C.x. 我的一位主机 ( A.B.C.10) 运行 ntpd,我让它从 europe.pool.ntp.org 同步时间。
现在我只想允许来自我的子网( A.B.C.x) 的主机能够同步到A.B.C.10. 默认情况下,全世界都可以同步到我的 NTP 服务器。我该如何实现?
我能找到的所有示例都假设我正在同步到特定的 IP 地址,但我同步到了 DNS 名称,并且据我所知,DNS 名称x.europe.pool.ntp.org 指向的 IP 地址是可变的。因此,我无法在防火墙中设置例外,也无法使用restrictntp.conf 中的选项,因为它也只接受IP 地址而不接受DNS 名称(哦!并且restrict像防火墙规则一样适用于客户端和服务器!)
我正在使用 chronyd 设置时间服务器,但无法同步。
# chronyc sources
210 Number of sources = 5
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^? smtp.visionnet.us 0 10 0 10y +0ns[ +0ns] +/- 0ns
^? nist1-lnk.binary.net 0 10 0 10y +0ns[ +0ns] +/- 0ns
^? c-73-98-218-154.hsd1.ut.c 0 10 0 10y +0ns[ +0ns] +/- 0ns
^? clock.xmission.com 0 10 0 10y +0ns[ +0ns] +/- 0ns
^? time-c.timefreq.bldrdoc.g 0 10 0 10y +0ns[ +0ns] +/- 0ns
Run Code Online (Sandbox Code Playgroud)
几个小时后,它仍然无法同步。
但是,如果我在具有相同 ntp 服务器的同一主机上配置 ntpd,它会立即同步:
# ntpq -p …Run Code Online (Sandbox Code Playgroud) 在 Debian 10 上,ntpd 4.2.8p12@1.3728-o无法同步并出现以下错误:
kernel reports TIME_ERROR: 0x41: Clock Unsynchronize
Run Code Online (Sandbox Code Playgroud)
这是ntp.conf:
disable monitor
statsdir /var/log/ntpstats
restrict -4 default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1
server 0.us.pool.ntp.org iburst
server 1.us.pool.ntp.org iburst
server 2.us.pool.ntp.org iburst
server 3.us.pool.ntp.org iburst
server 127.127.1.0
fudge 127.127.1.0 stratum 10
restrict 127.127.1.0
driftfile /var/lib/ntp/drift
Run Code Online (Sandbox Code Playgroud)
ntpq -c sysinfo:
associd=0 status=0614 leap_none, sync_ntp, 1 event, freq_mode,
system peer: 50-205-57-38-static.hfc.comcastbusiness.net:123
system peer mode: client …Run Code Online (Sandbox Code Playgroud)