前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >时间偏差超过15小时(54000秒),无法自动校时的解决方案

时间偏差超过15小时(54000秒),无法自动校时的解决方案

原创
作者头像
Windows技术交流
修改2022-08-08 18:38:42
1.5K0
修改2022-08-08 18:38:42
举报
文章被收录于专栏:Windows技术交流Windows技术交流

借鉴https://blog.csdn.net/weixin_43673589/article/details/109144725

承接https://cloud.tencent.com/developer/article/1851075

参考了微软官网文档:

https://docs.microsoft.com/zh-CN/troubleshoot/windows-server/identity/configure-w32ime-against-huge-time-offset

https://docs.microsoft.com/en-US/troubleshoot/windows-server/identity/configure-w32ime-against-huge-time-offset

https://docs.microsoft.com/zh-cn/troubleshoot/windows-client/identity/w32time-not-start-on-workgroup

https://docs.microsoft.com/en-us/troubleshoot/windows-client/identity/w32time-not-start-on-workgroup

https://docs.microsoft.com/zh-cn/troubleshoot/windows-server/identity/specialpollinterval-polling-interval-time-service-not-correct

https://docs.microsoft.com/en-us/troubleshoot/windows-server/identity/specialpollinterval-polling-interval-time-service-not-correct

有2个注册表项很关键

MaxPosPhaseCorrection MaxNegPhaseCorrection

Windows 2000、Windows XP、Windows Server 2003 和 Windows Vista 中的 ,这2个 注册表项的默认值为0xFFFFFFF,全F意味着使计算机任何时候都能自动校时。

在 ≥2008 的Server系统中,已采用 MaxPosPhaseCorrection 和 MaxNegPhaseCorrection 注册表项的新默认值为 48 小时(172800秒)。

在≥Win7的PC系统,已采用 MaxPosPhaseCorrection 和 MaxNegPhaseCorrection 注册表项的新默认值为 15 小时(54000秒)。

具体情况执行命令查看

reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config"|findstr PhaseCorrection

如下问题只是偶现,在阿里云、腾讯云等多家云厂商都有遇到,应该是windows系统层面的机制,而不是云厂商方面的问题。

腾讯云:

阿里云:

我调整时区前的时区是utc+7曼谷时间,然后我调时区到utc-10夏威夷时间,重启机器后,发现系统时间还是曼谷时间,并且不能自动校时到utc-10夏威夷时间,有类似如上的Time-Service系统日志和提醒手动校时的文字。

Windows can't synchronize automatically with the time server because the time difference is too great. Please update your time manually.

解决方案如下:阿里那边应用这个方案也可以,只需要把涉及内网域名的地方换成阿里的即可

