linux 时钟
chronyc sourcestats 查看所有的源以及那个比较稳定
chronyc tracking 查看当前使用的是那个
ntpstat
synchronised to NTP server (119.28.183.184) at stratum 3
time correct to within 57 ms
polling server every 1024 s
chronyc tracking | grep "Reference ID" # 显示实际在用的主同步源
timedatectl status # 显示当前时间服务状态(包括 NTP 是否激活)
chronyc tracking # 查看同步源和偏移量
chronyc sources -v # 列出所有时间源及其状态
chronyc sourcestats # 显示时间源的统计信息
ntpstat # 简要显示同步状态(需安装 `ntpstat` 包)
date # 查看系统本地时间
hwclock --show # 查看硬件时钟(RTC)时间
timedatectl # 综合查看系统时间、时区及 NTP 状态
- 偏移量(offset):本地时间与源时间的差异(单位:毫秒/微秒)。
- 同步状态(stratum):时间源的层级(数字越小越接近权威源,如 stratum 1 表示原子钟/GPS)。
- NTP 服务状态:确保服务为 active (running) 且启用了 NTP enabled: yes(timedatectl 输出)。
根据你的系统选择对应的命令即可。主流现代发行版(如 CentOS 8/RHEL 8、Ubuntu 22.04+)默认使用 chrony。
1. 查看当前活动的同步源(Reference ID)
bash
复制
chronyc tracking
输出示例:
复制
Reference ID : 193.182.111.142 (当前主同步源的IP/域名)
Stratum : 3
Ref time (UTC) : Thu Oct 05 12:34:56 2023
System time : 0.000123 seconds slow of NTP time
Last offset : -0.000456 seconds
RMS offset : 0.001234 seconds
Frequency : 15.432 ppm slow
Residual freq : +0.002 ppm
Skew : 0.123 ppm
Root delay : 0.012345 seconds
Root dispersion : 0.000987 seconds
Update interval : 64.2 seconds
Leap status : Normal
- Reference ID 字段会明确显示当前实际同步的服务器(如你提到的 193.182.111.142)。
2. 验证同步源状态
从你的 chronyc sourcestats 输出中:
- 193.182.111.142 的状态异常:
- NP=1(轮询间隔极短,可能未正常响应)。
- NR=0(最近无有效响应)。
- Offset=-17ms(偏移较大)。
- Std Dev=4000ms(抖动极高,网络可能不稳定)。
- 其他服务器(如 Cloudflare 和 Infomaniak)更稳定,但未被选中。
3. 为什么粉色显示的 193.182.111.142 是当前源?
- 粉色/高亮显示:在 chronyc 交互界面中,当前活动的同步源会以不同颜色(如粉色)标记。
- 可能原因:
- 配置优先级:该服务器在 /etc/chrony.conf 中可能是第一个配置的源。
- 临时切换:网络波动导致 Chrony 临时选择了该源。
- 服务器故障:其他源暂时不可用,被迫回退到此源。
4. 强制切换同步源
如果当前源不稳定,可以手动切换到更优的源(如 Cloudflare):
bash
复制
chronyc add server time.cloudflare.com iburst # 临时添加新源(可选)
chronyc waitsync 5 # 等待同步完成(最多5秒)
chronyc tracking # 再次检查是否切换成功
5. 优化配置
编辑 /etc/chrony.conf,确保优先使用稳定的服务器(如 Cloudflare):
ini
复制
server time.cloudflare.com iburst prefer # 标记为优先(prefer)
server tick.ntp.infomaniak.ch iburst
server tock.ntp.infomaniak.ch iburst
# 注释或删除不稳定的 193.182.111.142
重启服务:
bash
复制
systemctl restart chronyd
关键结论:
- 当前主同步源是 193.182.111.142(粉色高亮),但其状态异常(高偏移、无响应)。
- 建议切换到 time.cloudflare.com(稳定性最佳,Offset 仅 -404ns)。
- 检查网络连通性:ping 193.182.111.142 或 traceroute 193.182.111.142,确认是否存在延迟/丢包。