美文网首页
如何在 Linux 下确认 NTP 是否同步?

如何在 Linux 下确认 NTP 是否同步?

作者: 87d6dc4b11a7 | 来源:发表于2022-11-30 22:21 被阅读0次

NTP 即Network Time Protocol,它通过网络同步计算机系统之间的时钟。NTP 服务器可以使组织中的所有服务器保持同步,以便在组织中准确执行基于时间的作业。NTP 客户端会将其时钟与 NTP 服务器同步。

NTP的同步状态可以通过以下三个命令来验证:
ntpq:ntpq 是标准的 NTP 查询程序。
ntpstat:显示网络时间同步的状态。
timedatectl:它控制 systemd 系统中的系统时间和日期。

方法 1:如何使用 ntpq 命令检查 NTP 状态?
ntpq 命令用于监控NTP守护进程并确定其性能,可以通过查询主机上运行的NTP服务器来确定。
该程序可以在交互模式运行,也可以通过使用命令行参数运行。如果 NTP 正常工作,你将获得类似于下面的输出。

# ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*CentOS7.linux 133.243.238.163  2 u   14   64   37    0.686    0.151  16.432

-p:打印服务器已知的对等项列表以及其状态摘要。

方法 2:如何使用 ntpstat 命令检查 NTP 状态?
ntpstat 将报告在本地计算机上运行的 NTP 守护程序(ntpd)的同步状态。如果发现本地系统与参考时间源保持同步,则 ntpstat 将报告近似的时间精度。
ntpstat 命令根据 NTP 同步情况返回三种状态码。详情如下。
0:如果时钟同步,则返回 0。
1:如果时钟不同步,则返回 1。
2:如果时钟状态不确定,则返回 2,例如 ntpd 不可联系时。

# ntpstat

synchronised to NTP server (192.168.1.8) at stratum 3
   time correct to within 508 ms
   polling server every 64 s

方法 3:如何使用 timedatectl 命令检查 NTP 状态?
timedatectl 命令用于查询和更改系统时钟及其在 systmed 系统中的设置。

# timedatectl
or
# timedatectl status

      Local time: 四 2022-12-01 22:17:58 CST
  Universal time: 四 2022-12-01 14:17:58 UTC
        RTC time: 四 2022-12-01 14:17:58
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

原文链接:https://www.2daygeek.com/check-ntp-sync-status-linux/

相关文章

网友评论

      本文标题:如何在 Linux 下确认 NTP 是否同步?

      本文链接:https://www.haomeiwen.com/subject/cfvsfdtx.html