基本原理就是既设置ntp 1分钟校时,也设置开机计划任务1分钟校时,原因是开机后第1次校时要等若干分钟,校时成功后才会每隔1分钟校时1次,设置开机计划任务就是为了让开机后快速校时,不用等若干分钟(等若干分钟的原因见微软官网文档https://docs.microsoft.com/en-us/troubleshoot/windows-client/identity/w32time-not-start-on-workgroup ,参考微软文档后就不需要设置开机计划任务校时了,但设置上也无妨,双保险)

代码里的10进制数 4294967295 是16进制0xFFFFFFFF

管理员身份powershell运行代码

invoke-webrequest http://windowsgg-1251783334.cos.na-siliconvalley.myqcloud.com/timesync.ps1 -outfile c:\timesync.ps1 2>$null 1>$null

c:\timesync.ps1

代码详情如下

schtasks.exe /delete /tn "time sync" /F 2>&1 > $null

schtasks.exe /delete /tn "timesync" /F 2>&1 > $null

$configfile =@"

@echo off`n`r

net stop w32time 2>&1 > nul`n`r

#w32tm /unregister`n`r

#w32tm /register`n`r

sc.exe triggerinfo w32time delete`n`r

sc.exe config w32time start= auto`n`r

sc.exe triggerinfo w32time start/networkon stop/networkoff`n`r

net start w32time`n`r

w32tm /config /manualpeerlist:"time1.tencentyun.com,0x1 time2.tencentyun.com,0x1 time3.tencentyun.com,0x1 time4.tencentyun.com,0x1 time5.tencentyun.com,0x1" /syncfromflags:manual /reliable:yes /update`n`r

w32tm /resync`n`r

w32tm /resync`n`r

w32tm /resync`n`r

"@

$configfile|Out-File -FilePath C:\Windows\timesync.bat -Encoding ascii -Force

notepad C:\Windows\timesync.bat

#Invoke-WebRequest -uri http://windowsgg-1251783334.cos.na-siliconvalley.myqcloud.com/timesync.xml -OutFile c:\timesync.xml

#Register-ScheduledTask -xml (Get-Content 'c:\timesync.xml' | Out-String) -TaskName timesync -TaskPath \ -force

#上面2行代码适用≥2012系统,不适用2008R2系统,为了提升代码兼容性,上面2行的功能用下面的黑体代码替代了

$str1=""

$str2=""

$str3=""

if(((Get-WmiObject Win32_OperatingSystem).version) -eq "6.1.7601"){

$str1="certutil -urlcache -split -f "

$str2=" "

$str3="Win7"

}

if(((Get-WmiObject Win32_OperatingSystem).version) -ne "6.1.7601"){

$str1="Invoke-WebRequest -uri "

$str2=" -OutFile "

if(((Get-WmiObject Win32_OperatingSystem).version) -eq "6.3.9600"){$str3="Win8"}

if(((Get-WmiObject Win32_OperatingSystem).version).split(".")[0] -eq "10"){$str3="Win10"}

}

"Set-ExecutionPolicy Unrestricted -force" > c:\importtask.ps1

$str1+("'http://windowsgg-1251783334.cos.na-siliconvalley.myqcloud.com/timesync.xml'")+$str2+("'c:\timesync.xml'") >> c:\importtask.ps1

powershell -file c:\importtask.ps1

start-sleep 5

del "c:\importtask.ps1" 2>&1 > $null

schtasks /create /tn "timesync" /XML c:\timesync.xml 2>$null

start-sleep 5

del "c:\timesync.xml" 2>&1 > $null

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\W32Time\Config" /v MaxNegPhaseCorrection /t reg_dword /d 4294967295 /f

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\W32Time\Config" /v MaxPosPhaseCorrection /t reg_dword /d 4294967295 /f

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Policies\Microsoft\W32Time\Config" /v MaxNegPhaseCorrection /t reg_dword /d 4294967295 /f

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Policies\Microsoft\W32Time\Config" /v MaxPosPhaseCorrection /t reg_dword /d 4294967295 /f

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\w32time\Config" /v MaxNegPhaseCorrection /t reg_dword /d 4294967295 /f

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\w32time\Config" /v MaxPosPhaseCorrection /t reg_dword /d 4294967295 /f

net stop w32time 2>&1 > $null

#w32tm /unregister

#w32tm /register

sc.exe triggerinfo w32time delete ; sc.exe config w32time start= auto

#sc.exe config w32time start= delayed-auto

sc.exe triggerinfo w32time start/networkon stop/networkoff

net start w32time

reg add "HKLM\SYSTEM\CurrentControlSet\Services\W32Time\Config" /v "MinPollInterval" /t reg_DWORD /d 5 /f

reg add "HKLM\SYSTEM\CurrentControlSet\Services\W32Time\Config" /v "MaxPollInterval" /t reg_DWORD /d 10 /f

reg add "HKLM\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient" /v "SpecialPollInterval" /t reg_DWORD /d 60 /f

reg add "HKLM\SOFTWARE\Policies\Microsoft\W32Time\TimeProviders\NtpClient" /v "SpecialPollInterval" /t reg_DWORD /d 60 /f

reg add "HKLM\SOFTWARE\Wow6432Node\Policies\Microsoft\W32Time\TimeProviders\NtpClient" /v "SpecialPollInterval" /t reg_DWORD /d 60 /f

w32tm /config /update

w32tm /config /manualpeerlist:"time1.tencentyun.com,0x1 time2.tencentyun.com,0x1 time3.tencentyun.com,0x1 time4.tencentyun.com,0x1 time5.tencentyun.com,0x1" /syncfromflags:manual /reliable:yes /update

net stop w32time 2>&1 > $null

net start w32time

reg query HKLM\SYSTEM\CurrentControlSet\Services\W32Time\Parameters | findstr "NtpServer Type"

reg query HKLM\SOFTWARE\Policies\Microsoft\W32Time\Parameters | findstr "NtpServer Type"

reg query HKLM\SOFTWARE\WOW6432Node\Policies\Microsoft\W32time\Parameters | findstr "NtpServer Type"

reg query HKLM\SYSTEM\CurrentControlSet\Services\W32Time\Config | findstr "PollInterval"

reg query HKLM\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient | findstr "PollInterval"

reg query HKLM\SOFTWARE\Policies\Microsoft\W32Time\TimeProviders\NtpClient | findstr "PollInterval"

reg query HKLM\SOFTWARE\Wow6432Node\Policies\Microsoft\W32Time\TimeProviders\NtpClient | findstr "PollInterval"

w32tm /resync 2>&1 > $null

start-sleep 3

w32tm /resync 2>&1 > $null

start-sleep 3

w32tm /resync 2>&1 > $null

要验证调整不同的时区时是否会自动校时,命令行设置时区的命令tzutil /s ,举例

举例:

设置utc-10 阿拉斯加时区

tzutil /s "Hawaiian Standard Time"

设置utc-9阿拉斯加时区

tzutil /s "Alaskan Standard Time"

设置utc-8美国加拿大太平洋时区

tzutil /s "Pacific Standard Time"

设置utc+2埃及开罗时区

tzutil /s "Egypt Standard Time"

设置utc+8中国东八区

tzutil /s "China Standard Time"

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云服务器
云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档