运行 12.04LTS 已有一段时间了。当我们重新启动时,服务器启动时的时间会慢 46 分钟。几乎每次重新启动都是如此。我们安装了 ntp(apt-get install ntp),因此时间会在 4-5 分钟后自动更正,但 4-5 分钟的错误时间对我们来说非常糟糕。我们尝试将 @reboot root ntpdate -u pool.ntp.org 作为 crontab 条目,但这没有帮助。
答案1
实际上你可能需要关注的包是ntpdate
。它有 2 个钩子需要运行:
- 网络接口已启动:
/etc/network/if-up.d/ntpdate
- dhcp 客户端退出:
/etc/dhcp/dhclient-exit-hooks.d/ntpdate
因此请检查系统日志,可能是你的网络有问题
~$ grep ntp /var/log/syslog
Jul 8 10:04:57 BlueSkies ntpdate[3634]: name server cannot be used: Temporary failure in name resolution (-3)
Jul 8 10:05:02 BlueSkies dnsmasq[3777]: query[A] ntp.ubuntu.com from 127.0.0.1
Jul 8 10:05:02 BlueSkies dnsmasq[3777]: forwarded ntp.ubuntu.com to 192.168.1.1
Jul 8 10:05:02 BlueSkies dnsmasq[3777]: query[AAAA] ntp.ubuntu.com from 127.0.0.1
Jul 8 10:05:02 BlueSkies dnsmasq[3777]: forwarded ntp.ubuntu.com to 192.168.1.1
Jul 8 10:05:02 BlueSkies dnsmasq[3777]: reply ntp.ubuntu.com is 91.189.94.4
Jul 8 10:05:02 BlueSkies dnsmasq[3777]: reply ntp.ubuntu.com is 91.189.89.199
Jul 8 10:05:02 BlueSkies dnsmasq[3777]: reply ntp.ubuntu.com is 2001:67c:1560:8003::c7
Jul 8 10:05:08 BlueSkies ntpdate[3908]: adjust time server 91.189.89.199 offset 0.069675 sec
Jul 8 10:05:20 BlueSkies dnsmasq[3777]: query[A] ntp.ubuntu.com from 127.0.0.1
Jul 8 10:05:20 BlueSkies dnsmasq[3777]: forwarded ntp.ubuntu.com to 192.168.1.1
Jul 8 10:05:20 BlueSkies dnsmasq[3777]: query[AAAA] ntp.ubuntu.com from 127.0.0.1
Jul 8 10:05:20 BlueSkies dnsmasq[3777]: forwarded ntp.ubuntu.com to 192.168.1.1
Jul 8 10:05:20 BlueSkies dnsmasq[3777]: reply ntp.ubuntu.com is 91.189.94.4
Jul 8 10:05:20 BlueSkies dnsmasq[3777]: reply ntp.ubuntu.com is 91.189.89.199
Jul 8 10:05:20 BlueSkies dnsmasq[3777]: reply ntp.ubuntu.com is 2001:67c:1560:8003::c7
Jul 8 10:05:21 BlueSkies systemd-timesyncd[800]: Synchronized to time server 91.189.94.4:123 (ntp.ubuntu.com).
此外,我建议将默认 ntp 服务器名称更改为 IP,这样可以消除另一层故障(DNS 解析)。请参阅/etc/default/ntpdate
上述日志来自 Ubuntu 16.04 机器,这就是为什么有来自 systemd 单元的第 3 次同步请求systemd-timesyncd
。