<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>运维 on Zhang's Notes</title><link>https://zhangsnotes.com/tags/%E8%BF%90%E7%BB%B4/</link><description>Recent content in 运维 on Zhang's Notes</description><generator>Hugo</generator><language>zh-CN</language><copyright>Zhang's Notes</copyright><lastBuildDate>Wed, 23 Sep 2026 11:54:59 +0800</lastBuildDate><atom:link href="https://zhangsnotes.com/tags/%E8%BF%90%E7%BB%B4/index.xml" rel="self" type="application/rss+xml"/><item><title>一些关于Ntp server的使用</title><link>https://zhangsnotes.com/posts/ntp/</link><pubDate>Wed, 23 Sep 2026 11:16:05 +0800</pubDate><guid>https://zhangsnotes.com/posts/ntp/</guid><description>整理阿里云、腾讯云内外网 NTP 服务器地址，以及 Linux 下用 chrony 做时间同步的配置与排障命令。</description><content:encoded><![CDATA[<p><img src="/posts/ntp/cover.webp" alt="cover"></p>
<h1 id="ntp">NTP</h1>
<h2 id="阿里云内网">阿里云内网</h2>
<div class="code-block">
  <div class="code-block-header">
    <span class="code-block-lang">text</span>
    <button type="button" class="code-copy" aria-label="Copy code">
      <span class="code-copy-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>
</span>
      <span class="code-copy-icon code-copy-icon-check"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
</span>
      <span class="code-copy-label">Copy</span>
    </button>
  </div>
  <pre tabindex="0"><code>ntp.cloud.aliyuncs.com
ntp7.cloud.aliyuncs.com
ntp8.cloud.aliyuncs.com
ntp9.cloud.aliyuncs.com
ntp10.cloud.aliyuncs.com
ntp11.cloud.aliyuncs.com
ntp12.cloud.aliyuncs.com</code></pre>
</div>
<h2 id="阿里云外网">阿里云外网</h2>
<div class="code-block">
  <div class="code-block-header">
    <span class="code-block-lang">text</span>
    <button type="button" class="code-copy" aria-label="Copy code">
      <span class="code-copy-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>
</span>
      <span class="code-copy-icon code-copy-icon-check"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
</span>
      <span class="code-copy-label">Copy</span>
    </button>
  </div>
  <pre tabindex="0"><code>ntp.aliyun.com
ntp1.aliyun.com
ntp2.aliyun.com
ntp3.aliyun.com
ntp4.aliyun.com
ntp5.aliyun.com
ntp6.aliyun.com
ntp7.aliyun.com</code></pre>
</div>
<h2 id="腾讯云内网">腾讯云内网</h2>
<div class="code-block">
  <div class="code-block-header">
    <span class="code-block-lang">text</span>
    <button type="button" class="code-copy" aria-label="Copy code">
      <span class="code-copy-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>
</span>
      <span class="code-copy-icon code-copy-icon-check"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
</span>
      <span class="code-copy-label">Copy</span>
    </button>
  </div>
  <pre tabindex="0"><code>time1.tencentyun.com
time2.tencentyun.com
time3.tencentyun.com
time4.tencentyun.com
time5.tencentyun.com</code></pre>
</div>
<h2 id="腾讯云外网">腾讯云外网</h2>
<div class="code-block">
  <div class="code-block-header">
    <span class="code-block-lang">text</span>
    <button type="button" class="code-copy" aria-label="Copy code">
      <span class="code-copy-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>
</span>
      <span class="code-copy-icon code-copy-icon-check"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
</span>
      <span class="code-copy-label">Copy</span>
    </button>
  </div>
  <pre tabindex="0"><code>ntp.tencent.com
ntp1.tencent.com
ntp2.tencent.com
ntp3.tencent.com
ntp4.tencent.com
ntp5.tencent.com</code></pre>
</div>
<h1 id="linux使用方案">linux使用方案</h1>
<blockquote>
<p>以下默认是centos和ubuntu，默认是先centOS，后ubuntu</p>
</blockquote>
<h3 id="安装chronyc">安装chronyc</h3>
<div class="code-block">
  <div class="code-block-header">
    <span class="code-block-lang">text</span>
    <button type="button" class="code-copy" aria-label="Copy code">
      <span class="code-copy-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>
</span>
      <span class="code-copy-icon code-copy-icon-check"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
</span>
      <span class="code-copy-label">Copy</span>
    </button>
  </div>
  <pre tabindex="0"><code>sudo yum install chrony
##
sudo apt install chrony</code></pre>
</div>
<h3 id="修改配置文件">修改配置文件</h3>
<p>文件位于 <code>/etc/chrony.conf</code> 或者 <code>/etc/chrony/chrony.conf</code>，下面是配置文件示例（腾讯云内网方案）：</p>
<div class="code-block">
  <div class="code-block-header">
    <span class="code-block-lang">text</span>
    <button type="button" class="code-copy" aria-label="Copy code">
      <span class="code-copy-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>
</span>
      <span class="code-copy-icon code-copy-icon-check"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
</span>
      <span class="code-copy-label">Copy</span>
    </button>
  </div>
  <pre tabindex="0"><code># drift 文件用于记录之前时钟频率调整（单位是ppm）
driftfile /var/lib/chrony/drift

# chronyd 开启后的前三次时间调整，且时间差超过1.0秒才跳变调整时间
makestep 1.0 3

# 允许内核定期将系统时间同步到 RTC 时间
rtcsync

# TAI-UTC offset 和闰秒的信息
leapsectz right/UTC

# 日志输出到/var/log/chrony
logdir /var/log/chrony
# 打印每个 ntp 包的 rawmeasurements，一般在调试或问题排查时使用
log rawmeasurements
# 打印 tracking 日志，用来记录系统时钟的整体状态
log tracking

