NTP 配置
约 119 个字 34 行代码 预计阅读时间 1 分钟
查看服务状态
systemctl status systemd-timesyncd.service
● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-04-15 11:26:06 CST; 4min 21s ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 86012 (systemd-timesyn)
Status: "Initial synchronization to time server xx.x.x.xx:123 (xxxxxx)."
Tasks: 2 (limit: 19105)
Memory: 1.5M
CGroup: /system.slice/systemd-timesyncd.service
└─86012 /lib/systemd/systemd-timesyncd
Apr 15 11:26:06 hcm0153 systemd[1]: Starting Network Time Synchronization...
Apr 15 11:26:06 hcm0153 systemd[1]: Started Network Time Synchronization.
Apr 15 11:27:57 hcm0153 systemd-timesyncd[86012]: Initial synchronization to time server xx.x.x.xx (xxxxxx).
查看时间状态
Local time: Fri 2022-04-15 11:31:32 CST
Universal time: Fri 2022-04-15 03:31:32 UTC
RTC time: Fri 2022-04-15 03:31:32
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
配置文件
/etc/systemd/timesyncd.conf
[Time]
#NTP=
#FallbackNTP=ntp.ubuntu.com
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048
更改 NTP 服务器
编辑 /etc/systemd/timesyncd.conf
,取消 NTP
、FallbackNTP
的注释,设置服务器地址。如果有多个,用空格隔开。
重启服务:
systemctl restart systemd-timesyncd.service
问题解决
如果日志出现 Server has too large root distance. Disconnecting.
编辑 /etc/systemd/timesyncd.conf
,取消 RootDistanceMaxSec
的注释,设置一个比较大的数。保存后重启服务。
参考资料
Linux 时间同步 systemd-timesyncd 介绍_ruth13156402807 的博客-CSDN 博客_linux timesync