Ubuntu 自 18.04 开始使用 timesyncd 作为默认的 ntp client。当然如果有必要也可以安装较多包来部署一个自己的 ntp server。
本文只介绍如何配置 timesyncd。
方法
编辑配置文件
编辑 /etc/systemd/timesyncd.conf
,修改字段 NTP 为
NTP=ntp.sjtu.edu.cn
或者其它对方提供的 NTP 地址
更新服务
systemctl restart systemd-timesyncd
no output is the best output.
查看服务状态
systemctl status systemd-timesyncd
sample output
● systemd-timesyncd.service - Network Time Synchronization Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2023-02-04 08:36:41 CST; 22s ago Docs: man:systemd-timesyncd.service(8) Main PID: 82779 (systemd-timesyn) Status: "Initial synchronization to time server 162.159.200.123:123 (ntp.sjtu.edu.cn)." Tasks: 2 (limit: 18946) Memory: 1.2M CGroup: /system.slice/systemd-timesyncd.service └─82779 /lib/systemd/systemd-timesyncd Feb 04 08:36:41 egret systemd[1]: Starting Network Time Synchronization... Feb 04 08:36:41 egret systemd[1]: Started Network Time Synchronization. Feb 04 08:36:41 egret systemd-timesyncd[82779]: Initial synchronization to time server 162.159.200.123:123 (ntp.sjtu.edu.cn).
查看同步结果
timedatectl status
sample output
Local time: Sat 2023-02-04 08:37:29 CST Universal time: Sat 2023-02-04 00:37:29 UTC RTC time: Sat 2023-02-04 00:37:29 Time zone: Asia/Shanghai (CST, +0800) System clock synchronized: yes NTP service: active RTC in local TZ: no