<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>NTP on HiDa</title><link>https://www.0niu.cn/tags/ntp/</link><description>Recent content in NTP on HiDa</description><generator>Hugo -- gohugo.io</generator><language>zh</language><lastBuildDate>Mon, 08 Apr 2024 08:16:34 +0800</lastBuildDate><atom:link href="https://www.0niu.cn/tags/ntp/index.xml" rel="self" type="application/rss+xml"/><item><title>Windows域控配置时钟源</title><link>https://www.0niu.cn/posts/set-windows-dc-time-source/</link><pubDate>Mon, 08 Apr 2024 08:16:34 +0800</pubDate><guid>https://www.0niu.cn/posts/set-windows-dc-time-source/</guid><description>&lt;h2 id="背景">背景&lt;/h2>
&lt;p>在 Active Directory 环境中，所有成员计算机和域控制器默认使用层级时间同步架构：&lt;/p>
&lt;ul>
&lt;li>&lt;strong>森林根域的 PDC Emulator&lt;/strong> → 整个森林的权威时间源&lt;/li>
&lt;li>&lt;strong>子域的 PDC Emulator&lt;/strong> → 向森林根 PDC 同步&lt;/li>
&lt;li>&lt;strong>普通域控制器&lt;/strong> → 向同域的 PDC Emulator 同步&lt;/li>
&lt;li>&lt;strong>域成员计算机&lt;/strong> → 向所在站点的域控制器同步&lt;/li>
&lt;/ul>
&lt;p>因此，&lt;strong>只需在森林根域的 PDC Emulator 上配置外部 NTP 源&lt;/strong>，时间就能自动向下层传播。&lt;/p></description><content>&lt;h2 id="背景">背景&lt;/h2>
&lt;p>在 Active Directory 环境中，所有成员计算机和域控制器默认使用层级时间同步架构：&lt;/p>
&lt;ul>
&lt;li>&lt;strong>森林根域的 PDC Emulator&lt;/strong> → 整个森林的权威时间源&lt;/li>
&lt;li>&lt;strong>子域的 PDC Emulator&lt;/strong> → 向森林根 PDC 同步&lt;/li>
&lt;li>&lt;strong>普通域控制器&lt;/strong> → 向同域的 PDC Emulator 同步&lt;/li>
&lt;li>&lt;strong>域成员计算机&lt;/strong> → 向所在站点的域控制器同步&lt;/li>
&lt;/ul>
&lt;p>因此，&lt;strong>只需在森林根域的 PDC Emulator 上配置外部 NTP 源&lt;/strong>，时间就能自动向下层传播。&lt;/p>
&lt;h2 id="配置步骤">配置步骤&lt;/h2>
&lt;h3 id="1-查看当前时间同步状态">1. 查看当前时间同步状态&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-batch" data-lang="batch">&lt;span style="display:flex;">&lt;span>w32tm /query /status
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>输出中关注以下字段：&lt;/p>
&lt;ul>
&lt;li>&lt;code>源&lt;/code>：当前同步的上游服务器&lt;/li>
&lt;li>&lt;code>最后成功的同步时间&lt;/code>&lt;/li>
&lt;/ul>
&lt;h3 id="2-设置外部-ntp-源">2. 设置外部 NTP 源&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-batch" data-lang="batch">&lt;span style="display:flex;">&lt;span>w32tm /config /manualpeerlist:&lt;span style="color:#e6db74">&amp;#34;172.25.2.254,0x8 time.windows.com,0x8 pool.ntp.org,0x8&amp;#34;&lt;/span> /syncfromflags:manual /reliable:yes /update
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>参数说明：&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>参数&lt;/th>
&lt;th>说明&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>/manualpeerlist&lt;/code>&lt;/td>
&lt;td>手动指定 NTP 服务器列表，用空格分隔&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>0x8&lt;/code>&lt;/td>
&lt;td>客户端模式，不向对端提供时间服务（推荐用于 DC）&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>/syncfromflags:manual&lt;/code>&lt;/td>
&lt;td>仅从手动指定的列表同步&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>/reliable:yes&lt;/code>&lt;/td>
&lt;td>标记为可靠时间源，允许下游客户端向其同步&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>/update&lt;/code>&lt;/td>
&lt;td>将更改写入注册表并通知服务&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 id="3-重启时间服务并触发同步">3. 重启时间服务并触发同步&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-batch" data-lang="batch">&lt;span style="display:flex;">&lt;span>net stop w32time &amp;amp;&amp;amp; net start w32time
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>w32tm /resync /rediscover
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="4-验证">4. 验证&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-batch" data-lang="batch">&lt;span style="display:flex;">&lt;span>w32tm /query /status
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>w32tm /query /source
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>确认源地址已变更为指定的 NTP 服务器，且同步成功。&lt;/p>
&lt;h2 id="注意事项">注意事项&lt;/h2>
&lt;ul>
&lt;li>多个 NTP 服务器之间用&lt;strong>空格&lt;/strong>分隔，不是逗号&lt;/li>
&lt;li>&lt;code>0x8&lt;/code> 标志表示使用&lt;strong>客户端模式&lt;/strong>（NTP Client），适用于 DC 向上游同步；如果希望这台 DC 同时为其他客户端提供服务，仍然使用 &lt;code>0x8&lt;/code>，因为 &lt;code>/reliable:yes&lt;/code> 已声明其可靠性&lt;/li>
&lt;li>修改后无需重启服务器，重启 &lt;code>w32time&lt;/code> 服务即可生效&lt;/li>
&lt;li>域内客户端默认每 &lt;strong>604800 秒（7天）&lt;/strong> 进行一次时间校正偏移，可通过组策略调整 &lt;code>MaxPosPhaseCorrection&lt;/code> 和 &lt;code>MaxNegPhaseCorrection&lt;/code>&lt;/li>
&lt;/ul>
&lt;h2 id="排查">排查&lt;/h2>
&lt;p>时间同步失败时检查：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-batch" data-lang="batch">&lt;span style="display:flex;">&lt;span>:&lt;span style="color:#75715e">: 查看时间服务配置详情&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>w32tm /query /configuration
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>:&lt;span style="color:#75715e">: 检查 NTP 连通性（需放行 UDP 123）&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>w32tm /stripchart /computer:time.windows.com /samples:5 /dataonly
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>如果客户端时间偏差超过 &lt;strong>15 分钟&lt;/strong>，Kerberos 认证将失败，导致无法登录域。此时需手动同步：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-batch" data-lang="batch">&lt;span style="display:flex;">&lt;span>w32tm /resync /force
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></content></item></channel></rss>