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上与标准 ...
随机推荐
- Matplotlib库介绍
pyplot的plot()函数 pyplot的中文显示 pyplot的文本显示 pyplot的子绘图区域
- 11 Django组件-分页器
Django的分页器(paginator) view from django.shortcuts import render,HttpResponse # Create your views here ...
- Python3的unittest用例按编写顺序执行
unittest是Python标准库自带的单元测试框架,是Python版本的JUnit,关于unittest框架的使用,官方文档非常详细,网上也有不少好的教程,这里就不多说了. 本文主要分享在使用un ...
- Python程序执行时的不同电脑路径不同问题
原因:因代码转移时项目路径发生了变化,导致解释器无法找到对应路径,是的程序无法正常执行 需求: 1.我希望代码能在不同的电脑下,不必修改源代码就能正常执行(所需模块已安装的前提下) 2.我希望代码在命 ...
- 计算机图形学 opengl版本 第三版------胡事民 第三章更多的绘图工具
opengl 计算机图形学 第三版 第二部分 第三章更多的绘图工具 3.1 概述 第2章中 我们绘图使用的是屏幕窗口的基础坐标系 以像素为单位 屏幕坐标从左下角x从0延伸到scr ...
- JavaWeb笔记(七)Filter&Listener
Filter 实现Filter接口 一般用于完成通用的操作,如:登陆验证.统一编码处理.敏感字符过滤等 执行流程 执行过滤器 执行放行后的资源 继续执行过滤器放行代码下的代码 配置 拦截路径配置 注解 ...
- pyinstaller打包自己的python程序
使用Pyinstaller打包步骤如下 1. 安装pyinstaller pip install pyinstaller 查看安装的版本 pyinstaller --version 2. 给脚本加密 ...
- class内部处理
class A { public: int foo( ) { return val ; } static int staFun( ) { return staVal ; } static int st ...
- 想玩API,这些套路我来告诉你!
小伙伴是不是时常听说各种api接口的问题呢,可能许多人第一感觉:那是什么个玩意儿,那么多人回去研究它,今天思梦PHP小编就来为你揭开他的神秘的面纱,先看一下百度百科上面的官方的解释: 其实说白了就是为 ...
- file mmap
do_set_pmd 统计参数只会在这里设置: add_mm_counter(vma->vm_mm, MM_FILEPAGES, HPAGE_PMD_NR); 但是这貌似都是处理大页的情况哪,小 ...