ntpdate 和 ntpd同时打开,会导致ntpdate同步时间有误

Issue Description

客户遇到一个问题,在ntpdate时,同步时间总会出现错误

Analysis

这个问题在平台上复现不到,初步有怀疑为网络问题

不过,我有在log里看到下面这个让我比较介意:

16 Jul 10:17:11 ntpdate[522]: the NTP socket is in use, exiting

这是调用ntpdate之后打印的log

但是在我复现这个问题的时候,一直没有这个error打印

后来查询资料,在打开ntpd的时候,再去ntpdate,会报这个错误

然后我就猜测客户平台可能打开了ntpd

为了验证猜测,我先打开了ntpd

$ ntpd –q pool.ntp.org&

然后又开了三次ntpdate

ntpdate pool.ntp.org&

果然复现了客户一样的问题

 

第一次ntpdate是打印那个error,后面success的时间是错误的

然后,就向客户确认是否平台中有ntpd进程

经确认,的确平台中有ntpd进程先启动了导致了与ntpdate冲突

Solution

ntpd同步时间是加快时间流速的方法,

而ntpdate是越变,详细查阅ntp的官方说明文档。

可以通过增加 -u 选项,即可解决ntpd 与ntpdate冲突问题

即 ntpdate -u pool.ntp.org

-u 选项的具体说明如下:

Direct ntpdate to use an unprivileged port for outgoing packets. This  is  most  useful  when behind  a firewall that blocks incoming traffic to privileged ports, and you want to synchronize with hosts beyond the firewall. Note that the -d option always uses unprivileged  ports.

不在使用默认端口 而是选择了一个其他的端口,经测试,没有出现过该问题

建议ntpdate 和 ntpd的使用方法是

在开机时 使用ntpdate同步时间, 在机器运行过程中 用ntpd命令同步时间

猜你喜欢

转载自blog.csdn.net/qq_28351465/article/details/82995616