Debian Jessie 中似乎没有启用和同步 NTP

Ben*_*der 1 ntp ntpd

当我在 Ubuntu 中按照以下步骤操作时,NTP 已启用并同步。然而,Debian Jessie 中的情况却相反。有人知道 Debian 说“不”的原因吗?由于“当地时间”是正确的,我还应该担心吗?

采取的步骤

$ timedatectl set-timezone Europe/London

$ sudo apt-get install -y ntp

$ cat /etc/ntp.conf
driftfile /var/lib/ntp/ntp.drift
server 0.uk.pool.ntp.org iburst
server 1.uk.pool.ntp.org iburst
server 2.uk.pool.ntp.org iburst
server 3.uk.pool.ntp.org iburst
restrict 127.0.0.1
restrict ::1

$ service ntp stop
$ ntpd -gq
$ service ntp start

$ systemctl enable ntp
$ systemctl restart ntp
Run Code Online (Sandbox Code Playgroud)

Debian 状态

$ timedatectl
      Local time: Sun 2018-05-27 08:57:32 BST
  Universal time: Sun 2018-05-27 07:57:32 UTC
        RTC time: Sun 2018-05-27 07:57:30
       Time zone: Europe/London (BST, +0100)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2018-03-25 00:59:59 GMT
                  Sun 2018-03-25 02:00:00 BST
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2018-10-28 01:59:59 BST
                  Sun 2018-10-28 01:00:00 GMT


$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+h88-150-240-202 217.114.59.66    3 u   36   64    1   10.349   -1.919   0.882
*ntp3.wirehive.n 195.66.241.2     2 u   33   64    3   13.717   -0.094   1.398
+ns1.do.steersne 195.66.241.3     2 u   32   64    3    9.994   -1.230   0.947
Run Code Online (Sandbox Code Playgroud)

Ubuntu 状态

$ timedatectl
      Local time: Sun 2018-03-14 10:51:48 GMT
  Universal time: Sun 2018-03-14 10:51:48 UTC
        RTC time: Sun 2018-03-14 10:51:46
       Time zone: Europe/London (GMT, +0000)
 Network time on: yes
NTP synchronized: yes
 RTC in local TZ: no
Run Code Online (Sandbox Code Playgroud)

Tho*_*mas 5

要启用时间同步,timedatectl请使用以下命令。

timedatectl set-ntp true
Run Code Online (Sandbox Code Playgroud)

这将启用该systemd服务systemd-timesyncd.service。从man timedatectl

set-ntp [BOOL]
     Takes a boolean argument. Controls whether network time synchronization is active and enabled (if
     available). This enables and starts, or disables and stops the systemd-timesyncd.service unit. It does not
     affect the state of any other, unrelated network time synchronization services that might be installed on
     the system. This command is hence mostly equivalent to: systemctl enable --now systemd-timesyncd.service
     and systemctl disable --now systemd-timesyncd.service, but is protected by a different access policy.

     Note that even if time synchronization is turned off with this command, another unrelated system service
     might still synchronize the clock with the network. Also note that, strictly speaking,
     systemd-timesyncd.service does more than just network time synchronization, as it ensures a monotonic
     clock on systems without RTC even if no network is available. See systemd-timesyncd.service(8) for details
     about this.
Run Code Online (Sandbox Code Playgroud)

因此,egntp或可能chrony已经在运行,但timedatectl可能没有意识到这一点。

此外,您可能必须配置 NTP 服务器,/etc/systemd/timesyncd.conf除非您通过 DHCP 获取 NTP 服务器,否则它们也可能在相应的systemd-networkd.service配置中进行配置。欲了解更多信息,请参阅man systemd-timesyncd.service