windows 和linux做时间同步方法

abloz 2010-06-09
2010-06-09

周海汉 /文

2010.6.9

此前写了篇《linux设置时间 服务器 》,解决了Linux之间时间同步的问题。windows系统想偷懒,用windows自带的internet时间同步,向time.windows.com进行同步。双击任务栏右下角的时间,弹出时间设置,可以选择用哪些时间服务器更新。

但如果windows系统不能上公网时,必须使用本地的时间服务器。由于我linux局域网的时间服务器地址是192.168.12.31.如果直 接将时间服务器的IP修改为192.168.12.31, 更新时间会失败。加入域的windows缺省的时间同步类型是nt5ds,没有加入域的是ntp.

可以在windows直接安装一个ntp时间服务器。比如到此下载 :http://www.meinberg.de/english/sw/ntp.htm

现在既然linux已经有了时间服务器,就不必再安装时间服务器了。

由于windows自带时间同步客户端,可以直接修改注册表配置。

方便起见,直接导入注册表文件。


  1. Windows Registry Editor Version 5.00
  2. [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32Time]
  3. “Description”=”维护在网络上的所有客户端和服务器的时间和日期同步。如果此服务被停止,时间和日期的同步将不可用。如果此服务被禁用,任何明确依赖它的服务都将不能启动。
  4. “DisplayName”=”Windows Time”
  5. “ErrorControl”=dword:00000001
  6. “FailureActions”=hex:05,00,00,00,00,00,00,00,00,00,00,00,02,00,00,00,64,00,20,
  7. 00,01,00,00,00,60,ea,00,00,01,00,00,00,60,ea,00,00
  8. “Group”=””
  9. “ImagePath”=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,
  10. 74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,73,
  11. 00,76,00,63,00,68,00,6f,00,73,00,74,00,2e,00,65,00,78,00,65,00,20,00,2d,00,
  12. 6b,00,20,00,4c,00,6f,00,63,00,61,00,6c,00,53,00,65,00,72,00,76,00,69,00,63,
  13. 00,65,00,00,00
  14. “Objectname”=”NT AUTHORITY\LocalService”
  15. “Start”=dword:00000004
  16. “Type”=dword:00000020
  17. [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeConfig]
  18. “LastClockRate”=dword:0002625a
  19. “MinClockRate”=dword:000260d4
  20. “MaxClockRate”=dword:000263e0
  21. “FrequencyCorrectRate”=dword:00000004
  22. “PollAdjustFactor”=dword:00000005
  23. “LargePhaseOffset”=dword:02faf080
  24. “SpikeWatchPeriod”=dword:00000384
  25. “HoldPeriod”=dword:00000005
  26. “LocalClockDispersion”=dword:0000000a
  27. “EventLogFlags”=dword:00000002
  28. “PhaseCorrectRate”=dword:00000001
  29. “MinPollInterval”=dword:0000000a
  30. “MaxPollInterval”=dword:0000000f
  31. “UpdateInterval”=dword:00057e40
  32. “MaxNegPhaseCorrection”=dword:0000d2f0
  33. “MaxPosPhaseCorrection”=dword:0000d2f0
  34. “AnnounceFlags”=dword:00000005
  35. “MaxAllowedPhaseOffset”=dword:00000001
  36. [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeParameters]
  37. “ServiceMain”=”SvchostEntry_W32Time”
  38. “ServiceDll”=hex(2):43,00,3a,00,5c,00,57,00,49,00,4e,00,44,00,4f,00,57,00,53,
  39. 00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,77,00,33,00,
  40. 32,00,74,00,69,00,6d,00,65,00,2e,00,64,00,6c,00,6c,00,00,00
  41. “NtpServer”=”192.168.12.31,0x1”
  42. “Type”=”NTP”
  43. [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeSecurity]
  44. “Security”=hex:01,00,14,80,a8,00,00,00,b4,00,00,00,14,00,00,00,30,00,00,00,02,
  45. 00,1c,00,01,00,00,00,02,80,14,00,ff,01,0f,00,01,01,00,00,00,00,00,01,00,00,
  46. 00,00,02,00,78,00,05,00,00,00,00,00,14,00,8d,00,02,00,01,01,00,00,00,00,00,
  47. 05,0b,00,00,00,00,00,18,00,ff,01,0f,00,01,02,00,00,00,00,00,05,20,00,00,00,
  48. 20,02,00,00,00,00,18,00,8d,00,02,00,01,02,00,00,00,00,00,05,20,00,00,00,23,
  49. 02,00,00,00,00,14,00,9d,00,00,00,01,01,00,00,00,00,00,05,04,00,00,00,00,00,
  50. 18,00,9d,00,00,00,01,02,00,00,00,00,00,05,20,00,00, 00,21,02,00,00,01,01,00,
  51. 00,00,00,00,05,12,00,00,00,01,01,00,00,00,00,00,05,12,00,00,00
  52. [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeTimeProviders]
  53. [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeTimeProvidersNtpClient]
  54. “Enabled”=dword:00000001
  55. “InputProvider”=dword:00000001
  56. “AllowNonstandardModeCombinations”=dword:00000001
  57. “CrossSiteSyncFlags”=dword:00000002
  58. “ResolvePeerBackoffMinutes”=dword:0000000f
  59. “ResolvePeerBackoffMaxTimes”=dword:00000007
  60. “CompatibilityFlags”=dword:80000000
  61. “EventLogFlags”=dword:00000001
  62. “LargeSampleSkew”=dword:00000003
  63. “DllName”=”C:\WINDOWS\system32\w32time.dll”
  64. “SpecialPollTimeRemaining”=hex(7):00,00
  65. “SpecialPollInterval”=dword:00000e10
  66. [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeTimeProvidersNtpServer]
  67. “InputProvider”=dword:00000000
  68. “AllowNonstandardModeCombinations”=dword:00000001
  69. “DllName”=”C:\WINDOWS\system32\w32time.dll”
  70. “Enabled”=dword:00000001
  71. [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeEnum]
  72. “0”=”Root\LEGACY_W32TIME\0000”
  73. “Count”=dword:00000001
  74. “NextInstance”=dword:00000001

Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32Time] “Description”=”维护在网络上的所有客户端和服务器的时间和日期同步。如果此服务被停止,时间和日期的同步将不可用。如果此服务被禁用,任何明确依赖它的服务都将不能启动。 “ “DisplayName”=”Windows Time” “ErrorControl”=dword:00000001 “FailureActions”=hex:05,00,00,00,00,00,00,00,00,00,00,00,02,00,00,00,64,00,20, 00,01,00,00,00,60,ea,00,00,01,00,00,00,60,ea,00,00 “Group”=”” “ImagePath”=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00, 74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,73, 00,76,00,63,00,68,00,6f,00,73,00,74,00,2e,00,65,00,78,00,65,00,20,00,2d,00, 6b,00,20,00,4c,00,6f,00,63,00,61,00,6c,00,53,00,65,00,72,00,76,00,69,00,63, 00,65,00,00,00 “Objectname”=”NT AUTHORITY\LocalService” “Start”=dword:00000004 “Type”=dword:00000020 [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeConfig] “LastClockRate”=dword:0002625a “MinClockRate”=dword:000260d4 “MaxClockRate”=dword:000263e0 “FrequencyCorrectRate”=dword:00000004 “PollAdjustFactor”=dword:00000005 “LargePhaseOffset”=dword:02faf080 “SpikeWatchPeriod”=dword:00000384 “HoldPeriod”=dword:00000005 “LocalClockDispersion”=dword:0000000a “EventLogFlags”=dword:00000002 “PhaseCorrectRate”=dword:00000001 “MinPollInterval”=dword:0000000a “MaxPollInterval”=dword:0000000f “UpdateInterval”=dword:00057e40 “MaxNegPhaseCorrection”=dword:0000d2f0 “MaxPosPhaseCorrection”=dword:0000d2f0 “AnnounceFlags”=dword:00000005 “MaxAllowedPhaseOffset”=dword:00000001 [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeParameters] “ServiceMain”=”SvchostEntry_W32Time” “ServiceDll”=hex(2):43,00,3a,00,5c,00,57,00,49,00,4e,00,44,00,4f,00,57,00,53, 00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,77,00,33,00, 32,00,74,00,69,00,6d,00,65,00,2e,00,64,00,6c,00,6c,00,00,00 “NtpServer”=”192.168.12.31,0x1” “Type”=”NTP” [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeSecurity] “Security”=hex:01,00,14,80,a8,00,00,00,b4,00,00,00,14,00,00,00,30,00,00,00,02, 00,1c,00,01,00,00,00,02,80,14,00,ff,01,0f,00,01,01,00,00,00,00,00,01,00,00, 00,00,02,00,78,00,05,00,00,00,00,00,14,00,8d,00,02,00,01,01,00,00,00,00,00, 05,0b,00,00,00,00,00,18,00,ff,01,0f,00,01,02,00,00,00,00,00,05,20,00,00,00, 20,02,00,00,00,00,18,00,8d,00,02,00,01,02,00,00,00,00,00,05,20,00,00,00,23, 02,00,00,00,00,14,00,9d,00,00,00,01,01,00,00,00,00,00,05,04,00,00,00,00,00, 18,00,9d,00,00,00,01,02,00,00,00,00,00,05,20,00,00,00,21,02,00,00,01,01,00, 00,00,00,00,05,12,00,00,00,01,01,00,00,00,00,00,05,12,00,00,00 [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeTimeProviders] [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeTimeProvidersNtpClient] “Enabled”=dword:00000001 “InputProvider”=dword:00000001 “AllowNonstandardModeCombinations”=dword:00000001 “CrossSiteSyncFlags”=dword:00000002 “ResolvePeerBackoffMinutes”=dword:0000000f “ResolvePeerBackoffMaxTimes”=dword:00000007 “CompatibilityFlags”=dword:80000000 “EventLogFlags”=dword:00000001 “LargeSampleSkew”=dword:00000003 “DllName”=”C:\WINDOWS\system32\w32time.dll” “SpecialPollTimeRemaining”=hex(7):00,00 “SpecialPollInterval”=dword:00000e10 [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeTimeProvidersNtpServer] “InputProvider”=dword:00000000 “AllowNonstandardModeCombinations”=dword:00000001 “DllName”=”C:\WINDOWS\system32\w32time.dll” “Enabled”=dword:00000001 [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeEnum] “0”=”Root\LEGACY_W32TIME\0000” “Count”=dword:00000001 “NextInstance”=dword:00000001

