返回总目录页

NTP服务

 

 常用软件安装及使用首页

 

NTP 时间服务器

原文:http://www.zyops.com/ntp/

ntp也是一种协议

ntp软件(支持ntp协议)  CentOS6自带 CentOS7需要安装的

chrony软件(支持ntp协议)   CentOS7自带

1. NTP简介

NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms。

NTP服务器就是利用NTP协议提供时间同步服务的。

2. NTP服务器安装

# 系统自带ntp
[root@oldboyedu ~]# rpm -qa ntp
ntp-4.2.6p5-5.el6.centos.x86_64
# 如果没有就安装
yum -y install ntp

3. 配置NTP服务

[root@oldboyedu ~]# vim /etc/ntp.conf
# restrict default kod nomodify notrap nopeer noquery
restrict default nomodify
# nomodify客户端可以同步
# 将默认时间同步源注释改用可用源
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
# server 3.centos.pool.ntp.org iburst
server ntp1.aliyun.com
server time.nist.gov

4. 启动NTP服务器

# 如果计划任务有时间同步,先注释,两种用法会冲突。
[root@oldboyedu ~]# crontab -e
# time sync by oldboy at 2010-2-1
#*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1
[root@oldboyedu ~]# /etc/init.d/ntpd start
Starting ntpd:                                             [  OK  ]
[root@oldboyedu ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntp1.aliyun.com 10.137.38.86     2 u   22   64    1  525.885  -42.367   0.000
[root@oldboyedu ~]# ntpstat
synchronised to NTP server (110.75.186.247) at stratum 3
   time correct to within 4257 ms
   polling server every 64 s
[root@oldboyedu ~]# ntpdate 10.0.0.9
 7 Dec 18:43:07 ntpdate[26950]: the NTP socket is in use, exiting

5. 客户机时间同步

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

[root@zyops ~]# ntpdate 10.0.0.9
 7 Dec 18:40:16 ntpdate[1453]: step time server 10.0.0.9 offset 40.880807 sec
 # 将命令放入计划任务即可。

 6. ntpq -p参数详解

 

ntpq -p命令列出了所有作为时钟源校正过本地NTP服务器时钟上层NTP服务器的列表,每一列的含义分别如下:

remote:响应请求的NTP服务器的名称(IP地址或域名),带“*”的表示本地NTP服务器与该服务器同步

refid:远程NTP服务器使用的上一级ntp服务器的IP地址

st:远程NTP服务器的级别,由于NTP是层级结构,有顶端的服务器,多层的Relay Server再到客户端。所以服务器从高到低,级别可以设定为1~16级。为了减缓负荷和网络堵塞,原则上应该避免直接连接到级别为1的服务器。

t:本地NTP服务器与远程NTP服务器的通信方式。u:单播;b:广播;I:本地

when:上次成功请求后到现在的秒数

poll:本地NTP服务器与远程NTP服务器同步的时间间隔。

reach:这是一个八进制的值,用来测试衡量前八次查询是否成功和服务器连接。377表示都成功,0表示不成功

delay:网络延时,单位为微秒(μs)

offset:本地NTP服务器与远程NTP服务器的时间偏移,单位为毫秒(ms)。offset越接近于0,主机与NTP服务器的时间越接近

jitter:查询偏差的分布值,用于表示远程NTP的网络延时是否稳定,单位为微秒(μs)。

 

posted @ 2018-08-27 21:27  马昌伟  阅读(361)  评论(0编辑  收藏  举报
博主链接地址:https://www.cnblogs.com/machangwei-8/