1. 思路
利用 systemd-timesyncd 服務實現
2. 實現
修改配置文件,重啟服務
nano /etc/systemd/timesyncd.conf
[Time]
NTP=10.1.89.1
重啟服務
systemctl restart systemd-timesyncd
3. 檢查
3.1 文件方式
/var/lib/systemd/timesync/clock
此文件的修改時間表示上次成功同步的時間戳。 如果無法同步,則至少表示 systemd 的 編譯時間。
/run/systemd/timesync/synchronized
每次同步成功時都會 touch 該文件,以幫助 systemd-time-wait-sync 及其他程序 檢測同步事件。
3.2 服務日志方式
systemctl status systemd-timesyncd
>>
systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/etc/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
Drop-In: /usr/lib/systemd/system/systemd-timesyncd.service.d
└─disable-with-time-daemon.conf
Active: active (running) since Tue 2021-03-01 16:43:48 CST; 16s ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 1415788 (systemd-timesyn)
Status: "Synchronized to time server for the first time 10.1.89.1:123 (10.1.89.1)."
Tasks: 2 (limit: 7372)
Memory: 1.6M
CGroup: /system.slice/systemd-timesyncd.service
└─1415788 /lib/systemd/systemd-timesyncd
Mar 01 16:43:48 pve08 systemd[1]: Starting Network Time Synchronization...
Mar 01 16:43:48 pve08 systemd[1]: Started Network Time Synchronization.
Mar 01 16:43:45 pve08 systemd-timesyncd[1415788]: Synchronized to time server for the first time 10.1.89.1:123 (10.1.89.1
引用/延伸:
http://manpages.ubuntu.com/manpages/bionic/zh_TW/man1/timedatectl.1.html
http://www.jinbuguo.com/systemd/systemd-timesyncd.service.html
http://www.jinbuguo.com/systemd/timesyncd.conf.html#
