解决ntp时间同步在重启后失效

虽然配置了开机自动启动,但是在系统重启后,ntp时间仍然同步失效。
查看ntp服务状态:

[root@hadoop1 etc]# service ntpd status
Redirecting to /bin/systemctl status  ntpd.service
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since 四 2019-12-05 16:46:34 CST; 5h 19min left
 Main PID: 8425 (code=exited, status=0/SUCCESS)

12月 03 21:31:27 hadoop1 ntpd[8425]: Listen normally on 6 ens192 fe80::41e1:b2b4:f43a:8715 UDP 123
12月 03 21:31:27 hadoop1 ntpd[8425]: Listening on routing socket on fd #23 for interface updates
12月 03 21:31:27 hadoop1 ntpd[8425]: inappropriate address 10.19.8.10 for the fudge command, line ignored
12月 03 21:31:27 hadoop1 ntpd[8425]: 0.0.0.0 c016 06 restart
12月 03 21:31:27 hadoop1 ntpd[8425]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
12月 03 21:31:27 hadoop1 ntpd[8425]: 0.0.0.0 c011 01 freq_not_set
12月 03 21:31:27 hadoop1 systemd[1]: Started Network Time Service.
12月 05 16:46:34 hadoop1 ntpd[8425]: ntpd exiting on signal 15
12月 05 16:46:34 hadoop1 systemd[1]: Stopping Network Time Service...
12月 05 16:46:34 hadoop1 systemd[1]: Stopped Network Time Service.

查看开机启动配置

[root@hadoop1 ntp]# systemctl is-enabled ntpd
enabled

从给出的信息可知ntp已被设置为开机启动,但是开机启动并未成功。一般引起这个问题的最为常见的原因是系统上安装了一个与NTP相冲突的工具:chrony。
查看chronyd开机启动配置,chrony已经被设置为enabled

[root@hadoop1 ntp]# systemctl is-enabled chronyd
enabled

解决方法:

  • stop chronyd.service
  • systemctl disable chronyd
[root@hadoop1 ntp]# systemctl stop chronyd.service
[root@hadoop1 ntp]# systemctl status chronyd.service
● chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

12月 05 16:46:34 hadoop1 chronyd[27426]: chronyd version 2.1.1 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +DEBUG +ASYNCDNS +IPV6 +SECHASH)
12月 05 16:46:34 hadoop1 chronyd[27426]: Frequency 2.073 +/- 0.059 ppm read from /var/lib/chrony/drift
12月 05 16:46:34 hadoop1 systemd[1]: Started NTP client/server.
12月 05 16:46:44 hadoop1 chronyd[27426]: Selected source 94.130.49.186
12月 05 16:46:44 hadoop1 chronyd[27426]: System clock wrong by -28896.132038 seconds, adjustment started
12月 05 08:45:08 hadoop1 chronyd[27426]: System clock was stepped by -28896.132038 seconds
12月 05 08:45:09 hadoop1 chronyd[27426]: Selected source 203.107.6.88
12月 05 11:36:39 hadoop1 chronyd[27426]: chronyd exiting
12月 05 11:36:39 hadoop1 systemd[1]: Stopping NTP client/server...
12月 05 11:36:39 hadoop1 systemd[1]: Stopped NTP client/server.
[root@hadoop1 ntp]# systemctl disable chronyd
Removed symlink /etc/systemd/system/multi-user.target.wants/chronyd.service.

再次开启ntp

[root@hadoop6 ~]# service ntpd start
Redirecting to /bin/systemctl start  ntpd.service
您在 /var/spool/mail/root 中有新邮件
[root@hadoop6 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 10.19.8.10      .INIT.          16 u    -   64    0    0.000    0.000   0.000
[root@hadoop6 ~]# systemctl status ntpd
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
   Active: active (running) since 四 2019-12-05 11:42:34 CST; 2min 56s ago
  Process: 4760 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 4761 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─4761 /usr/sbin/ntpd -u ntp:ntp -g

12月 05 11:42:34 hadoop6 ntpd[4761]: Listen and drop on 1 v6wildcard :: UDP 123
12月 05 11:42:34 hadoop6 ntpd[4761]: Listen normally on 2 lo 127.0.0.1 UDP 123
12月 05 11:42:34 hadoop6 ntpd[4761]: Listen normally on 3 ens192 10.19.8.8 UDP 123
12月 05 11:42:34 hadoop6 ntpd[4761]: Listen normally on 4 virbr0 192.168.122.1 UDP 123
12月 05 11:42:34 hadoop6 ntpd[4761]: Listen normally on 5 lo ::1 UDP 123
12月 05 11:42:34 hadoop6 ntpd[4761]: Listening on routing socket on fd #22 for interface updates
12月 05 11:42:34 hadoop6 ntpd[4761]: inappropriate address 10.19.8.10 for the fudge command, line ignored
12月 05 11:42:34 hadoop6 ntpd[4761]: 0.0.0.0 c016 06 restart
12月 05 11:42:34 hadoop6 ntpd[4761]: 0.0.0.0 c012 02 freq_set kernel 0.008 PPM
12月 05 11:42:34 hadoop6 systemd[1]: Started Network Time Service.

参考:https://blog.csdn.net/bluishglc/article/details/41452923

你可能感兴趣的:(环境搭建)