Arch ntpd/ntpdate 不同步时钟

fat*_*fat 7 linux arch-linux ntpd ntp raspberry-pi

我的 raspi 运行 Arch 没有使用 NTPD 更新时间。我在跑

 [root@fatpi ~]# cat /proc/version
 Linux version 3.10.28-1-ARCH (nobody@root-armv6-copy) (gcc version 4.8.2 20131219 (prerelease) (GCC) ) #1 PREEMPT Tue Jan 28 15:46:05 MST 2014
Run Code Online (Sandbox Code Playgroud)

所以我停止服务并尝试使用 ntpdate 进行更新,但是“ntpdate -sb”不起作用,奇怪的是“ntpdate -qd”将输出正确的日期和偏移量:


[root@fatpi ~]# ntpdate -dq time.nist.gov
31 Dec 18:09:13 ntpdate[299]: ntpdate 4.2.6p5@1.2349-o Sat Jan 11 17:42:10 UTC 2014 (1)
Looking for host time.nist.gov and service ntp
host found : nist1-chi.ustiming.org
transmit(216.171.120.36)
receive(216.171.120.36)
transmit(216.171.120.36)
receive(216.171.120.36)
transmit(216.171.120.36)
receive(216.171.120.36)
transmit(216.171.120.36)
receive(216.171.120.36)
server 216.171.120.36, port 123
stratum 1, precision -29, leap 00, trust 000
refid [ACTS], delay 0.07671, dispersion 0.00000
transmitted 4, in filter 4
reference time:    d69d8005.439fdedc  Wed, Feb  5 2014 21:29:09.264
originate timestamp: d69d800c.753a297e  Wed, Feb  5 2014 21:29:16.457
transmit timestamp:  83aa80af.2239d5e4  Wed, Dec 31 1969 18:09:19.133
filter delay:  0.07681  0.07671  0.07689  0.07681
         0.00000  0.00000  0.00000  0.00000
filter offset: 13916567 13916567 13916567 13916567
         0.000000 0.000000 0.000000 0.000000
delay 0.07671, dispersion 0.00000
offset 1391656797.298671

31 Dec 18:09:19 ntpdate[299]: step time server 216.171.120.36 offset 1391656797.298671 sec
Run Code Online (Sandbox Code Playgroud)

当我的 ntpd 服务运行时,这是“ntpq”输出,refid 不会从 INIT 状态改变,并且reach始终为 0。


ntpq> peers
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 nist1.ny.certic .INIT.          16 u    -   64    0    0.000    0.000   0.000
 elara.mysnip.de .INIT.          16 u    -   64    0    0.000    0.000   0.000
 dsl-201-120-53- .INIT.          16 u    -   64    0    0.000    0.000   0.000
 golem.canonical .INIT.          16 u    -   64    0    0.000    0.000   0.000
ntpq> as

ind assid status  conf reach auth condition  last_event cnt
===========================================================
  1 22183  8011   yes    no  none    reject    mobilize  1
  2 22184  8011   yes    no  none    reject    mobilize  1
  3 22185  8011   yes    no  none    reject    mobilize  1
  4 22186  8011   yes    no  none    reject    mobilize  1
ntpq>

Run Code Online (Sandbox Code Playgroud)

我的 /var/log/ntp.log 读作:(没什么意思)


