美文网首页
ntp对时无效问题排查

ntp对时无效问题排查

作者: HellWord | 来源:发表于2023-01-30 10:05 被阅读0次

一、描述

CentOS 7 配置ntp时,在ntp.conf中配置server 10.10.192.1 iburstserver 10.10.192.3 iburst,同时执行systemctl start ntpd启动对时服务,但是在第二天执行date查看时,服务器时钟仍然存在一天的误差,ntp对时居然无效。

[root@localhost ~]# date
2023-01-30 01:02:25
#实际时间是2023-01-31才对
#此处date显示的内容是因为执行过alias date="date '+%Y-%m-%d %H:%M:%S'"

二、排查过程:时区显示的问题

  1. 从ntp配置方面排查了多次没有发现问题。

  2. 查看/var/log/message中ntp日志,发现具有对时操作,ntp服务正常

Jan 30 01:02:11 localhost ntpd[10398]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
Jan 30 01:02:11 localhost ntpd[10398]: 0.0.0.0 c011 01 freq_not_set
Jan 30 01:02:19 localhost ntpd[10398]: 0.0.0.0 c61c 0c clock_step +0.947240 s
Jan 30 01:02:19 localhost ntpd[10398]: 0.0.0.0 c614 04 freq_mode
Jan 30 01:02:20 localhost ntpd[10398]: 0.0.0.0 c618 08 no_sys_peer
Jan 30 01:17:41 localhost ntpd[10398]: 0.0.0.0 c612 02 freq_set kernel 2.066 PPM
Jan 30 01:17:41 localhost ntpd[10398]: 0.0.0.0 c615 05 clock_sync

  1. 执行ntpstat查看状态,由于长时间对时,当前对时周期为1024秒

[root@localhost ~]# ntpstat 
unsynchronised
   polling server every 1024 s
  1. 百思不得其解之时,上网寻求帮助,看到一篇文章提示,要注意时区是否一致。随后使用原始的date命令查看:
[root@localhost ~]# unalias date
[root@localhost ~]# date
Mon Jan 30 20:19:46 EST 2023

注意到上面的时区是”EST“,这是Eastern Standard Time东部标准时间,主要用于北美。我国用的时间是中国标准时间CST(China Standard Time)

三、问题解决:修改时间时区

查看当前系统设置的时区

ba[root@localhost ~]# ll /etc/localtime 
lrwxrwxrwx. 1 root root 38 2021-08-25 04:51:23 /etc/localtime -> ../usr/share/zoneinfo/America/New_York
[root@localhost ~]# echo $TZ

[root@localhost ~]# timedatectl 
      Local time: Mon 2023-01-30 20:33:31 EST
  Universal time: Tue 2023-01-31 01:33:31 UTC
        RTC time: Tue 2023-01-31 01:33:31
       Time zone: America/New_York (EST, -0500)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: no
 Last DST change: DST ended at
                  Sun 2022-11-06 01:59:59 EDT
                  Sun 2022-11-06 01:00:00 EST
 Next DST change: DST begins (the clock jumps one hour forward) at
                  Sun 2023-03-12 01:59:59 EST
                  Sun 2023-03-12 03:00:00 EDT
[root@localhost ~]# date -R
Mon, 30 Jan 2023 20:34:03 -0500
#可以通过timedatectl list-timezones查看系统当前支持的时区

设置时区

  1. 声明变量,该方法仅是修改当前会话的时区,在重新登录时失效
[root@eas-heq61-12-12-46 ~]# export TZ="Asia/Shanghai"
[root@eas-heq61-12-12-46 ~]# date
Tue Jan 31 09:30:46 CST 2023

  1. 使用命令:timedatectl ,永久有效
[root@localhost ~]# date
Mon Jan 30 20:36:53 EST 2023
[root@localhost ~]# timedatectl 
      Local time: Mon 2023-01-30 20:38:21 EST
  Universal time: Tue 2023-01-31 01:38:21 UTC
        RTC time: Tue 2023-01-31 01:38:21
       Time zone: America/New_York (EST, -0500)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: no
 Last DST change: DST ended at
                  Sun 2022-11-06 01:59:59 EDT
                  Sun 2022-11-06 01:00:00 EST
 Next DST change: DST begins (the clock jumps one hour forward) at
                  Sun 2023-03-12 01:59:59 EST
                  Sun 2023-03-12 03:00:00 EDT
[root@localhost ~]# timedatectl set-timezone Asia/Shanghai
[root@localhost ~]# date
Tue Jan 31 09:38:39 CST 2023
[root@localhost ~]# timedatectl 
      Local time: Tue 2023-01-31 09:38:47 CST
  Universal time: Tue 2023-01-31 01:38:47 UTC
        RTC time: Tue 2023-01-31 01:38:47
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a
[root@localhost ~]# ll /etc/localtime 
lrwxrwxrwx 1 root root 35 Jan 31 09:38 /etc/localtime -> ../usr/share/zoneinfo/Asia/Shanghai

相关文章

  • ntp对时

    1 手动设置date命令:date :查看当前时间,结果如下:Wed Feb 4 16:29:51 CST 20...

  • 2018-04-16

    Linux对时 在NTP服务器上,即一般都是用于对时的前置服务器,修改/etc/ntp/ntp.conf,在该文件...

  • Linux校对时间

    linux服务器校对时间方法 Linux中有个ntp包可以自动校准时间,并且非常好用。 Debian系统安装NTP...

  • NTP校时

    小僧很想和同行的朋友沟通交流、并肩前行,志同道合的朋友看过来喽! NTP对时 NTP Server端 右击“我的电...

  • [Android Things] 设置自动对时服务器

    Android things内置的自动对时NTP服务器在国内无法访问,所以每次开机后时间都是2009.1.1 00...

  • 03-MongoDB集群运维-NTP时间同步

    背景 使用 NTP时间同步操作,避免出现因时间不一致导致集群间数据同步问题 NTP时间同步 测试NTP常用服务器是...

  • Centos 7.4 升级 NTP 到 4.2.8p12

    升级ntp主要是为了解决系统安全问题: 因为 centos7.4系统中默认安装的是 ntp ...

  • Linux 遇到ntpdate[****]: the NTP s

    有时候linux下时间同步会碰见the NTP socket is use.的问题,这个是因为NTP服务正在运行的...

  • web的时间戳与NTP

    1、滴答滴答滴 :(就是平台相关的计算ns时间,记住是相对时间哦) 2、webrtc 开机计算一次 NTP矫正时间...

  • 北斗邦泰:CDMA时钟同步服务器提供商!

    CDMA时钟同步服务器提供商! CDMA时钟同步服务器(CDMA对时服务器,CDMA网络校时器,NTP授时器)是我...

网友评论

      本文标题:ntp对时无效问题排查

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