Linux 使用 chrony 进行 NTP 时间同步及自建方法

chrony是网络时间协议的实现。它可以替代ntpd,后者是NTP的参考实现。它在类Unix操作系统上运行,并在GNU GPL v2下发布。 服务端和

chrony是网络时间协议的实现。它可以替代ntpd,后者是NTP的参考实现。它在类Unix操作系统上运行,并在GNU GPL v2下发布。

服务端和客户端配置文件都是同一个,分别配置为服务器和客户端即可使用, 配置文件在 /etc/chrony.conf or /etc/chrony/chrony.conf ,具体看版本, 可以使用 man chrony 确认一下。

服务端配置

服务端配置:

1
2
3
4
5
6
7
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server s1a.time.edu.cn iburst
server ntp.aliyun.com iburst

# Allow NTP client access from local network.
allow 192.168.8.0/24

开启同步

1
2
3
4
5
6
7
systemctl enable chronyd
systemctl restart chronyd

# 查看时间同步状态
timedatectl status
# 开启网络时间同步
timedatectl set-ntp true

客户端配置

1
2
3
4
5
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 192.168.8.5 iburst

# Allow NTP client access from local network.

开启同步

1
2
3
4
5
6
7
systemctl enable chronyd
systemctl restart chronyd

# 查看时间同步状态
timedatectl status
# 开启网络时间同步
timedatectl set-ntp true

常用命令

1
2
3
4
5
6
7
8
9
10
11
# 查看 ntp_servers
chronyc sources -v

# 查看 ntp_servers 状态
chronyc sourcestats -v

# 查看 ntp_servers 是否在线
chronyc activity -v

# 查看 ntp 详细信息
chronyc tracking -v

参考文献


Linux 使用 chrony 进行 NTP 时间同步及自建方法
https://www.frytea.com/post/20230109024531.html
作者
Tianlun Song
发布于
2023年1月9日
更新于
2024年6月10日
许可协议