str=$(printf "%-25s" "*")
echo -e "${str// /*}"
echo -e "*\t\t\t*"
echo -e "*\tNTP 安装\t*"
echo -e "*\t\t\t*"
echo -e "${str// /*}"
#搭建ntp建议搭建在Puppet控制端
ntp=`rpm -qa | grep ntp- && echo $?`
if [[ "$ntp"x == ""x ]];then
yum install ntp-* -y > /dev/null >&
fi
#同步时间
/etc/init.d/ntpd stop > /dev/null >&
ntp=`ntpdate .uk.pool.ntp.org && ntpdate .uk.pool.ntp.org && echo $?`
if [[ "$ntp" == "" ]];then
echo 'NTP同步失败'
echo "执行ntpdate 0.uk.pool.ntp.org检查"
exit
fi
#写入配置文件
cat > /etc/ntp.conf << EFO
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict 0.0.0.0 mask 0.0.0.0 nomodify
SYNC_HWCLOCK=yes
server time.nist.gov prefer
server .centos.pool.ntp.org minpoll maxpoll iburst
server .centos.pool.ntp.org minpoll maxpoll iburst
server .centos.pool.ntp.org minpoll maxpoll iburst
server .centos.pool.ntp.org minpoll maxpoll iburst
server 210.72.145.44
server 218.21.130.42
server 127.127.1.0
fudge 127.127.1.0 stratum
restrict time.nist.gov nomodify notrap noquery
restrict .centos.pool.ntp.org nomodify notrap noquery
restrict .centos.pool.ntp.org nomodify notrap noquery
restrict .centos.pool.ntp.org nomodify notrap noquery
restrict .centos.pool.ntp.org nomodify notrap noquery
restrict 210.72.145.44 nomodify notrap noquery
restrict 218.21.130.42 nomodify notrap noquery
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
EFO
if [ $? != ];then
echo "写入失败"
exit
fi
#启动
/etc/init.d/ntpd start
ntp=`/etc/init.d/ntpd status | grep -Eo stopped`
if [ "$ntp" == "stopped" ];then
echo "启动失败"
echo "执行/etc/init.d/ntpd status检查并启动"
exit
fi
chkconfig ntpd on > /dev/null >&
ntp=`chkconfig --list ntpd | awk '{print $4,$5,$6}' | sed -e 's/://g' -e 's/[2-4\]//g' -e 's/ /\n/g'|uniq | grep -v 'on'`
if [[ "$ntp" != "" ]];then
echo "设置NTP开机启动失败"
echo "执行chkconfig --list ntpd检查"
exit
fi
ntp=`ntpq -p | sed '1,2d' | awk '{print $9}'`
for i in ntp
do
if [ x"$i" == x'' ];then
echo "时间同步有问题"
echo "执行ntpq -p检查"
exit
fi
done
#将ntp写入crontab
#ntp
ntp=`grep -q "NTP" /etc/crontab && echo $?`
if [[ "$ntp" != "" ]];then
echo "#NTP" >> /etc/crontab
echo "0 1 * * * root /usr/sbin/ntpdate time-b.nist.gov >/dev/null 2" >> /etc/crontab
service crond reload
fi

