Windows 时间同步(w32time)
场景
服务器时间越跑越偏,域内登录报「时钟偏差过大」,或者日志时间和实际对不上。
前置条件
- 管理员权限
- 知道内网 NTP 地址(域环境直接用域控)
- 123/udp 通
配置
:: 指向内网 NTP
w32tm /config /manualpeerlist:"ntp1.corp.local,0x8 ntp2.corp.local,0x8" /syncfromflags:manual /reliable:yes /update
:: 重启服务
net stop w32time
net start w32time
:: 立即同步
w32tm /resync /force
域控作为时间源时:
w32tm /config /reliable:yes /update
验证
w32tm /query /status
w32tm /query /configuration
w32tm /monitor
w32tm /stripchart /computer:ntp1.corp.local /samples:5
Source 显示的是当前时间源,Poll Interval 正常在 10 分钟级别。
回滚
w32tm /config /syncfromflags:domhier /update
net stop w32time && net start w32time
坑
- 偏差超过 5 分钟,
/resync会拒绝,得先手动w32tm /config /update再强制。 - 虚拟机上宿主机会把时间带飞,记得装集成服务并关闭时间同步或指定源。
- 域内客户端不要手动配 NTP,会打乱域层级同步。
0x8是客户端模式,服务端用0x9,别搞反。- 时间同步不对会连带 Kerberos、证书、日志排序全出问题。
- 改完
net stop再net start,直接 restart 有时不生效。