# （可选）监听 NTP 端口（默认是 udp 123），作为 NTP server 向其他机器提供 NTP 服务
# allow all

# 配置 NTP 服务器
server time1.tencentyun.com iburst
server time2.tencentyun.com iburst
server time3.tencentyun.com iburst
server time4.tencentyun.com iburst
server time5.tencentyun.com iburst</code></pre>
</div>
<p>或者</p>
<div class="code-block">
  <div class="code-block-header">
    <span class="code-block-lang">text</span>
    <button type="button" class="code-copy" aria-label="Copy code">
      <span class="code-copy-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>
</span>
      <span class="code-copy-icon code-copy-icon-check"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
</span>
      <span class="code-copy-label">Copy</span>
    </button>
  </div>
  <pre tabindex="0"><code># 配置信息，包含了 NTP 服务器地址，最小轮询间隔，最大轮询间隔等信息。
server ntp.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp10.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp11.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp12.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp7.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp8.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp9.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst</code></pre>
</div>
<h3 id="启动-chrony">启动 chrony</h3>
<div class="code-block">
  <div class="code-block-header">
    <span class="code-block-lang">text</span>
    <button type="button" class="code-copy" aria-label="Copy code">
      <span class="code-copy-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>
</span>
      <span class="code-copy-icon code-copy-icon-check"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
</span>
      <span class="code-copy-label">Copy</span>
    </button>
  </div>
  <pre tabindex="0"><code>sudo systemctl restart chronyd  # 重启 chronyd 服务
sudo systemctl enable chronyd   # 开机自动启动 chronyd

###

sudo systemctl restart chrony  # 重启 chrony 服务
sudo systemctl enable chrony   # 开机自动启动 chrony</code></pre>
</div>
<h3 id="检查-chrony-状态">检查 chrony 状态</h3>
<div class="code-block">
  <div class="code-block-header">
    <span class="code-block-lang">text</span>
    <button type="button" class="code-copy" aria-label="Copy code">
      <span class="code-copy-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>
</span>
      <span class="code-copy-icon code-copy-icon-check"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
</span>
      <span class="code-copy-label">Copy</span>
    </button>
  </div>
  <pre tabindex="0"><code>systemctl status chronyd     # 查看 chronyd 服务状态，Active: active (running)表示正在运行
systemctl is-enabled chronyd # 查看 chronyd 是否开机自动启动，enabled 表示开机自动启动

### 

systemctl status chrony     # 查看 chrony 服务状态，Active: active (running)表示正在运行
systemctl is-enabled chrony # 查看 chrony 是否开机自动启动，enabled 表示开机自动启动</code></pre>
</div>
<h2 id="其他命令">其他命令</h2>
<div class="code-block">
  <div class="code-block-header">
    <span class="code-block-lang">text</span>
    <button type="button" class="code-copy" aria-label="Copy code">
      <span class="code-copy-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>
</span>
      <span class="code-copy-icon code-copy-icon-check"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
</span>
      <span class="code-copy-label">Copy</span>
    </button>
  </div>
  <pre tabindex="0"><code>chronyd -Q # 向 NTP 服务器查询当前时间差，不修改系统时间

chronyc sources -v # 查看时钟源的状态，有时钟源被星号*标记表示已同步
chronyc tracking   # 查看系统时钟状态</code></pre>
</div>
<h2 id="关于chronyc的其他内容">关于chronyc的其他内容</h2>
<p><strong>chronyc sources -v 指标简要说明</strong></p>
<p><code>M</code>：对端类型，<code>^</code>表示 server。</p>
<p><code>S</code>：<code>*</code>表示最优时钟源，<code>+</code>表示按统计方式（加权平均）合入系统时钟的调整，<code>-</code>表示未合入。</p>
<p><code>Name/IP Address</code>：时钟源的域名/IP。</p>
<p><code>Stratum</code>：表示时钟源的层级，正常取值1到15，16表示有异常。</p>
<p><code>Poll</code>：log2轮询间隔，poll=4表示轮询间隔是24秒，即16秒。</p>
<p><code>Reach</code>：表示近8个数据包的到达情况，八进制377表示近8个 ntp 包都没有丢。</p>
<p><code>LastRx</code>：距离上一次收到通过校验的 ntp 包过了多久。单位一般为秒，具体以界面显示为准。</p>
<p><code>Last sample</code>：用来衡量当前机器与时钟源的时间差，这里几个时间差是统计计算的中间结果。</p>
<p><strong>chronyc tracking 指标简要说明</strong></p>
<p><code>Reference ID</code>：最优时钟源域名/IP。</p>
<p><code>Stratum</code>：当前机器的层级。</p>
<p><code>Ref time</code>：上次从时钟源计算指标的时间。</p>
<p><code>System time</code>：非跳变调整的时间差。</p>
<p><code>Last offset</code>：上一次时间差，正数表示本地时钟比服务器时钟快。</p>
<p><code>RMS offset</code>：时间差的长期统计均值。</p>
<p><code>Frequency</code>：表示如果 chrony 不调整时钟，系统时钟频率会差多少。</p>
<p><code>Residual freq</code>：当前时钟频率与最优时钟源频率的差距。</p>
<p><code>Skew</code>：频率误差界。</p>
<p><code>Root delay</code>：到 stratum-1时钟源的 RTT（roud-time trip）。</p>
<p><code>Root dispersion</code>：到 stratum-1时钟源的固有误差。</p>
<p><code>Update interval</code>：两次时钟修正的间隔。</p>
<p><code>Leap status</code>：闰秒状态。</p>
]]></content:encoded></item></channel></rss>