centos 搭建ntp的更多相关文章

  1. 使用阿里云镜像站NTP服务搭建NTP服务器(基于CentOS 7系统)

    镜像下载.域名解析.时间同步请点击 阿里云开源镜像站 一.NTP服务器介绍 网络时间协议(Network Time Protocol,NTP)服务器,也就是日常所说的NTP服务器,用来提供同步时间服务 ...

  2. CentOS 6.5 下搭建NTP服务器

    参考网站: http://www.iyunv.com/thread-64847-1-1.html http://acooly.iteye.com/blog/1993484 1         检查系统 ...

  3. Centos7安装搭建NTP服务器和NTP客户端同步时间

    NTP简介: NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议. 在计算机的世界里,时间非常地重要 例如:对于火箭发射这种科研活动,对时间的 ...

  4. 搭建ntp服务器

    1.同步网络时间 先关闭掉ntp服务,使用ntpd同步网络时间. /etc/init.d/ntpd stop ntpdate 2.hk.pool.ntp.org 网络时间可以从http://www.p ...

  5. CentOS之NTP服务器配置

    本文使用CentOS 6.5作为搭建环境 一.服务器端配置 1.安装所需软件包 yum -y install ntp ntpdate---------------------------------- ...

  6. centos7搭建ntp时间同步服务器chrony服务

    centos7搭建ntp时间同步服务器chrony服务 前言: 在centos6的时候我们基本使用的是ntp服务用来做时间同步,但是在centos7后推荐是chrony作为时间同步器的服务端使用, ...

  7. CentOS7搭建NTP服务器及客户端同步时间

    一.服务器配置 1.查看服务器.客户端操作系统版本 [root@hadoop101 ~]# cat /etc/redhat-release CentOS Linux release (Core) 2. ...

  8. centos6 & centos7搭建ntp服务器

    原理 NTP(Network TimeProtocol,网络时间协议)是用来使计算机时间同步的一种协议.它可以使计算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1 ...

  9. linux搭建ntp时间同步服务

    1.NTP简介 NTP(Network Time Protocol,网络时间协议)用来使计算机时间同步的一种协议.它可以使计算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正(LAN上与标准 ...

随机推荐

  1. saltstack执行远程命令

    目录 Remote Execution salt state salt state 系统 salt state 系统流程 Runner salt runner Orchestrate Runner S ...

  2. pdfmake实现中文支持,解决中文乱码问题

    引言:当初自己为了在项目中bootstrap-table中实现导出pdf,使用的pdfmake,但是pdfmake默认使用的不是中文字体,实现pdfmake使用中文字体主要就是编译新的vfs_font ...

  3. P3819 松江1843路(洛谷月赛)

    P3819 松江1843路 题目描述 涞坊路是一条长L米的道路,道路上的坐标范围从0到L,路上有N座房子,第i座房子建在坐标为x[i]的地方,其中住了r[i]人. 松江1843路公交车要在这条路上建一 ...

  4. Postman-进阶(2)

    Postman-进阶(2) Postman-简单使用 Postman-进阶使用 Postman-CI集成Jenkins 管理请求 保存请求-添加“打开百度首页请求” 设置请求方式为Get,地址为www ...

  5. Java学习笔记17---成员方法的重载与重写

    重载是指,一个类中定义了一个成员方法后,通过修改参数个数.参数类型或参数顺序,重新实现该方法,则这两个方法互为对方的重载方法. 重写是指,子类重新实现父类的成员方法. 重载后的方法,与原方法相比: ( ...

  6. 一些 ssh 小技巧

    本文来自网易云社区. 作者:沈高峰 ssh 经常需要使用的,每次使用都  ssh  abc@XXX.def.com -p 12138 -i ~/.ssh/id_rsa 来一遍显然太麻烦了,下面分享一点 ...

  7. 《数据结构》C++代码 前言

    现在大二正在上<数据结构>课,课内的书上代码实现很喜欢无脑用类.变量名字很长,而且常常实现太繁琐,并且代码有些无法运行,这些对于老手无所谓,但初学者看起来却会很不舒服.因此写点自己实现这些 ...

  8. 图解-Excel的csv格式特殊字符处理方式尝试笔记(个人拙笔)

    Excel格式如下.(截图来自,WPS Office) CSV是一种文本格式的Excel文档格式.不支持Excel的字体特效(比如加粗,颜色)等等的保存. 每一行数据用 "\n" ...

  9. Windows环境下,python webdriver环境搭建

    最近刚开始学习selenium,这是我从虫师的<selenium2自动测试实战--基于Python语言>这本书上学到搭建环境的步骤,里面有加上我的一些总结,希望对大家有所帮助!   准备工 ...

  10. leetcode_day02

    任务二:删除排序数组中的重复项 原文链接:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/ 最开始的解决思路: ...