#/bin/sh
ntps=192.168.199.0
mainEng=xxx.xx.xxx.xxxx
#关闭防火墙和selinux
service iptables stop &>/dev/null
setenforce 0 &>/dev/null
echo "安装ntp服务服务端"
cd /opt
echo "离线安装ntp"
rpm -ivh ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm
echo "修改ntp配置文件"
echo "# 记录和上游服务器时间差的文件
driftfile /var/lib/ntp/drift
# 对于默认的client拒绝所有操作,下面的restrict开通指定权限
restrict default nomodify notrap nopeer noquery
#允许本机地址的一切操作
restrict 127.0.0.1
restrict ::1
#允许192.168.199段机器同步时间,指定可以和ntp通信的ip或者网段
restrict ${ntps} mask 255.255.255.0 nomodify notrap
server ${mainEng}
server 127.127.1.0 iburst
fudge 127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
" >/etc/ntp.conf
systemctl start ntpd
systemctl enable ntpd
ntpq -p
echo="定时任务"
NTP_SERVER=cn.poolntp.org
NTP_DATE="/usr/sbin/ntpdate"
#crontab -e 一般会在/var/spool/cron/下创建一个文件夹
if [ ! -e /var/spool/cron/ ];then
mkdir -p /var/spool/cron/
fi
echo "* * * * * ${NTP_DATE} ntpdate ${NTP_SERVER} >> /var/log/ntpdate.log" >>/var/spool/cron/root