ntp服务器的搭建

第1章 NTP时间服务器

1.1 NTP简介

NTP(Network Time Protocol,网络时间协议)是用来使网络中的计算机时间同步的一种协议。

NTP服务器利用NTP协议来提供时间同步服务。

1.2 环境准备

1.2.1主机规划表

主机名    服务器/客户    外网IP          内网IP

ntp-s      Server       10.0.0.41        172.16.1.41

ntp-c      Client       10.0.0.31        172.16.1.31

1.2.2查看系统环境

[[email protected] ~]# cat /etc/redhat-release
CentOS release 6.7 (Final)
[[email protected] ~]# uname -r
2.6.32-573.el6.x86_64
[[email protected] ~]# /etc/init.d/iptables status
iptables:未运行防火墙。
[[email protected] ~]# getenforce
Disabled
[[email protected] ~]# /etc/init.d/iptables status
iptables:未运行防火墙。

1.3 安装NTP服务

CentOS6.7默认已安装ntp服务。如果没安装,就用yum安装即可。

[[email protected] ~]# rpm -qa ntp
ntp-4.2.6p5-5.el6.centos.x86_64

1.4 配置NTP

NTP服务默认的配置文件为:/etc/ntp.conf

1.4.1操作前备份

[[email protected] ~]# cp /etc/ntp.conf{,.ori}
[[email protected] ~]# ll /etc/ntp.conf{,.ori}
-rw-r--r--. 1 root root 1778 2015-04-28 18:11/etc/ntp.conf
-rw-r--r-- 1 root root 1778 2016-07-28 15:28 /etc/ntp.conf.ori

1.4.2配置完成如下

[[email protected] ~]# grep -vE "^$|#" /etc/ntp.conf #过滤空行和注释行
driftfile /var/lib/ntp/drift
restrict 127.0.0.1
restrict -6 ::1
restrict default nomodify
server ntp1.aliyun.com
server time.nist.gov
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys

1.4.3NTP配置重要参数详解

driftfile /var/lib/ntp/drift #记录上次的NTP server与上层NTP server联接所花费的时间
restrict default nomodify  #允许所有主机进行时间同步
server ntp1.aliyun.com    #同步时间服务器
server 210.72.145.44 prefer #prefer表示优先

1.5 启动NTP服务

~注意:如果有ntpdate定时任务,需要先关闭;否则两者会有冲突。

[[email protected] ~]# /etc/init.d/ntpd start #启动服务
正在启动 ntpd:                                            [确定]
[[email protected] ~]# chkconfig ntpd on   #加入开机自启动
[[email protected] ~]# chkconfig --list ntpd

1.5.1查看本机和上层服务器的时间同步结果

[[email protected] ~]# ntpq -p

1.6 客户端同步

客户机要等几分钟再与启动的ntp服务器进行时间同步,否则会提示no server suitable for synchronization found错误。

[[email protected] ntpstats]# date -s"20160606"  #修改当前时间
2016年 06月 06日 星期一 00:00:00 CST
[[email protected] ntpstats]# ntpdate 172.16.1.41 #与NTP server进行时钟同步
28 Jul 15:55:27 ntpdate[8510]: step time server172.16.1.41 offset 4550114.397444 sec
[[email protected] ntpstats]# date
2016年 07月 28日 星期四 15:55:30 CST

1.7 定时任务(客户端)

[[email protected] ~]# crontab -l
#time sync by ChenDianHu at 2016-06-28
*/5 * * * * /usr/sbin/ntpdate 172.16.1.41>/dev/null 2>&1

1.8 命令说明

ntpdate ntp1.aliyun.com #向阿里云时间服务器,立即同步更新时间
ntpq -p   peers    #查看本机和上层服务器的时间同步结果
时间: 2024-08-01 22:44:05

ntp服务器的搭建的相关文章

NTP服务器的搭建和时间同步

一.NTP服务器1.安装NTP服务 yum install -y ntp 2.修改ntp的配置文件[[email protected] ~]# grep -Ev "^#|^$" /etc/ntp.confdriftfile /var/lib/ntp/driftpidfile /var/run/ntpd.pidlogfile /var/log/ntp.logrestrict -4 default kod notrap nomodifyrestrict -6 default kod not

