centos 7 ntp服务端配置脚本 + 定时任务

#/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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值