Ntp
NTP 似 乎沒有在 Debian Jessie 中啟用和同步
當我在 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
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
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
要啟用時間同步,
timedatectl
請使用以下命令。timedatectl set-ntp true
這將啟用該
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.
因此,例如
ntp
或chrony
已經在執行但timedatectl
可能沒有意識到這一點是可能的。此外,您可能必須配置您的 NTP 伺服器,
/etc/systemd/timesyncd.conf
除非您通過 DHCP 獲取您的 NTP 伺服器,或者它們也可能在相應的配置中進行systemd-networkd.service
配置。有關詳細資訊,請參閱man systemd-timesyncd.service
。