Linux NTP 服务器搭建

Linux时间同步服务器搭建 NTP(Network Time Protocol)是用来使计算机时间同步化的一种协议,它使用UDP协议123号端口对外提供服务,它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)做时间的同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒),且可介由加密确认的方式来防止恶毒的协议攻击.时间按NTP服务器的等级传播.按照离外部UTC源的远近把所有服务器归入不同的Stratum(层)中. 今天做一个项目需要配置一台NTP时间同步服

CentOS6.5系统搭建NTP服务器

在进入到我们的主题之前首先我们可以简单了解一下这几个名词 Atomic Clock: 现在计算时间最准确的是使用 原子震荡周期 所计算的物理时钟(Atomic Clock),因此也被定义为标准时间(International Atomic Time) UTC(coordinated Universal Time): 协和标准时间 就是利用 Atomic Clock 为基准定义出来的正确时间 (世界统一时间,世界标准时间,国际协调时间) 硬件时钟: 硬件时钟是指嵌在主板上的特殊的电路, 它的存在就

docker 搭建ntp服务器

背景 在搭建etcd集群时,如果主机时间相差太多会出现同步错误,如果外部网络不可用时,需要使用内部的ntp服务器同步时间. 构建ntp镜像 创建Dockerfile # usage: # docker build -t ntp . # docker run docker run -d --name ntp-server -p 123:123 -v /etc/localtime:/etc/localtime:ro -v /etc/timezone:/etc/timezone:ro ntp from

Linux下NTP服务器搭建

一.搭建准备 1.确定自己的时区 #date命令可以查看当前系统时间,中国的时区为CST.使用tzselect命令进行配置时区 配置文件的修改:/etc/sysconfig/clock 2.检查NTP服务程序 #rpm -qa |grep ntp fontpackages-filesystem-1.41-1.1.el6.noarch ntpdate-4.2.4p8-3.el6.x86_64 如果没有,则需要安装ntp程序 #yum -y install ntp ntpdate 需要配置好yum源

鸟哥服务器架设——NTP服务器搭建

NTP服务器搭建 一.NTP通信协议 实际上,Linux操作系统的计时方式主要从1970年1月1日开始计算总秒数,因此,如果你还记得date这个命令的话,会发现他有个+%s的参数,可以去的总秒数,这个就是软件时钟.但是,如同前面说的,计算机硬件主要是以BIOS内部的时间为主要的时间依据(硬件时钟),而偏偏这个时间可能因为BIOS内部芯片本身的问题,而导致BIOS时间与标准时间(UTC)存在一点点的差异.所以,为了避免主机时间因为长期运行而导致时间偏差,进行时间同步(synchronize)的工作

为嵌入式开发板客户端自己动手在虚拟机上搭建NTP服务器

网络时间协议NTP(Network Time Protocol)是用于互联网中时间同步的标准互联网协议.NTP的用途是把计算机的时间同步到某些时间标准.目前采用的时间标准是世界协调时UTC(Universal Time Coordinated).NTP的主要开发者是美国特拉华大学的David L. Mills教授.NTP对于我们个人来说有什么用呢,简单的讲,当你的计算机时间不准确了,你可以接入到互联网,从网上同步一下时间,看多方便. 对于企业来说,当你有成百上千的计算机,都不能直接连接互联网,时

为嵌入式开发板客户端自己动手在虚拟机上搭建时间同步NTP服务器

网络时间协议NTP(Network Time Protocol)是用于互联网中时间同步的标准互联网协议.NTP的用途是把计算机的时间同步到某些时间标准.目前采用的时间标准是世界协调时 UTC(Universal Time Coordinated).NTP的主要开发者是美国特拉华大学的David L. Mills教授.NTP对于我们个人来说有什么用呢,简单的讲,当你的计算机时间不准确了,你可以接入到互联网,从网上同步一下时间,看多方便. 对于企业来说,当你有成百上千的计算机,都不能直接连接互联网,

搭建配置NTP服务器

1.yum install -y ntp 2.关闭防火墙     service iptables stop     service ip6tables stop     chkconfig iptables off     chkconfig ip6tables off     vim /etc/selinux/config          修改SELINUX=disabled           3.备份ntp.conf配置文件     cp /etc/ntp.conf /etc/ntp.