Ubuntu如何在没有ntp的情况下同步时间?

通过单击“系统设置 – >时间和日期 – >从Internet自动”,我可以从Internet同步时间。

但是,我发现我没有ntpd守护进程(它甚至没有安装)。 那么同步如何工作呢?

这是通过与ntpdate工具同步完成的。

man ntpdate

 NAME ntpdate - set the date and time via NTP ntpdate sets the local date and time by polling the Network Time Proto‐ col (NTP) server(s) given as the server arguments to determine the cor‐ rect time. It must be run as root on the local host (unless the option -q is used). A number of samples are obtained from each of the servers specified and a subset of the NTP clock filter and selection algorithms are applied to select the best of these. Note that the accuracy and reliability of ntpdate depends on the number of servers, the number of polls each time it is run and the interval between runs. ntpdate can be run manually as necessary to set the host clock, or it can be run from the host startup script to set the clock at boot time. This is useful in some cases to set the clock initially before starting the NTP daemon ntpd. It is also possible to run ntpdate from a cron script. However, it is important to note that ntpdate with contrived cron scripts is no substitute for the NTP daemon, which uses sophisti‐ cated algorithms to maximize accuracy and reliability while minimizing resource use. Finally, since ntpdate does not discipline the host clock frequency as does ntpd, the accuracy using ntpdate is limited. 

你可以这样做

 sudo ntpdate TIME-SERVER 

可以在此处创建TIME-SERVER列表

每次网络连接启动时,Ubuntu都会与ntpdate实用程序同步(这通常在您启动时发生)。

默认情况下安装此实用程序,但仅在Ubuntu调用它时运行,并且不作为守护程序在后台运行。

安装ntp软件包会安装NTP守护程序。 ntp守护程序允许在系统运行时持续同步时间。


更新 :在最新版本的Ubuntu(例如16.04)中, ntpdatetimedatectl取代,后者在启动时以及网络启动时同步一次,但在其他时间不会继续运行。 有关详细信息,请参阅https://help.ubuntu.com/lts/serverguide/NTP.html 。

对于那些拥有16.04 LTS的人来说,时间同步似乎由sytemd专门处理“timedatectl”

 timedatectl status Local time: Wed 2016-11-30 17:45:18 CST Universal time: Wed 2016-11-30 23:45:18 UTC RTC time: Sun 2016-12-04 06:50:39 Time zone: America/Chicago (CST, -0600) Network time on: yes NTP synchronized: yes RTC in local TZ: no 

配置是

 /etc/systemd/timesyncd.conf 

更多信息: 使用NTP和timedatectl进行 时间同步

另请注意,对于未安装的服务,完全可能存在前端接口。

您可以根据需要更改该前端(GUI)界面中的设置,但如果未安装实际执行任务的服务,则不会发生任何事情。

但请注意,我认为“switch”是有效的,因为它告诉它在EACH启动时进行一次性更新。 (或不这样做)。

除非这是一个非网络连接系统,或者还有一些其他重要原因没有将其时间设置为匹配“标准”时间,我强烈建议您安装ntpd,并正确配置和运行它。

请参阅: https : //help.ubuntu.com/community/UbuntuTime

Ubuntu标配ntpdate,并将在启动时运行一次,以根据Ubuntu的NTP服务器设置时间。 但是,如果重新启动之间的时间很长,系统的时钟可能会在重新启动之间大幅度漂移。 在这种情况下,偶尔纠正时间是有意义的。 最简单的方法是让cron每天运行它。

 ntpdate ntp.ubuntu.com 

出于某种原因,在16.04, Maythux的答案不会马上起作用。

但是从那里取得领先,这对我有用。

 $ sudo ntpdate-debian 

请注意,它显然需要sudo特权。

在引擎盖下,它使用ntpdate工具,只有配置文件不同。

ntpdate-debianntpdate(8)相同,只是它/etc/default/ntpdate使用/etc/default/ntpdate的配置。 ntpdate通过轮询网络时间协议(NTP)服务器来设置本地日期和时间。

那么后来的Ubuntu版本经常使用chrony来做,这是ntp的替代实现,但有一些不同之处: –

  1. 一些较少使用的ntpfunction未实现
  2. 它试图很好地应对您具有间歇性网络访问的情况 – 连接时,它会同步本地时钟并跟踪其漂移的速度。 断开连接时,它使用本地时钟,但调整时间以允许它通常如何漂移。

有关更多信息,请参阅https://chrony.tuxfamily.org/ 。