Ntp客户端无法同步到ntp服务器

时间:2018-03-20 06:09:04

标签: centos7 ntp ntpd

我在centos7上设置了一个ntp服务器。它运行ntpd服务。我在下面发布了配置,它基本上尝试同步到centos池组织服务器(配置中存在默认的服务器),如果失败,它会尝试将时钟设置为它自己的本地时间,如果服务器在没有Internet访问的情况下运行的话。我也有ntp客户端的从属节点和我的ntp服务器同步时间。重点是让我的整个集群保持同步,无论它是否可以与ntp.pool.org成员联系。如果它可以很好,如果没有,所有主机必须在时间上同步。

  

192.168.50.4 - > ntp服务器(node1)

     

192.168.50.5 - > ntp客户端(node2)

我运行的问题是当我在客户端(node2)上运行此命令时,我的ntp客户端拒绝强制与ntp服务器同步,并出现以下错误:

$ sudo ntpd -gqd
ntpd 4.2.6p5@1.2349-o Wed Apr 12 21:24:06 UTC 2017 (1)
20 Mar 02:43:29 ntpd[18010]: proto: precision = 0.063 usec
20 Mar 02:43:29 ntpd[18010]: 0.0.0.0 c01d 0d kern kernel time sync enabled
event at 0 0.0.0.0 c01d 0d kern kernel time sync enabled
Finished Parsing!!
restrict: op 1 addr 0.0.0.0 mask 0.0.0.0 mflags 00000000 flags 000001d0
restrict: op 1 addr :: mask 0.0.0.0 mflags 00000000 flags 000001d0
restrict: op 1 addr 127.0.0.1 mask 255.255.255.255 mflags 00000000 flags 00000000
restrict: op 1 addr ::1 mask ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff mflags 00000000 flags 00000000
20 Mar 02:43:29 ntpd[18010]: ntp_io: estimated max descriptors: 64000, initial socket boundary: 16
20 Mar 02:43:29 ntpd[18010]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 123
20 Mar 02:43:29 ntpd[18010]: Listen and drop on 1 v6wildcard :: UDP 123
20 Mar 02:43:29 ntpd[18010]: Listen normally on 2 lo 127.0.0.1 UDP 123
restrict: op 1 addr 127.0.0.1 mask 255.255.255.255 mflags 00003000 flags 00000001
20 Mar 02:43:29 ntpd[18010]: Listen normally on 3 eth0 10.0.2.15 UDP 123
restrict: op 1 addr 10.0.2.15 mask 255.255.255.255 mflags 00003000 flags 00000001
20 Mar 02:43:29 ntpd[18010]: Listen normally on 4 eth1 192.168.50.5 UDP 123
restrict: op 1 addr 192.168.50.5 mask 255.255.255.255 mflags 00003000 flags 00000001
20 Mar 02:43:29 ntpd[18010]: Listen normally on 5 lo ::1 UDP 123
restrict: op 1 addr ::1 mask ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff mflags 00003000 flags 00000001
20 Mar 02:43:29 ntpd[18010]: Listen normally on 6 eth0 fe80::a00:27ff:fe2d:3fba UDP 123
restrict: op 1 addr fe80::a00:27ff:fe2d:3fba mask ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff mflags 00003000 flags 00000001
20 Mar 02:43:29 ntpd[18010]: Listen normally on 7 eth1 fe80::a00:27ff:fed1:69a2 UDP 123
restrict: op 1 addr fe80::a00:27ff:fed1:69a2 mask ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff mflags 00003000 flags 00000001
20 Mar 02:43:29 ntpd[18010]: Listening on routing socket on fd #24 for interface updates
key_expire: at 0 associd 15167
peer_clear: at 0 next 1 associd 15167 refid INIT
event at 0 192.168.50.4 8011 81 mobilize assoc 15167
newpeer: 192.168.50.5->192.168.50.4 mode 3 vers 4 poll 6 10 flags 0x101 0x1 ttl 0 key 00000000
20 Mar 02:43:29 ntpd[18010]: 0.0.0.0 c016 06 restart
event at 0 0.0.0.0 c016 06 restart
20 Mar 02:43:29 ntpd[18010]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
event at 0 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
20 Mar 02:43:29 ntpd[18010]: 0.0.0.0 c011 01 freq_not_set
event at 0 0.0.0.0 c011 01 freq_not_set
transmit: at 1 192.168.50.5->192.168.50.4 mode 3 len 48
auth_agekeys: at 1 keys 1 expired 0
receive: at 1 192.168.50.5<-192.168.50.4 mode 4 len 48
packet: flash header 1620
transmit: at 3 192.168.50.5->192.168.50.4 mode 3 len 48
receive: at 3 192.168.50.5<-192.168.50.4 mode 4 len 48
packet: flash header 1620
transmit: at 5 192.168.50.5->192.168.50.4 mode 3 len 48
receive: at 5 192.168.50.5<-192.168.50.4 mode 4 len 48
packet: flash header 1620
transmit: at 7 192.168.50.5->192.168.50.4 mode 3 len 48
receive: at 7 192.168.50.5<-192.168.50.4 mode 4 len 48
packet: flash header 1620
transmit: at 9 192.168.50.5->192.168.50.4 mode 3 len 48
receive: at 9 192.168.50.5<-192.168.50.4 mode 4 len 48
packet: flash header 1620
20 Mar 02:43:40 ntpd[18010]: ntpd: no servers found
ntpd: no servers found

