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 ...
随机推荐
- 2014多校第七场1003 || HDU 4937 Lucky Number
题目链接 题意 : 给定一个十进制n,让你转化成某个进制的数,让这个数只包含3 4 5 6这些数字,这个进制就成为n的幸运数字,输出有多少幸运数字,例如19,5进制表示是34,所以5是19的一个幸运数 ...
- (7)nehe教程1 创建一个OpenGL窗口:
不要用那个nehe ndk了 误人子弟! 转自: 一个窗口,代码可真多啊 http://www.yakergong.net/nehe/ 在这个教程里,我将教你在Windows环境中创建OpenGL程序 ...
- Windows 代码实现关机(直接黑屏)
整理资料的时候发现的以前的代码,本机Win7 x64 Sp1 运行直接关机,黑屏.就是利用RtlAdjustPrivilege函数提权,代码中的注释写的很详细了.用的VS2010写的,直接编译成x64 ...
- Android应用的核心基础
Android4开发入门经典 之 第二部分:Android应用的核心基础 Android应用中的组件 Application Components Android应用中最主要的组件是: 1:Activ ...
- c语言结构体赋值问题
对于结构体赋值问题: static psl{ int a; char ch; }; 我过去一般会对结构体这样赋值: static psl pslname = { , 'b', }; 记住有一点,‘b’ ...
- Rate Limiter设计
先存着,以后再写 http://iamzhongyong.iteye.com/blog/1982113 http://baike.baidu.com/view/2530454.htm https:// ...
- java读写中文文件
在用Java程序进行读写含中文的txt文件时,经常会出现读出或写入的内容会出现乱码.原因其实很简单,就是系统的编码和程序的编码采用了不同的编码格式.通常,假如自己不修改的话,windows自身采用的编 ...
- HDU4675【GCD of scequence】【组合数学、费马小定理、取模】
看题解一开始还有地方不理解,果然是我的组合数学思维比较差 然后理解了之后自己敲了一个果断TLE.... 我以后果然还得多练啊 好巧妙的思路啊 知识1: 对于除法取模还需要用到费马小定理: a ^ (p ...
- NAND Flash【转】
转自:http://www.cnblogs.com/lifan3a/articles/4958224.html 以Micron公司的MT29F2G08为例介绍NAND Flash原理和使用. 1. 概 ...
- win8找到程序员计算器
最近想用计算器的十进制和十六进制转化的功能,发现win8没有开始菜单了,从网上查了查,原来指令如此简单,特此做笔记,谨防忘记! 操作:win+r打开运行,输入calc,确定就出来了!