1. 程式人生 > >ntp時間同步問題解決方法

ntp時間同步問題解決方法

adf provider start 方法 net tick ech announce pool

亞洲 - asia.pool.ntp.org http://www.pool.ntp.org/zone/asia
0.asia.pool.ntp.org
1.asia.pool.ntp.org
2.asia.pool.ntp.org
3.asia.pool.ntp.org

2.1 註冊表信息修改
PDC配置外部時間源設置

#config external NTP server
w32tm.exe /config /manualpeerlist:”0.asia.pool.ntp.org,1.asia.pool.ntp.org,2.asia.pool.ntp.org,3.asia.pool.ntp.org,0x1” /syncfromflags:manual /reliable:YES /update

#update
w32tm.exe /config /update
#此處可以在配置過程中不使用,在配置不生效的情況下再執行關閉和開啟服務器的動作
#stop w32time
Stop-Service W32Time
#start w32time
start-Service w32time

#internal NTP for PDC
Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Parameters" -Name "Type" -Value NTP
Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Config" -Name "AnnounceFlags" -Value 5

Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer" -Name "Enabled" -Value 1
Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient" -Name "SpecialPollInterval" -Value 900
說明:
以上代碼配置可以直接對PDC配置外部時間源,同時針對客戶端的更細頻率等參數進行設置,設置可以根據客戶的實際要求酌情進行調整

2.1.1 指定外部時間源
w32tm /config /manualpeerlist:"time.stdtime.gov.tw clock.stdtime.gov.tw tick.stdtime.gov.tw watch.stdtime.gov.tw,0x1" /syncfromflags:manual /reliable:yes /update
技術分享圖片
2.1.2 設置授權時間服務器
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config"
[AnnounceFlags]修改設定值為5

技術分享圖片
2.1.3 啟用NTP服務
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters" [Type]設定值修改為NTP
技術分享圖片
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer" [Enabled]數值修改為1

技術分享圖片

2.1.4 設定查詢時間間隔
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient" [SpecialPollInterval]修改數值為"十進制"600
技術分享圖片
2.1.5 時間修正設置
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config"
[MaxPosPhaseCorrection]修改為十進制6000 (負差校正) – 若網絡時間比本地時間慢超過這個秒數就不自動更正
[MaxNegPhaseCorrection]修改為十進制6000 (正差校正) – 若網絡時間比本地時間快超過這個秒數就不自動更正
技術分享圖片

2.1.6 開啟時間服務端口
netsh firewall add portopening protocol=UDP port=123 name=NTPSERVER

技術分享圖片

2.1.7 重啟Time32時間服務並同步外部時間源
Net stop w32time & net start w32time //重啟w32time時間服務器
W32tm /config /update //更新時間服務配置信息
W32tm /resync //同步時間源
w32tm /query /peers //查詢時間同步服務器及相關情報
W32tm /query /source //查看同步時間源
技術分享圖片
2.2 修改AD相關設置

2.2.1 設置AD時間源服務器
技術分享圖片

2.2.2 修改PDC服務器使用內部時間源
技術分享圖片
2.2.3 組策略設置
技術分享圖片
3 同步時間測試
沒有加域的客戶端第一次需要運行同步時間腳本,來指定內部NTP服務器進行時間同步
腳本 內容如下:
@echo off
color 2f
title 調整 Time
echo.
echo.
echo.
echo. 開啟防火墻123端口
netsh firewall add portopening protocol = UDP port =123 name = NTPSERVER
echo.
echo.
echo.
echo. 寫入註冊表信息
w32tm /config /update /manualpeerlist:"172.16.108.7 ntp.fudan.edu.cn s1b.time.edu.cn s1c.time.edu.cn,0x1"
echo.
echo.
echo.
echo. 重啟w32time服務
net stop w32time & net start w32time
echo.
echo.
echo.
echo. 更新時間配置
w32tm /config /update
w32tm /config /update
w32tm /config /update
w32tm /resync
w32tm /resync
w32tm /resync
w32tm /resync
w32tm /resync
w32tm /resync
pause
經過反復測試,客戶端可以成功同步時間服務器時間;

查看註冊表分支:[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient],找到Enabled,修改0為1,然後重啟時間同步服務即可;
同步時間遇到“找不到元素”時這樣操作可以解決。

ntp時間同步問題解決方法