@@ -25,67 +25,67 @@ icon: material/web-clock
2525
2626Linux 中支持 NTP 的软件有多种,其中较为常见的有 [ chrony] ( https://chrony-project.org/ ) 、 [ systemd-timesyncd] ( https://wiki.archlinux.org/title/Systemd-timesyncd ) 和 [ ntpdate] ( https://www.ntp.org/documentation/4.2.8-series/ntpdate/ ) 。
2727
28- ** chrony ** <!-- markdownlint-disable MD036 -->
28+ ### chrony
2929
30- : chrony 是一个功能丰富 NTP 软件,它支持多种时间源和网络协议,能够在不稳定的网络环境中保持较高的同步精度,甚至使用与计算机相连的 GPS 设备作为时钟信号源。chrony 还具有自动检测网络延迟和时钟漂移的能力,适合在虚拟机、笔记本电脑等经常变更网络环境的设备上使用。
30+ chrony 是一个功能丰富 NTP 软件,它支持多种时间源和网络协议,能够在不稳定的网络环境中保持较高的同步精度,甚至使用与计算机相连的 GPS 设备作为时钟信号源。chrony 还具有自动检测网络延迟和时钟漂移的能力,适合在虚拟机、笔记本电脑等经常变更网络环境的设备上使用。
3131
32- chrony 曾经是 Debian 发行版的默认 NTP 客户端。对于安装的 Debian 或 Ubuntu 系统 ,你也可以使用 `apt install chrony` 手动安装它。
32+ chrony 曾经是 Debian 发行版的默认 NTP 客户端。对于 Debian 和 Ubuntu 发行版 ,你也可以使用 ` apt install chrony ` 手动安装它。
3333
34- 使用以下命令可以查看当前同步状态,包括系统时钟偏移量和误差修正速率等信息:
34+ 使用以下命令可以查看当前同步状态,包括系统时钟偏移量和误差修正速率等信息:
3535
36- ```shell
37- chronyc tracking
38- ```
36+ ``` shell
37+ chronyc tracking
38+ ```
3939
40- 查看各时间源的状态(Stratum 一列展示了各时间源的层级):
40+ 查看各时间源的状态(Stratum 一列展示了各时间源的层级):
4141
42- ```shell
43- chronyc sources
44- chronyc sources -v # 显示详细界面说明
45- ```
42+ ``` shell
43+ chronyc sources
44+ chronyc sources -v # 显示详细界面说明
45+ ```
4646
47- ** systemd-timesyncd** <!-- markdownlint-disable MD036 -->
47+ ### systemd-timesyncd
4848
49- : systemd 项目也提供了一个轻量级的时间同步客户端,即 systemd-timesyncd。该服务可以在系统联网后通过 NTP 协议定期向网络上的时间服务器请求当前时间,并自动校准系统时钟。如果你只需要“能同步时间”,尤其是当校园网或企业内网中存在 NTP 服务器的时候,systemd-timesyncd 是一个更加简单省心的选项。
49+ systemd 项目也提供了一个轻量级的时间同步客户端,即 systemd-timesyncd。该服务可以在系统联网后通过 NTP 协议定期向网络上的时间服务器请求当前时间,并自动校准系统时钟。如果你只需要“能同步时间”,尤其是当校园网或企业内网中存在 NTP 服务器的时候,systemd-timesyncd 是一个更加简单省心的选项。
5050
51- Debian 自 12(Bookworm)版本起选择 systemd-timesyncd 作为默认的 NTP 客户端,因此通常情况下你不再需要手动安装它(即 `apt install systemd-timesyncd`)。
51+ Debian 自 12(Bookworm)版本起选择 systemd-timesyncd 作为默认的 NTP 客户端,因此通常情况下你不再需要手动安装它(即 ` apt install systemd-timesyncd ` )。
5252
53- 你可以在 `/etc/systemd/timesyncd.conf` 文件中查看发行版提供的默认时间服务器配置。如果你想要自己指定同步的时间服务器,可在 `/etc/systemd/timesyncd.conf.d/` 目录下新建一个配置文件(例如 `custom.conf`)。我们推荐尽可能使用位于校园网或企业内网的时间源,以减少网络延迟并提升同步稳定性。例如,科大校园网提供了一个 Stratum 2 的时间服务器 `time.ustc.edu.cn`,你可以在 `/etc/systemd/timesyncd.conf.d/custom.conf` 中添加以下内容让 systemd-timesyncd 使用它:
53+ 你可以在 ` /etc/systemd/timesyncd.conf ` 文件中查看发行版提供的默认时间服务器配置。如果你想要自己指定同步的时间服务器,可在 ` /etc/systemd/timesyncd.conf.d/ ` 目录下新建一个配置文件(例如 ` custom.conf ` )。我们推荐尽可能使用位于校园网或企业内网的时间源,以减少网络延迟并提升同步稳定性。例如,科大校园网提供了一个 Stratum 2 的时间服务器 ` time.ustc.edu.cn ` ,你可以在 ` /etc/systemd/timesyncd.conf.d/custom.conf ` 中添加以下内容让 systemd-timesyncd 使用它:
5454
55- ```ini
56- [Time]
57- NTP=time.ustc.edu.cn
58- ```
55+ ``` ini
56+ [Time]
57+ NTP =time.ustc.edu.cn
58+ ```
5959
60- 可以使用以下命令查看 `systemd-timesyncd` 的同步状态:
60+ 可以使用以下命令查看 ` systemd-timesyncd ` 的同步状态:
6161
62- ```shell
63- timedatectl show-timesync
62+ ``` shell
63+ timedatectl show-timesync
6464 ```
6565
66- ** ntpdate ** <!-- markdownlint-disable MD036 -->
66+ # ## ntpdate
6767
68- : ntpdate 是一个一次性的时间同步工具。它适用于临时性地校准系统时钟,通常用于在系统启动时或在没有持续运行的 NTP 服务的情况下进行时间同步。
68+ ntpdate 是一个一次性的时间同步工具。它适用于临时性地校准系统时钟,通常用于在系统启动时或在没有持续运行的 NTP 服务的情况下进行时间同步。
6969
70- 你可以在 Debian/Ubuntu 系统中使用以下命令安装 ntpdate:
70+ 你可以在 Debian/Ubuntu 系统中使用以下命令安装 ntpdate:
7171
72- ```shell
73- apt install ntpdate
74- ```
72+ ` ` ` shell
73+ apt install ntpdate
74+ ` ` `
7575
76- 可以使用以下命令查询某个特定的时间服务器的 Stratum 层级、与本地时钟的偏差以及网络延迟等信息:
76+ 可以使用以下命令查询某个特定的时间服务器的 Stratum 层级、与本地时钟的偏差以及网络延迟等信息:
7777
78- ```shell
79- ntpdate -q time.ustc.edu.cn
80- ```
78+ ` ` ` shell
79+ ntpdate -q time.ustc.edu.cn
80+ ` ` `
8181
82- 如果需要手动同步时间,可以使用以下命令:
82+ 如果需要手动同步时间,可以使用以下命令:
8383
84- ```shell
85- ntpdate -u time.ustc.edu.cn
86- ```
84+ ` ` ` shell
85+ ntpdate -u time.ustc.edu.cn
86+ ` ` `
8787
88- 需要注意的是,ntpdate 并不是一个持续运行的服务,只会在每次执行时进行一次时间同步,因此如果你需要持续的时间同步功能,还需要结合其他工具(如 cron)来定期执行 ntpdate 命令。相比之下,我们推荐直接使用 systemd-timesyncd 或 chrony 来实现持续的时间同步。
88+ 需要注意的是,ntpdate 并不是一个持续运行的服务,只会在每次执行时进行一次时间同步,因此如果你需要持续的时间同步功能,还需要结合其他工具(如 cron)来定期执行 ntpdate 命令。相比之下,我们推荐直接使用 systemd-timesyncd 或 chrony 来实现持续的时间同步。
8989
9090# # 设置时区 {#timezone}
9191
0 commit comments