2020-08-20 15:36:07 +08:00
|
|
|
|
# NTP 同步网络时间
|
|
|
|
|
|
|
|
|
|
Linux 使用 NTP 协议进行网络时间同步。使用 ntpdate 命令可进行网络时间同步。
|
|
|
|
|
|
|
|
|
|
## 1.安装
|
|
|
|
|
|
|
|
|
|
首先需要安装 NTP 协议和相关工具。
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# Manjaro
|
2022-04-29 13:20:16 +08:00
|
|
|
|
sudo pacman -S ntp
|
2020-08-20 15:36:07 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 2.同步网络时间
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# 同步网络时间
|
2023-05-05 21:25:27 +08:00
|
|
|
|
sudo ntpdate 0.cn.pool.ntp.org
|
2020-08-20 15:36:07 +08:00
|
|
|
|
# 将系统时钟写到硬件中
|
2023-05-05 21:25:27 +08:00
|
|
|
|
sudo hwclock -w
|
2020-08-20 15:36:07 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 3.服务器列表
|
|
|
|
|
|
|
|
|
|
一级服务器列表:<http://support.ntp.org/bin/view/Servers/StratumOneTimeServers>
|
|
|
|
|
|
|
|
|
|
二级服务器列表:<http://support.ntp.org/bin/view/Servers/StratumTwoTimeServers>
|
|
|
|
|
|
|
|
|
|
清华大学:ntp.tuna.tsinghua.edu.cn
|
|
|
|
|
|
|
|
|
|
微软:time.windows.com
|
|
|
|
|
|
|
|
|
|
## 4.设置每日自动更新
|
|
|
|
|
|
|
|
|
|
Alternatively, enable ntpdate.service to synchronize time once (option -q) and non-forking (option -n) per boot.
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
systemctl enable ntpdate.service
|
|
|
|
|
systemctl start ntpdate.service
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
如果需要同步时间到 hardware clock,则需要在 start ntpdate.service 之前创建并编辑 /etc/systemd/system/ntpdate.service.d/hwclock.conf,内容如下:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
[Service]
|
|
|
|
|
ExecStart=/usr/bin/hwclock -w
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 5.内部参考关键字
|
|
|
|
|
|
2020-09-28 16:48:24 +08:00
|
|
|
|
1. Linux
|
|
|
|
|
2. 时间管理
|