使用chrony作为NTP服务软件。
1.主服务器安装chrony
bash
sudo apt install chrony -y
配置 /etc/chrony/chrony.conf:
bash
# 允许内网客户端
allow 192.168.1.0/24
# 使用外部时间源
pool 0.ubuntu.pool.ntp.org iburst
pool 1.ubuntu.pool.ntp.org iburst
# 本地时钟作为备用
local stratum 10
2.客户端安装chrony
bash
sudo apt install chrony -y
配置 /etc/chrony/chrony.conf:
bash
# 指向主时间服务器
server 192.168.1.100 iburst
3.管理chrony服务
bash
sudo systemctl restart chrony
sudo systemctl enable chrony
# 查看状态
chronyc sources -v
chronyc tracking
4.查看客户端是否同步成功
查看客户端列表(在主服务器上检查)
bash
# 在主服务器上执行
chronyc clients
输出示例:
bash
Hostname NTP Drop Int IntL Last Cmd Drop Int Last
===============================================================================
192.168.1.101 0 0 6 - 45 0 0 - -