> 文章列表 > ntpdate命令执行 the NTP socket is in use, exiting

ntpdate命令执行 the NTP socket is in use, exiting

ntpdate命令执行 the NTP socket is in use, exiting

描述:

在做paas平台的巡检的时发现了宿主机上的时间同步有异常,提示与master节点的心跳检测相差7分钟,并且是遇见了好几台服务器,根据系统的要求,需要将集群下所有宿主机的时间保持在一个时间点,根据运维习惯去查询cron的定时任务配置:

# crontab -l

[root@sltpro-monitor-01 ~]# crontab -l
#Ansible: #Ansible: time
*/5 * * * * /usr/sbin/ntpdate 172.36.5.234

然后执行在去执行时间同步的命令

/usr/sbin/ntpdate 172.36.5.234

但是执行之后却遇到了“the NTP socket is in use, exiting”的问题,具体显示如下:

21 Sep 14:39:09 ntpdate[24744]: the NTP socket is in use, exiting

分析: 

根据运维习惯,首先去ntp服务器上查看时间是否准确,登入到172.36.5.234的服务器上执行date发现时间是没有问题的,说明时间同步的源端是没有问题的,有问题的是ntp的客户端存在异常的。

根据提示的信息,查询发现原因如下:

到此错误消息的原因是由于 xntpd 已经绑定到了该 Socket。运行 ntpdate 时,它会首先进行广播,然后侦听端口 123。

[root@SZDX-DNS-1 bin]# ps -ef|grep xntpd
root     124185   6192  0 15:49 pts/1    00:00:00 grep xntpd
可惜没有找到pid。

没有lsof命令的话:yum install -y lsof 

lsof -i:123
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
ntpd    124171  ntp   16u  IPv4 420557      0t0  UDP *:ntp 
ntpd    124171  ntp   17u  IPv6 420558      0t0  UDP *:ntp 
ntpd    124171  ntp   18u  IPv6 420562      0t0  UDP localhost:ntp 
ntpd    124171  ntp   19u  IPv6 420563      0t0  UDP [fe80::1251:72ff:fe31:f52b]:ntp 
ntpd    124171  ntp   20u  IPv6 420564      0t0  UDP [fe80::6a91:d0ff:fe60:a9d4]:ntp 
ntpd    124171  ntp   21u  IPv4 420565      0t0  UDP localhost:ntp 
ntpd    124171  ntp   22u  IPv4 420566      0t0  UDP 218.94.214.29:ntp 

解决:

这里主要有两种方式

方式一:是直接kill掉123端口的进程

[root@spark1 bin]# kill -9 12417
[root@spark11 bin]# ntpdate 192.168.100.120
13 Apr 09:08:36 ntpdate[124200]: step time server 192.168.100.120 offset -24096.422190 sec
[root@spark1 bin]# date

这样就能同步到最新的时间,并且与时间服务的时间保持一致了。

方式二:是停止掉ntpd服务

[root@esx4 ~]# service ntpd stop
Shutting down ntpd:                                        [  OK  ][root@esx4 ~]# ntpdate ntp.api.bz
21 Sep 15:22:43 ntpdate[25723]: step time server 114.80.81.1 offset 2312.159684 sec

注:ntpd同步时间服务是运维中常见的问题,为此可以帮到大家,麻烦动动小手点赞加关注!!