我在ntp.conf(node1)中的ntp服务器配置中所做的唯一更改:

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
server  127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10

为什么我放最后两行。这样ntpd服务器就会回归到它自己的时间。正如我之前提到的,我只关心群集中的所有主机在它们之间同步。

我的ntp客户端(node2)配置(目前在vagrant中测试):

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 192.168.50.4 iburst

这里我将我的ntp客户端指向我的ntp服务器。他们应该盲目地从ntp服务器上获取时间。

已正确配置所有必需的防火墙设置。我实际上可以在ntp客户端上成功运行ntpdate -d 192.168.50.4。但是当我运行ntpd -gq,因为不推荐使用ntpdate我得到了这个错误,没有找到服务器。

一段时间后,我的ntp服务器上的ntpd由于恐慌停止而崩溃:

sudo systemctl status ntpd -l
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2018-03-20 02:50:36 UTC; 56min ago
  Process: 20148 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 20149 (code=exited, status=255)

Mar 20 02:36:46 node1 ntpd[20149]: 0.0.0.0 0612 02 freq_set kernel 1042.779 PPM
Mar 20 02:36:46 node1 ntpd[20149]: 0.0.0.0 061c 0c clock_step +1.118902 s
Mar 20 02:36:48 node1 ntpd[20149]: 0.0.0.0 c618 08 no_sys_peer
Mar 20 02:41:29 node1 ntpd[20149]: Deleting interface #7 eth0, fe80::a00:27ff:fe2d:3fba#123, interface stats: received=0, sent=0, dropped=0, active_time=1360 secs
Mar 20 02:41:31 node1 ntpd[20149]: Listen normally on 8 eth0 fe80::a00:27ff:fe2d:3fba UDP 123
Mar 20 02:41:31 node1 ntpd[20149]: new interface(s) found: waking up resolver
Mar 20 02:50:36 node1 ntpd[20149]: 0.0.0.0 c617 07 panic_stop +8381 s; set clock manually within 1000 s.
Mar 20 02:50:36 node1 systemd[1]: ntpd.service: main process exited, code=exited, status=255/n/a
Mar 20 02:50:36 node1 systemd[1]: Unit ntpd.service entered failed state.
Mar 20 02:50:36 node1 systemd[1]: ntpd.service failed.

我在ansible中的步骤 - 在所有主机上安装ntpd - 在服务器和客户端上放置适当的ntp.conf以指向服务器 - 在ntp服务器上运行ntpd -gq - 在我的ntp服务器上启用并启动ntpd - 在ntp客户端上运行ntpd -gq(失败)&lt; - 与ntpdate -d一起使用 - 在我的ntp客户端上启用并启动ntpd

我真的不知道为什么会发生这种情况,并希望得到任何帮助。谢谢。

1 个答案:

答案 0 :(得分:0)

如果系统时间已经过去,那么除非您强制执行更新,否则ntpd将不会更新时间...

关闭NTP服务

$ sudo service ntpd stop

从远程NTP服务器强制更新

$ sudo ntpdate 0.centos.pool.ntp.org

重新启动NTP服务

 $ sudo service ntpd start