centos 搭建ntp
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的更多相关文章
- 使用阿里云镜像站NTP服务搭建NTP服务器(基于CentOS 7系统)
镜像下载.域名解析.时间同步请点击 阿里云开源镜像站 一.NTP服务器介绍 网络时间协议(Network Time Protocol,NTP)服务器,也就是日常所说的NTP服务器,用来提供同步时间服务 ...
- CentOS 6.5 下搭建NTP服务器
参考网站: http://www.iyunv.com/thread-64847-1-1.html http://acooly.iteye.com/blog/1993484 1 检查系统 ...
- Centos7安装搭建NTP服务器和NTP客户端同步时间
NTP简介: NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议. 在计算机的世界里,时间非常地重要 例如:对于火箭发射这种科研活动,对时间的 ...
- 搭建ntp服务器
1.同步网络时间 先关闭掉ntp服务,使用ntpd同步网络时间. /etc/init.d/ntpd stop ntpdate 2.hk.pool.ntp.org 网络时间可以从http://www.p ...
- CentOS之NTP服务器配置
本文使用CentOS 6.5作为搭建环境 一.服务器端配置 1.安装所需软件包 yum -y install ntp ntpdate---------------------------------- ...
- centos7搭建ntp时间同步服务器chrony服务
centos7搭建ntp时间同步服务器chrony服务 前言: 在centos6的时候我们基本使用的是ntp服务用来做时间同步,但是在centos7后推荐是chrony作为时间同步器的服务端使用, ...
- CentOS7搭建NTP服务器及客户端同步时间
一.服务器配置 1.查看服务器.客户端操作系统版本 [root@hadoop101 ~]# cat /etc/redhat-release CentOS Linux release (Core) 2. ...
- centos6 & centos7搭建ntp服务器
原理 NTP(Network TimeProtocol,网络时间协议)是用来使计算机时间同步的一种协议.它可以使计算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1 ...
- linux搭建ntp时间同步服务
1.NTP简介 NTP(Network Time Protocol,网络时间协议)用来使计算机时间同步的一种协议.它可以使计算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正(LAN上与标准 ...
随机推荐
- 3,MongoDB之数据类型
一.MongoDB 之数据类型 首先我们要先了解一下MongoDB中有什么样的数据类型: Object ID :Documents 自生成的 _id String: 字符串,必须是utf-8 Boo ...
- C# Dictionary的遍历理解
C# Dictionary容器类的理解 本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/det ...
- [工具使用]xshell 中“快速命令集”的使用
突然看到朋友的xshell比我多一个按钮,且一点,哈哈哈 ,实现了很炫酷的功能,耐不住好奇,问了一句,原来是快速命令集! 1.选择快速命令集(两种方法a&b) a:文件 > 属性 > ...
- android stadio open recent 在同一窗口打开
Android staido 有一个功能是open recent ,默认是下面这样的: 就出来一个框,给你选择,是在新的窗口打开,还是在当前窗口打开.如果你选了当前窗口,并且点了Remember,do ...
- JAVA API访问Hbase org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=32
Java使用API访问Hbase报错: 我的hbase主节点是spark1 java代码访问hbase的时候写的是ip 结果运行程序报错 不能够识别主机名 修改主机名 修改主机hosts文 ...
- 干货100+ 最超全的web开发工具和资源大集合
干货100+ 最超全的web开发工具和资源大集合 作为Web开发者,这是好的时代,也是坏的时代.Web开发技术也在不断变化.虽然很令人兴奋,但是这也意味着Web开发人员需要要积极主动的学习新技术和 ...
- 《Cracking the Coding Interview》——第12章:测试——题目6
2014-04-25 00:53 题目:你要如何测试一个分布式银行系统的ATM机? 解法:ATM是Automatic Teller Machine,取钱的.我想了半天,没找到什么很清晰的思路,也许是因 ...
- 【Kernal Support Vector Machine】林轩田机器学习技术
考虑dual SVM 问题:如果对原输入变量做了non-linear transform,那么在二次规划计算Q矩阵的时候,就面临着:先做转换,再做内积:如果转换后的项数很多(如100次多项式转换),那 ...
- Node应用进程管理器pm2的使用
本文转载自:豆瓣-PM2介绍 更多内容见github上的pm2说明文档pm2 pm2 是一个带有负载均衡功能的Node应用的进程管理器. 当你要把你的独立代码利用全部的服务器上的所有CPU,并保证进程 ...
- Python全栈工程师(多继承、函数重写)
ParisGabriel 每天坚持手写 一天一篇 决定坚持几年 为了梦想为了信仰 开局一张图 Python人工智能从入门到精通 补充: 对象 --------- ...