ntp同步异常问题解决方案

一、将node1作为ntp服务端

1.1、设置node1与硬件时钟同步:

#先确保时钟正确,在正确的前提下写入硬件时钟
sudo hwclock -w
#再查看硬件时间否正常
sudo hwclock --show
#在开机脚本中设置开机后自动与硬件时钟同步,将原来的'hwclock --systohc'注释
hwclock --hctosys 
#在root用户下添加crontab定时任务,每天凌晨1点对一次时
crontab -e
0 1 * * *  /usr/sbin/hwclock --hctosys

1.2、设置node1的ntp服务输出日志

#修改/etc/sysconfig/ntpd文件,内容如下
OPTIONS="-g -l /data/log/ntpstats/ntpd.log"
SYNC_HWCLOCK=yes
#创建日志文件
sudo mkdir /data/log/ntpstats
sudo touch /data/log/ntpstats/ntpd.log
#创建完成后重启ntp服务
sudo systemctl restart ntpd

1.3、统一node1的/etc/ntp.conf文件,如不同,请修改

driftfile /var/lib/ntp/drift
server 127.127.1.0
fudge 127.127.1.0 stratum 10
restrict 127.0.0.1
restrict -6 ::1
restrict -6 default nomodify notrap noquery
restrict :: default nomodify notrap noquery
restrict default nomodify notrap noquery
disable monitor

1.4、修改其他节点的/etc/ntp.conf文件,完整内容如下,如不同,请修改

driftfile /var/lib/ntp/drift
restrict 127.0.0.1
restrict -6 ::1
server node1 prefer minpoll 3 maxpoll 3
restrict node1
restrict node1 nomodify notrap noquery
restrict -6 default nomodify notrap noquery
restrict :: default nomodify notrap noquery
restrict default nomodify notrap noquery
disable monitor

新增最后一句目的是允许上层时间服务器主动修改本机时间

1.5、重启其他节点的ntp服务

sudo systemctl restart ntpd

1.6、设置其他节点的chrony与node1同步,修改 /etc/chrony.conf文件,具体如截图所示

在这里插入图片描述

#注释原来的server,添加node1作为server
server node1 iburst
#修改完成后重启chrony
sudo systemctl stop chronyd
sudo chronyd -q 'server node1 iburst'
sudo systemctl start chronyd

二、异常解决

如仍不能解决时钟偏移问题,则只能采用定时对时措施

#在root用户下添加crontab定时任务,每天凌晨1点对一次时
0 1 * * * /usr/sbin/ntpdate -u node1

猜你喜欢

转载自blog.csdn.net/xfp1007907124/article/details/132606882
今日推荐