31 Dec 18:00:18 ntpd[124]: Deferring DNS for time.nist.gov 1
31 Dec 18:00:18 ntpd[124]: Deferring DNS for 0.pool.ntp.org 1
31 Dec 18:00:18 ntpd[124]: Deferring DNS for 1.pool.ntp.org 1
31 Dec 18:00:18 ntpd[124]: Deferring DNS for 2.pool.ntp.org 1
31 Dec 18:00:18 ntpd[124]: Deferring DNS for ntp.ubuntu.com 1
31 Dec 18:00:18 ntpd[132]: signal_no_reset: signal 17 had flags 4000000
31 Dec 18:00:20 ntpd[132]: host name not found: time.nist.gov
31 Dec 18:00:20 ntpd[132]: host name not found: 0.pool.ntp.org
31 Dec 18:00:20 ntpd[132]: host name not found: 1.pool.ntp.org
31 Dec 18:00:20 ntpd[132]: host name not found: 2.pool.ntp.org
31 Dec 18:00:20 ntpd[132]: host name not found: ntp.ubuntu.com
31 Dec 18:00:30 ntpd[124]: Listen normally on 2 eth0 192.168.0.104 UDP 123
31 Dec 18:00:30 ntpd[124]: peers refreshed
31 Dec 18:00:30 ntpd[124]: new interface(s) found: waking up resolver
31 Dec 18:00:32 ntpd[132]: DNS time.nist.gov -> 216.171.120.36
31 Dec 18:00:32 ntpd[132]: DNS 0.pool.ntp.org -> 201.120.27.5
31 Dec 18:00:32 ntpd[132]: DNS 1.pool.ntp.org -> 201.120.27.5
31 Dec 18:00:32 ntpd[132]: DNS 2.pool.ntp.org -> 201.120.27.5
31 Dec 18:00:32 ntpd[132]: DNS ntp.ubuntu.com -> 91.189.94.4

Run Code Online (Sandbox Code Playgroud)

我已经将我的 ntp.conf 文件更改了无数次,目前:


server time.nist.gov iburst
server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst
server ntp.ubuntu.com iburst

restrict default noquery nopeer restrict 127.0.0.1 restrict ::1

driftfile /var/lib/ntp/ntp.drift logfile /var/log/ntp.log

Run Code Online (Sandbox Code Playgroud)

我的 ntpd.service 文件显示:


[Unit]
Description=Network Time Service
After=network.target nss-lookup.target

[Service]
Type=forking
PrivateTmp=true
PIDFile=/var/run/ntpd.pid
ExecStart=/usr/bin/ntpd -g -u ntp:ntp -p /var/run/ntpd.pid
Restart=always

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

我还安装了 fake-hwclock 但没有帮助(应该没关系,因为我的 ntpd 使用 -g 运行)


ntpd -q 输出:


