天天看點

linux時間同步windows,windows 和linux做時間同步方法

周海漢 /文

2010.6.9

此前寫了篇《

linux時間同步windows,windows 和linux做時間同步方法

但如果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自帶時間同步用戶端,可以直接修改系統資料庫配置。

友善起見,直接導入系統資料庫檔案。

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/W32Time]

"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_MACHINE/SYSTEM/CurrentControlSet/Services/W32Time/Config]

"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_MACHINE/SYSTEM/CurrentControlSet/Services/W32Time/Parameters]

"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_MACHINE/SYSTEM/CurrentControlSet/Services/W32Time/Security]

"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_MACHINE/SYSTEM/CurrentControlSet/Services/W32Time/TimeProviders]

[HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/W32Time/TimeProviders/NtpClient]

"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_MACHINE/SYSTEM/CurrentControlSet/Services/W32Time/TimeProviders/NtpServer]

"InputProvider"=dword:00000000

"AllowNonstandardModeCombinations"=dword:00000001

"DllName"="C://WINDOWS//system32//w32time.dll"

"Enabled"=dword:00000001

[HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/W32Time/Enum]

"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_MACHINE/SYSTEM/CurrentControlSet/Services/W32Time/Parameters/NtpServer

這一項是設定标準時鐘源IP 位址的。将192.168.12.31 替換為標明的時鐘伺服器的IP 位址,後面的,0x1 留着不要改。

2 .(根據需要更改)

HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/W32Time/TimeProviders/NtpClient/SpecialPollInterval

這一項是設定用戶端向伺服器同步的輪詢間隔,機關為秒,預設設為1 小時,可根據需要做修改。

3 .( 根據需要更改 )

HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/W32Time/Config/MaxPosPhaseCorrection

這一項是設定最大的正時間校準量,機關為秒,預設設為15 小時,可根據需要修改。

4 .( 根據需要更改)

HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/W32Time/Config/MaxNegPhaseCorrection

這一項是設定最大的負時間校準量,機關為秒,預設設為15 小時,可根據需要修改。

5 . 退出系統資料庫編輯器。

6 .在指令提示符處,鍵入以下指令以重新啟動 Windows 時間服務,然後按 Enter :

net stop w32time && net start w32time

也可以到系統的服務裡找到windows time服務,重新開機該服務。對叢集伺服器,會引起叢集服務的關閉。