一、下载ntp、ntpdate
yum install -y ntp ntpdate
二、配置ntp
vim /etc/ntp.conf
修改:
#203.107.6.88 ntp.aliyun.com
server 203.107.6.88
#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
vim /etc/sysconfig/ntpd
修改:
# Drop root to id 'ntp:ntp' by default.
#-x 微调 -g 忽略相差时间过大(1000s),如果相差时间过大1000s,下层ntpd会死掉
#OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
OPTIONS="-x -u ntp:ntp -p /var/run/ntpd.pid"
SYNC_HWCLOCK=yes
-g 忽略相差时间过大(1000s),如果相差时间过大1000s,下层ntpd会死掉。
强烈建议:先执行ntpdate手动同步时间!!!
另外:ntpd服务运行状态,无法执行ntpdate命令。
date
ntpdate 203.107.6.88
hwclock -w
date
三、开机启动
systemctl enable ntpd
systemctl status ntpd
systemctl start ntpd
四、防火墙设置
firewall-cmd --zone=public --add-port=123/udp --permanent
firewall-cmd --reload
五、测试与上层ntp的连通性
ntpstat
watch ntpq -p