将以上脚本另存为ntp.reg, 192.168.12.31修改为你要的ntp服务器地址,然后导入。

Windows ntp客户端配置

除标准时钟服务器外,其它的Windows 平台都作为客户端,不需要安装程序,只作注册表配置。导入压缩包里的注册表ntp.reg ,打开注册表,根据需要做以下修改:

1 .如果导入前没有修改ntp地址,则必须进入注册表编辑如下键值

HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeParametersNtpServer

这一项是设置标准时钟源IP 地址的。将192.168.12.31 替换为选定的时钟服务器的IP 地址,后面的,0x1 留着不要改。

2 .(根据需要更改)

HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeTimeProvidersNtpClientSpecialPollInterval

这一项是设置客户端向服务器同步的轮询间隔,单位为秒,默认设为1 小时,可根据需要做修改。

3 .( 根据需要更改 )

HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeConfigMaxPosPhaseCorrection

这一项是设置最大的正时间校准量,单位为秒,默认设为15 小时,可根据需要修改。

4 .( 根据需要更改)

**HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW32TimeConfigMaxNegPhaseCorrection **

这一项是设置最大的负时间校准量,单位为秒,默认设为15 小时,可根据需要修改。

5 . 退出注册表编辑器。

6 .在命令提示符处,键入以下命令以重新启动 Windows 时间服务,然后按 Enter :

net stop w32time && net start w32time

也可以到系统的服务里找到windows time服务,重启该服务。对集群服务器,会引起集群服务的关闭。


如非注明转载, 均为原创. 本站遵循知识共享CC协议,转载请注明来源