1.下载安装与依赖包
下载地址: https://pan.baidu.com/s/1T9BAcCqSKB64Xi-Xei8H0g
2.上传与解压
将安装上传并解压到 /var/cache/apt目录下
3.安装ntpdate与相关依赖
cd /var/cache/apt/archives
dpkg -i libopts25_5.18.7-3_amd64.deb
dpkg -i libssl1.0.0_1.0.2g-1ubuntu4.13_amd64.deb
dpkg -i ntp_1%3a4.2.6.p3+dfsg-1ubuntu3.1_amd64.deb
dpkg -i ntpdate_4.2.8p4+dfsg-3ubuntu5.9_amd64.deb
dpkg -i ntpstat_0.0.0.1-1_amd64.deb
4.修改ntpdate的配置
vim /etc/ntp.conf
将ntp.conf中的内容替换成下面的内容:
##下面两行默认是拒绝所有来源的任何访问
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
#开放本机的任何访问
restrict 192.168.13.81
restrict 192.168.13.83
restrict 127.0.0.1
restrict -6 ::1
#允许内网其他机器同步时间(允许192.168.1.0/24 网段主机进行时间同步)
restrict 192.168.1.0 mask 255.255.255.0 nomodify
#指定ntp服务器地址
server 192.168.11.25 prefer
#外部时间服务器不可用时,以本地时间作为时间服务
server 127.127.1.0
fudge 127.127.1.0 stratum 10
##下面两行为配置文件默认开启
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys
5.启动192.168.11.25
/etc/init.d/ntp start 或者 systemctl start ntp
6.查看启动的进程
ps -ef | grep ntp
7.其他机器同步192.168.11.25的时间
192.168.13.81与192.168.13.83同步192.168.11.25的时间。
7.1 192.168.13.81与192.168.13.83不需要启动ntpdate服务,如果启动会同步不成功,执行ntpdate 192.168.11.25时显示:
如果启动了ntpdate服务则采用 /etc/init.d/ntp stop或者 systemctl stop ntp
停止服务。
7.2 192.168.11.25中ntpdate服务必须启动
同步时间时,在192.168.13.81与192.168.13.83执行
ntpdate 192.168.11.25
8.验证3台时间是否一直
采用分窗口模式同时执行date
9.设置定时任务每5分钟同步一下192.168.11.25的时间
在 192.168.13.81与192.168.13.83执行crontab -e
增加下面内容,保存即可。
*/5 * * * * ntpdate 192.168.11.25 >> /dev/null 2>&1 &