[root@fatpi ~]# ntpd -qd
ntpd 4.2.6p5@1.2349-o Sat Jan 11 17:42:09 UTC 2014 (1)
31 Dec 18:02:42 ntpd[296]: proto: precision = 1.000 usec
event at 0 0.0.0.0 c01d 0d kern kernel time sync enabled
Finished Parsing!!
31 Dec 18:02:42 ntpd[296]: ntp_io: estimated max descriptors: 1024, initial socket boundary: 16
31 Dec 18:02:42 ntpd[296]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 123
31 Dec 18:02:42 ntpd[296]: Listen normally on 1 lo 127.0.0.1 UDP 123
restrict: op 1 addr 127.0.0.1 mask 255.255.255.255 mflags 00003000 flags 00000001
31 Dec 18:02:42 ntpd[296]: Listen normally on 2 eth0 192.168.0.104 UDP 123
restrict: op 1 addr 192.168.0.104 mask 255.255.255.255 mflags 00003000 flags 00000001
31 Dec 18:02:42 ntpd[296]: peers refreshed
31 Dec 18:02:42 ntpd[296]: Listening on routing socket on fd #19 for interface updates
restrict: op 1 addr 0.0.0.0 mask 0.0.0.0 mflags 00000000 flags 00000050
restrict: op 1 addr :: mask 0.0.0.0 mflags 00000000 flags 00000050
restrict: op 1 addr 127.0.0.1 mask 255.255.255.255 mflags 00000000 flags 00000000
31 Dec 18:02:42 ntpd[296]: restrict: error in address '::1' on line 12. Ignoring...
key_expire: at 0 associd 21204
peer_clear: at 0 next 1 associd 21204 refid INIT
event at 0 64.250.229.100 8011 81 mobilize assoc 21204
newpeer: 192.168.0.104->64.250.229.100 mode 3 vers 4 poll 6 10 flags 0x101 0x1 ttl 0 key 00000000
key_expire: at 0 associd 21205
peer_clear: at 0 next 2 associd 21205 refid INIT
event at 0 132.248.81.123 8011 81 mobilize assoc 21205
newpeer: 192.168.0.104->132.248.81.123 mode 3 vers 4 poll 6 10 flags 0x101 0x1 ttl 0 key 00000000
key_expire: at 0 associd 21206
peer_clear: at 0 next 3 associd 21206 refid INIT
event at 0 91.189.94.4 8011 81 mobilize assoc 21206
newpeer: 192.168.0.104->91.189.94.4 mode 3 vers 4 poll 6 10 flags 0x101 0x1 ttl 0 key 00000000
event at 0 0.0.0.0 c016 06 restart
event at 0 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
event at 0 0.0.0.0 c011 01 freq_not_set
transmit: at 1 192.168.0.104->64.250.229.100 mode 3 len 48
auth_agekeys: at 1 keys 1 expired 0
transmit: at 2 192.168.0.104->132.248.81.123 mode 3 len 48
transmit: at 3 192.168.0.104->91.189.94.4 mode 3 len 48
transmit: at 66 192.168.0.104->64.250.229.100 mode 3 len 48
transmit: at 68 192.168.0.104->132.248.81.123 mode 3 len 48
transmit: at 69 192.168.0.104->91.189.94.4 mode 3 len 48
transmit: at 131 192.168.0.104->64.250.229.100 mode 3 len 48
transmit: at 133 192.168.0.104->91.189.94.4 mode 3 len 48
transmit: at 135 192.168.0.104->132.248.81.123 mode 3 len 48
transmit: at 197 192.168.0.104->91.189.94.4 mode 3 len 48
transmit: at 197 192.168.0.104->64.250.229.100 mode 3 len 48
transmit: at 202 192.168.0.104->132.248.81.123 mode 3 len 48
transmit: at 262 192.168.0.104->91.189.94.4 mode 3 len 48
transmit: at 263 192.168.0.104->64.250.229.100 mode 3 len 48
transmit: at 267 192.168.0.104->132.248.81.123 mode 3 len 48
transmit: at 327 192.168.0.104->91.189.94.4 mode 3 len 48
transmit: at 327 192.168.0.104->64.250.229.100 mode 3 len 48
transmit: at 331 192.168.0.104->132.248.81.123 mode 3 len 48
^C31 Dec 18:09:12 ntpd[296]: ntpd exiting on signal 2
[root@fatpi ~]#

Run Code Online (Sandbox Code Playgroud)

但!ntpdate -buv作品!!!!


[root@fatpi ~]# ntpdate -bv ntp.ubuntu.com
31 Dec 18:11:18 ntpdate[299]: ntpdate 4.2.6p5@1.2349-o Sat Jan 11 17:42:10 UTC 2014 (1)
31 Dec 18:11:27 ntpdate[299]: no server suitable for synchronization found
[root@fatpi ~]# date
Wed Dec 31 18:11:52 CST 1969
[root@fatpi ~]# ntpdate -buv ntp.ubuntu.com
31 Dec 18:11:54 ntpdate[303]: ntpdate 4.2.6p5@1.2349-o Sat Jan 11 17:42:10 UTC 2014 (1)
 6 Feb 14:31:00 ntpdate[303]: step time server 91.189.94.4 offset 1391717938.800589 sec
[root@fatpi ~]# date
Thu Feb  6 14:31:02 CST 2014
Run Code Online (Sandbox Code Playgroud)

我想使它工作的原因是 ntpdate 的 -u,它使用非特权端口。我阅读了 ntpdate 的 -u 选项的手册页,它指出 -d 总是使用这个选项,所以这就是为什么我在我的 ntpdate -dq 命令上看到传输/接收/传输/接收——好吧,大不!

我猜端口 udp 123 转发是我现在应该检查的内容?

Jei*_*ght 10

看来 NTP 太不同步 (1391656797.298671),需要强制同步。

使用 中的-d选项时ntpdate,它只是调试。它经历了所有步骤,但实际上并不强制同步。

执行以下操作之一:

ntpd -q
Run Code Online (Sandbox Code Playgroud)

或者

ntpdate -buv ntp.ubuntu.com
Run Code Online (Sandbox Code Playgroud)