NTP 同步问题

1.ntpq -p
查看 ntp 服务器与上层 ntp 服务器的状态:ntpq

[root@data01 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 61-216-153-104. 211.22.103.157   3 u 213m 1024    0  110.694   47.411   0.000
+ntp3.itcomplian 10.6.30.8        6 u  163 1024  157  408.690  -71.435  35.453
 gus.buptnet.edu 10.3.8.150       5 u  206 1024  331   11.849   -2.486  31.750
*ntp.wdc1.us.lea 130.133.1.10     2 u  417 1024  377  241.163  -12.288  18.173
  
# 其中:
# remote - 本机和上层ntp的ip或主机名,“+”表示优先,“*”当前所用的同步服务器
# refid  - 参考上一层ntp主机地址
# st     - stratum阶层
# when   - 上一次校正时间与现在时间的差值。
# poll   - 本地和远程服务器多少时间进行一次同步,单位秒,在一开始运行NTP的时候这个poll值会比较小,服务器同步的频率大,可以尽快调整到正确的时间范围,之后poll值会逐渐增大,同步的频率也就会相应减小
# reach  - 是一种衡量前8次查询是否成功的位掩码值,377表示都成功,0表示不成功。
# delay  - 网络延时,单位是10的-6次方秒。
# offset - 本地NTP服务器与远程NTP服务器的时间偏移。
# jitter - 统计了在特定个连续的连接数里offset的分布情况。简单地说这个数值的绝对值越小,主机的时间就越精确
 
如果所有远程服务器的jitter值是4000并且delay和reach的值是0,那么说明时间同步是有问题的。

2.ntptime
该命令返回错误,会导致 kudu 挂掉

root@data01 ~]# ntptime
ntp_gettime() returns code 0 (OK)
  time ddc7b43c.647b02b0  Tue, Nov 28 2017 18:09:00.392, (.392502425),
  maximum error 1274517 us, estimated error 24500 us, TAI offset 0
ntp_adjtime() returns code 0 (OK)
  modes 0x0 (),
  offset -28966.227 us, frequency 22.090 ppm, interval 1 s,
  maximum error 1274517 us, estimated error 24500 us,
  status 0x2001 (PLL,NANO),
  time constant 10, precision 0.001 us, tolerance 500 ppm,
 
[sa_cluster@BJSH-DATAHARBINGER-138-125 ~]$ ntptime
ntp_gettime() returns code 5 (ERROR)
  time ddc8bcde.563a4000  Wed, Nov 29 2017 12:58:06.336, (.336826),
  maximum error 16000000 us, estimated error 16 us, TAI offset 0
ntp_adjtime() returns code 5 (ERROR)
  modes 0x0 (),
  offset 0.000 us, frequency 0.000 ppm, interval 1 s,
  maximum error 16000000 us, estimated error 16 us,
  status 0x4041 (PLL,UNSYNC,MODE),
  time constant 7, precision 1.000 us, tolerance 500 ppm,
 
# returns code: 0 表示同步正常, 5 表示同步失败
# 它使用ntp_gettime() 系统调用读取并显示与时间相关的内核变量

3.ntp 日志

/var/log/ntp.log
/var/log/messages

4.以本地时间作为时间服务

# 在 /etc/ntp.conf 配置
server  127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10

5.硬件时钟

# 显示硬件时钟
hwclock -r
# 系统时钟写入bios
hwcloc -w

6./etc/sysconfig/ntpd

# ntpd同时把时间同步到bios
SYNC_HWCLOCK=yes
# Drop root to id 'ntp:ntp' by default.
OPTIONS="-x -u ntp:ntp -p /var/run/ntpd.pid -g"
 
应该去掉-x参数,否则会造成ntptime error(具体原因不详)
OPTIONS="-x -u ntp:ntp -p /var/run/ntpd.pid -g"

7.ucloud机器ntp error解决方法
如何确认是 ucloud 机器?搜索一下 yum 源。

grep 'ucloud.cn' /etc/yum.repos.d/CentOS-Base.repo

修改 ntp.conf 注释掉 以下几行

tinker dispersion 100
tinker step 1800
tinker stepout 3600

或者直接

sed -i 's/tinker/#tinker/g' /etc/ntp.conf

最后重启 ntp 服务
sudo service ntpd restart

发布了8 篇原创文章 · 获赞 0 · 访问量 40

猜你喜欢

转载自blog.csdn.net/Abson_Lu/article/details/104519355