$ timedatectl status
Local time: Tue 2018-05-01 21:54:24 CST
Universal time: Tue 2018-05-01 13:54:24 UTC
RTC time: Tue 2018-05-01 13:54:24
Time zone: Asia/Shanghai (CST, +0800)
Network time on: yes
NTP synchronized: yes
RTC in local TZ: no
使用systemctl status systemd-timesyncd可以检查时钟同步情况:
$ systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/systemd-timesyncd.service.d
└─disable-with-time-daemon.conf
Active: active (running) since Mon 2018-04-16 10:33:42 CST; 2 weeks 1 days ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 910 (systemd-timesyn)
Status: "Synchronized to time server 91.189.91.157:123 (ntp.ubuntu.com)."
Tasks: 2
Memory: 2.2M
CPU: 2.710s
CGroup: /system.slice/systemd-timesyncd.service
└─910 /lib/systemd/systemd-timesyncd
Apr 29 07:30:24 devstack systemd-timesyncd[910]: Timed out waiting for reply from 91.189.91.157:123 (ntp.ubuntu.com).
Apr 29 07:30:24 devstack systemd-timesyncd[910]: Synchronized to time server 91.189.94.4:123 (ntp.ubuntu.com).
Apr 29 09:14:36 devstack systemd-timesyncd[910]: Timed out waiting for reply from 91.189.94.4:123 (ntp.ubuntu.com).
Apr 29 09:14:46 devstack systemd-timesyncd[910]: Timed out waiting for reply from 91.189.89.198:123 (ntp.ubuntu.com).
Apr 29 09:14:56 devstack systemd-timesyncd[910]: Timed out waiting for reply from 91.189.89.199:123 (ntp.ubuntu.com).
Apr 29 09:49:06 devstack systemd-timesyncd[910]: Synchronized to time server 91.189.89.199:123 (ntp.ubuntu.com).
Apr 29 13:52:01 devstack systemd-timesyncd[910]: Timed out waiting for reply from 91.189.89.199:123 (ntp.ubuntu.com).
Apr 29 13:52:11 devstack systemd-timesyncd[910]: Timed out waiting for reply from 91.189.89.198:123 (ntp.ubuntu.com).
Apr 29 13:52:21 devstack systemd-timesyncd[910]: Timed out waiting for reply from 91.189.94.4:123 (ntp.ubuntu.com).
Apr 29 13:52:22 devstack systemd-timesyncd[910]: Synchronized to time server 91.189.91.157:123 (ntp.ubuntu.com).
再次检查systemctl status systemd-timesyncd,就可以看到和指定NTP服务器同步时间:
...
May 01 22:38:36 pi1 systemd[1]: Starting Network Time Synchronization...
May 01 22:38:37 pi1 systemd[1]: Started Network Time Synchronization.
May 01 22:38:37 pi1 systemd-timesyncd[23922]: Synchronized to time server 192.168.0.1:123 (192.168.0.1).