AlmaLinux 10:把一台主机变成局域网时间源
AlmaLinux 10.2 Server 组虚拟机,chrony-4.8-2.el10。
实验:本机不接外部 NTP(实验网无外网),加两行配置让它以自身时钟为参考,对局域网提供时间;另一台 VM 指过来取时。截图:public/evidence/chrony/alma-server.png。
$ grep -E '^(allow|local stratum)' /etc/chrony.confallow 192.168.2.0/24local stratum 10allow 192.168.2.0/24:允许该网段的客户端取时;local stratum 10:本机没有可用上游时,把自己当作 stratum 10 的参考源。
改完 systemctl restart chronyd。
自己看到的状态
Section titled “自己看到的状态”$ chronyc tracking | grep -E '^(Reference ID|Stratum)'Reference ID : 7F7F0101 ()Stratum : 10Reference ID 7F7F0101 是 chrony 对「本地时钟」的固定标记(127.127.1.1),看到它说明没有上游,靠本地时钟在撑。这正是实验环境的样子,也是它不能用于生产授时的原因。
谁在向我取时
Section titled “谁在向我取时”$ chronyc clientsHostname NTP Drop Int IntL Last Cmd Drop Int Last===============================================================================192.168.2.243 7 0 3 - 28 0 0 - -
$ chronyc serverstats | head -3NTP packets received : 7NTP packets dropped : 0clients 列出正在取时的客户端与包数,serverstats 给总量。两者都是「服务端视角」的验证手段——比在客户端猜要直接。
端口必须放行
Section titled “端口必须放行”$ firewall-cmd --list-servicescockpit dhcpv6-client ntp ssh$ ss -lun | grep ':123 ' | head -1UNCONN 0 0 0.0.0.0:123 0.0.0.0:*Server 组默认不含 ntp 服务,需要 firewall-cmd --permanent --add-service=ntp && firewall-cmd --reload。
什么时候可以这么用
Section titled “什么时候可以这么用”| 场景 | 合适吗 |
|---|---|
| 隔离实验网、需要统一时间 | 合适(误差取决于本机 RTC) |
| 生产内网的时间源 | 不合适:local 是「劣化模式」,不纠正频率漂移 |
| 上游偶发不可用时的兜底 | 可短时使用,但要监控 stratum 变化 |
真正的时间源应至少接两台上游(pool 或 server ... iburst ×2),local 只在完全隔离时启用。

- 只加
allow不加local stratum:没有上游时 stratum 0,客户端拒绝使用; - 忘了放行 ntp:客户端一直
^?,服务端NTP packets received为 0; - 以为
local是「高精度」:它只是让本机可用作参考,精度取决于硬件时钟; - 上游恢复后
local还在:chrony 会优先用真实上游,但配置残留容易误导排障。
练习:验证「服务端看到什么」
Section titled “练习:验证「服务端看到什么」”sudo grep -E '^(allow|local stratum)' /etc/chrony.confsudo chronyc serverstats | head -3sudo chronyc clients | head -4sudo firewall-cmd --list-services | tr ' ' '\n' | grep -x ntp检查:
allow的网段覆盖客户端所在网段;serverstats的NTP packets received随客户端运行增长;clients里出现客户端 IP;- 防火墙服务列表里有
ntp。
常见问题
local stratum 10 会不会污染上游?
不会。它是本地参考,只在没有更好来源时使用;客户端看到的是 stratum 10 起步的值。
能只允许特定客户端吗?
可以,allow 支持网段与具体地址,也可配合 chrony 的 restrict 指令细化权限。
为什么客户端 stratum 是 11?
chrony 每经过一层加 1;服务端 10,客户端即 11。
- 离线更新源:/offline-updates/
- systemd 定时器:/systemd-timers/
- 服务与日志:/journald-logging/