NTP时间服务器配置与解析
NTP时间服务器配置与解析
Edit By ZhenXing_Yu
目 录
编译安装ntp server 2
修改ntp.conf配置文件 2
配置时间同步客户机 2
在服务端验证: 3
在客户端进行同步验证: 3
启动、重启启动与关闭NTP 4
第一种方式 4
第二种方式 4
查看NTP服务: 4
设置开机自启动: 5
NTP的主配置文件/etc/ntp.conf解析 5
NTP服务报错解析: 7
编译安装ntp server
rpm -qa | grep ntp
Yum install ntp
修改ntp.conf配置文件
vi /etc/ntp.conf
①、第一种配置:允许任何IP的客户机都可以进行时间同步
#restrict default kod nomodify notrap nopeer noquery(表示默认拒绝所有IP的时间同步)
restrict default modify notrap
②、第二种配置:只允许192.168.2.0网段的客户机进行时间同步
restrict 192.168.2.0 mask 255.255.255.0 nomodify notrap
配置时间同步客户机
在客户端手工执行 ntpdate <ntp server> 来同步,如:
ntpdate 172.25.25.25
或者利用crontab来执行
crontab -e
0-59/10 * * * * /usr/sbin/ntpdate 192.168.2.10 >> /root/ntpdate.log 2>&1
表示每隔10分钟同步一次时间
在服务端验证:
# watch ntpq -p
Every 2.0s: ntpq -p Tue Dec 7 05:52:55 2010
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0) .LOCL. 8 l 22 64 377 0.000 0.000 0.001
服务正常运行
在客户端进行同步验证:
# ntpdate -d 192.168.2.10
注:-d表示显示详细信息
Ntpdate指令不能在服务端使用,只能在客户端使用
7 Dec 05:54:42 ntpdate[3627]: ntpdate 4.2.2p1@1.1570-o Thu Nov 26 11:35:07 UTC 2009 (1)
Looking for host 192.168.2.10 and service ntp
host found : 192.168.2.10
transmit(192.168.2.10)
receive(192.168.2.10)
transmit(192.168.2.10)
receive(192.168.2.10)
transmit(192.168.2.10)
receive(192.168.2.10)
transmit(192.168.2.10)
receive(192.168.2.10)
transmit(192.168.2.10)
server 192.168.2.10, port 123
stratum 9, precision -20, leap 00, trust 000
refid [192.168.2.10], delay 0.02632, dispersion 0.00061
transmitted 4, in filter 4
reference time: d0a890f1.b4d040ff Tue, Dec 7 2010 5:54:41.706
originate timestamp: d0a89102.09318178 Tue, Dec 7 2010 5:54:58.035
transmit timestamp: d0a890f2.3c8effe2 Tue, Dec 7 2010 5:54:42.236
filter delay: 0.02910 0.02632 0.02808 0.02641
0.00000 0.00000 0.00000 0.00000
filter offset: 15.80026 15.79880 15.79793 15.79837
0.000000 0.000000 0.000000 0.000000
delay 0.02632, dispersion 0.00061
offset 15.798801
7 Dec 05:54:42 ntpdate[3627]: step time server 192.168.2.10 offset 15.798801 sec
显示此段表示同步成功,建议多执行几次以保持时间的更精确的同步
Offset表示延迟了15秒。
启动、重启启动与关闭NTP
第一种方式
[root@YuZhenXing ~]# /etc/init.d/ntpd start
Starting ntpd: [ OK ]
[root@YuZhenXing ~]# /etc/init.d/ntpd restart
Shutting down ntpd: [ OK ]
Starting ntpd: [ OK ]
[root@YuZhenXing ~]# /etc/init.d/ntpd stop
Shutting down ntpd: [ OK ]
第二种方式
[root@YuZhenXing ~]# service ntpd start
Starting ntpd: [ OK ]
[root@YuZhenXing ~]# service ntpd restart
Shutting down ntpd: [ OK ]
Starting ntpd: [ OK ]
[root@YuZhenXing ~]# service ntpd stop
Shutting down ntpd: [ OK ]
[root@YuZhenXing ~]#
查看NTP服务:
NTP服务主要是UDP且在port123端口
[root@X /]# netstat -tlunp | grep ntp
设置开机自启动:
[root@YuZhenXing ~]# chkconfig ntpd on
[root@YuZhenXing ~]# chkconfig --list ntpd
ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
NTP的主配置文件/etc/ntp.conf解析
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
允许其他客户端与本时间服务器进行同步,但不允许客户端去查询或者修改这个服务器上的服务资源。
restrict default kod nomodify notrap nopeer noquery 《=====拒绝所有IPv4的用户
restrict -6 default kod nomodify notrap nopeer noquery 《=====拒绝I所有Pv6的用户
Restrict 172.25.25.25 《=========允许这个IP进入NTP服务器
---------------------------------------------------------------------------------------------------
参数介绍:
ignore:拒绝所有类型的NTP连接
Nomodify:客户端不能使用ntpc与ntpq这两个程序来修改服务器的时间参数,但客户端仍可通过这部主机来进行网络校时
Notrap:不提供trap这个远程事件登陆(remote event logging)的功能
Noquery:客户端不能够使用ntpc与ntpq等命令来查询时间服务器,等于不提供NTP的网络校时
Notrust:拒绝没有认证的客户端
如果使用在没有参数的地方添加,表示该IP或者网段不受任何限制
如:
172.25.25.25 表示该IP不受任何限制
一般可以先关闭NTP的同步权限,再一个一个的添加可以同步的客户端IP或网段。
----------------------------------------------------------------------------------------
# Permit all access over the loopback interface. This could
允许所有本地回环接口。
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1 《===放行本机回环IPv4形式
restrict -6 ::1 《====放行本机回环IPv6形式
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap 《====放行局域网来源
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.rhel.pool.ntp.org ======上层同步的服务器
server 1.rhel.pool.ntp.org ======上层同步的服务器
server 2.rhel.pool.ntp.org ======上层同步的服务器
#broadcast 192.168.1.255 key 42 # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 key 42 # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 key 42 # manycast client
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
如果在上层时间服务器不能提供服务的时候,则使用这里进行本机的同步
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
# Drift file. Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()'ing
# it to the file.
driftfile /var/lib/ntp/drift
TIP:
因为NTP默认本身的时间计算式依据BIOS的芯片振荡周期频率来计算的,但是这个数值与上层time server不见得一致,所以NTP这个daenon(ntpd)会自动去计算我们自己主机的频率与上层time server的频率,并且将两个频率的误差记录下来,记录下来的文件就是在driftfiile后面的完整文件名指定的文件。
- 该文件必须指定完整的路径
- 该文件不能是链接文件
- 该文件需要设置成ntpd这个daemon可以写入的权限
- 改文件所记录的数值单位是百万分之一秒(ppm)
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
NTP服务报错解析:
当用ntpdate -d 来查询时会发现导致 no server suitable for synchronization found 的错误的信息有以下2个:
错误1.Server dropped: Strata too high
在ntp客户端运行ntpdate serverIP,出现no server suitable for synchronization found的错误。
在ntp客户端用ntpdate -d serverIP查看,发现有“Server dropped: strata too high”的错误,并且显示“stratum 16”。而正常情况下stratum这个值得范围是“0~15”。
这是因为NTP server还没有和其自身或者它的server同步上。
以下的定义是让NTP Server和其自身保持同步,如果在/ntp.conf中定义的server都不可用时,将使用local时间作为ntp服务提供给ntp客户端。
server 127.127.1.0
fudge 127.127.1.0 stratum 8
在ntp server上重新启动ntp服务后,ntp server自身或者与其server的同步的需要一个时间段,这个过程可能是5分钟,在这个时间之内在客户端运行ntpdate命令时会产生no server suitable for synchronization found的错误。
那么如何知道何时ntp server完成了和自身同步的过程呢?
在ntp server上使用命令:
# watch ntpq -p
Every 2.0s: ntpq -p Tue Dec 7 05:52:55 2010
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0) .LOCL. 8 l 22 64 377 0.000 0.000 0.001
注意LOCAL的这个就是与自身同步的ntp server。
注意reach这个值,在启动ntp server服务后,这个值就从0开始不断增加,当增加到17的时候,从0到17是5次的变更,每一次是poll的值的秒数,是64秒*5=320秒的时间。
如果之后从ntp客户端同步ntp server还失败的话,用ntpdate –d来查询详细错误信息,再做判断。
错误2.Server dropped: no data
从客户端执行netdate –d时有错误信息如下:
transmit(192.168.30.22)
transmit(192.168.30.22)
transmit(192.168.30.22)
transmit(192.168.30.22)
transmit(192.168.30.22)
192.168.30.22: Server dropped: no data
server 192.168.30.22, port 123
.....
28 Jul 17:42:24 ntpdate[14148]: no server suitable for synchronization found
出现这个问题的原因可能有2:
1。检查ntp的版本,如果你使用的是ntp4.2(包括4.2)之后的版本,在restrict的定义中使用了notrust的话,会导致以上错误。
使用以下命令检查ntp的版本:
# ntpq -c version
下面是来自ntp官方网站的说明:
The behavior of notrust changed between versions 4.1 and 4.2.
In 4.1 (and earlier) notrust meant "Don't trust this host/subnet for time".
In 4.2 (and later) notrust means "Ignore all NTP packets that are not cryptographically authenticated." This forces remote time servers to authenticate themselves to your (client) ntpd
解决:
把notrust去掉。
2。检查ntp server的防火墙。可能是server的防火墙屏蔽了upd 123端口。
可以用命令
#service iptables stop
来关掉iptables服务后再尝试从ntp客户端的同步,如果成功,证明是防火墙的问题,需要更改iptables的设置。
NTP时间服务器配置与解析的更多相关文章
- ORACLE RAC NTP 时间服务器配置
Linux 时间同步配置 . 一. 使用ntpdate 命令 1.1 服务器可链接外网时 # crontab -e 加入一行: */1 * * * * ntpdate 210.72.145.44 21 ...
- linux ntp时间服务器配置
Network Time Protocol (NTP) 也是RHCE新增的考试要求. 学习的时候也顺便复习了一下如何设置Linux的时间,现在拿出来和大家分享 设置NTP服务器不难但是NTP本身是一个 ...
- NTP时间服务器配置
1.服务器端配置: #允许这些IP向自己同步时间 restrict x.x.x.x mask x.x.x.x nomodiy notrap #当和定义的所有server服务器无法同步后,和自身同步 s ...
- 企业内部在centos7.2系统中必杀技NTP时间服务器及内网服务器时间同步(windows和linux客户端同步)
网络时间协议NTP(Network Time Protocol)是用于互联网中时间同步的标准互联网协议.NTP的用途是把计算机的时间同步到某些时间标准.目前采用的时间标准是世界协调时UTC(Unive ...
- ntp时钟服务器配置
集群中时间不同步有可能会让大数据的应用程序运行混乱,造成不可预知的问题,比如Hbase,当时间差别过大时就会挂掉,所以在大数据集群中,ntp服务,应该作为一种基础的服务,以下在演示在CentOS 7. ...
- 局域网部署ntp时间服务器
搭建ntp时间服务器 时间服务器配置 须切换到root用户,再进行操作 检查ntp是否安装 [root@hadoop01 ~]# rpm -qa | grep ntp 如果没有安装,须安装 [root ...
- centos7.5配置ntp时间服务器
Centos7配置ntp时间服务器 Centos7配置时间服务器,一个服务端,多个客户端,客户端去同步服务端 服务端: 1.先修改时区,否则即使配置完ntp时间也不对,修改时区参照:https://w ...
- 搭建内网的NTP时间服务器
NTP时间服务器 标签: linux 笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 1.简介 NTP(Network Time Protocol,网络时间协议) ...
- 国内可用的Internet时间同步服务器地址(NTP时间服务器)
不知道什么鬼我这系统自带的Internet时间同步服务器地址居然不可用,终端ping系统自带服务器两个居然都不通???难道时间服务器也和谐么? 好在阿里云提供了7个NTP时间服务器也就是Interne ...
随机推荐
- 什么是Nib文件?(Nib文件是一种特殊类型的资源文件,它用于保存iPhone OS或Mac OS X应用程序的用户接口)
Nib文件是一种特殊类型的资源文件,它用于保存iPhone OS或Mac OS X应用程序的用户接口.Nib文件是Interface Builder文档.通常您会使用Interface Builder ...
- hdu 1526(最大匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1526 思路:floyd求传递闭包,然后就是最大匹配了,不过一开始输入没看清,被坑了将近2个小时. #i ...
- 【poj1006-biorhythms】中国剩余定理
http://poj.org/problem?id=1006 题意:中国剩余定理的裸题. 题目可转化为求最小的x满足以下条件: x%23=a;x%28=b;x%33=c; 关于中国剩余定理可看我昨天的 ...
- http://blog.sina.com.cn/s/blog_5b9b4abe01017638.html
http://blog.sina.com.cn/s/blog_5b9b4abe01017638.html
- PHP页面跳转几种实现技巧
PHP被许多程序员用来开发WEB的首选语言.在实际开发中,网站的各项功能都可以通过PHP语言的编写来满足,比如PHP页面跳转这一方法. 探讨PHP变量解析顺序如何获取提交数据 深入解读PHP运行机制 ...
- Adb connection Error:远程主机强迫关闭了一个现有的连接 解决方法
用真机调试程序的时候,eclipse 的 Console 总是出现如下的错误"Adb connection Error:远程主机强迫关闭了一个现有的连接". 问题出现的原因:这是 ...
- Largest Rectangle in Histogram-最大长方形
题目描述: 给定n个非负整数height[n],分别代表直方图条的高,每个条的宽设为1,求直方图中面积最大的矩形的面积 题目来源: http://oj.leetcode.com/problems/la ...
- SQL Agent Job ->> 通过sys.sysprocesses的program_name字段来定位对应的Job
;WITH T AS ( SELECT 'SQLAgent - TSQL JobStep (Job 0x'+ ),)),) + ' : Step ' + )) + ')' filter, j.job_ ...
- Maven+Spring+Hibernate+Shiro+Mysql简单的demo框架(二)
然后是项目下的文件:完整的项目请看 上一篇 Maven+Spring+Hibernate+Shiro+Mysql简单的demo框架(一) 项目下的springmvc-servlet.xml配置文件: ...
- html5 canvas移动设备渲染测试
最近项目闲着没什么事,又想起了canvas, 针对移动端设备默认浏览器,做了点渲染方面效率的测试,手头设备不多(有一些低端机型和pc chrome做对比),现将测试数据分享给大家吧,本想和css3 a ...