参考 :
https://wenku.baidu.com/view/8a649980f624ccbff121dd36a32d7375a417c6f2.html
https://blog.csdn.net/zhong_jianyu/article/details/86220914#单个可行
CentOS7时间同步NTP服务安装及配置_Huber~的博客-CSDN博客_centos配置ntp时间同步
inappropriate address 172.18.74.119 for the fudge_weixin_33786077的博客-CSDN博客
1.下载依赖包
公网机器使用yum下载所有依赖包
# 安装yum-utils
yum -y install yum-utils
# 下载 ntp 全量依赖包
repotrack ntp
2.安装ntp
上传上个步骤下载的所有rpm包到内网所有机器,执行安装
rpm -Uvh --force --nodeps *.rpm
3.配置
3.1.ntp服务器
选一台机器为时钟源(若该机器ip为192.168.1.1),该机器修改 [/etc/ntp.conf] 文件
删除restrict和server开头配置,新增如下配置
restrict default nomodify
server 127.127.1.0
Fudge 127.127.1.0 stratum 10
3.2.ntp客户端
修改 [/etc/ntp.conf] 文件
删除server开头配置,新增如下配置(ip为ntp服务器ip)
server 192.168.1.1
4.启动ntp服务
所有机器执行
# 启动
service ntpd start
# 查看状态
service ntpd status
# 设置开机自启
chkconfig ntpd on
# 查看ntp时钟源
ntpq -p
# 查看ntp状态(手动同步时间一段时间后变成正常)
ntpstat
客户端执行同步时间
ntpdate -u 192.168.1.1
5.客户端设置定时同步时间
通过crontab定时任务定时同步时间
编辑定时任务
crontab -e
添加任务(每10分钟同步一次时间)
*/10 * * * * service ntpd start && /usr/sbin/ntpdate 192.168.1.1 >> /var/log/ntpdate.log
注 : 遇到过ntp会挂,定时任务可以这么设置
*/10 * * * * /usr/sbin/ntpdate 192.168.1.1 >> /var/log/ntpdate.log