定义:NTP全称为Network Time Protocol,即网络时间协议。是用来使计算机时间同步的一种协议。它可以使计算机对服务器或时钟源做同步,可以提供高精度的时间校正(LAN 上与标准时间小于1毫秒,WAN上几十毫秒),而且可以由加密确认的方式防止恶意的协议攻击。

端口:

[root@sishen_63 ~]# grep 'ntp' /etc/services

………….

ntp             123/tcp

ntp             123/udp                         # Network Time Protocol

安装

一般情况下,选择基本的桌面版安装环境,默认是已经装了的。如果没有安装使用:

[root@sishen_63 ~]# yum install -y ntp

进行一键式安装。

安装完成后使用service ntpd start启动。

根据自己需要可以修改/etc/ntp.conf配置文件。

这是配置文件中的NTP时间服务器。

在使用ntpdate命令校正时间之前,如果ntpd服务正在运行,则需要使用service ntpd stop来停掉ntpd服务,然后再执行ntpdate命令即可,如下图所示:

配置一个内网时钟服务器

首先查看我们本地服务器的上游NTP服务器

[root@sishen_63 ~]# vim /etc/ntp.conf

restrict 192.168.1.0 mask 255.255.255.0        #允许这个网段的服务器访问本地NTP服务器

restrict 192.168.1.64                   #允许这太主机访问

server 0.rhel.pool.ntp.org            #指定本地NTP服务器的上游NTP服务为0.rhel.pool.ntp.org,并且设置为优先服务器。同步时间,从上到下,写的越靠上,优先级越高。

注意:写在所有server最前面的IP地址为优先服务器,此服务器同步不了时间,寻找下一个NTP服务器

[root@sishen_63 ~]# vim /etc/ntp.conf

28 server 127.127.1.0  #local clock 如果上面的服务器都无法同步时间,就和本地系统时间同步
  29 fudge 127.127.1.0 stratum 10  #127.127.1.0为第10层,ntp和127.127.1.0同步完成后,就变成了11层。ntp同步上层服务器的stratum大小必须小于16层。

使用ntpdate校正时间

[root@sishen_63 ~]# ntpdate 0.rhel.pool.ntp.org

12 Sep 19:40:30 ntpdate[3735]: step time server 85.199.214.100 offset 220924453.272504 sec

[root@sishen_63 ~]# date

Tue Sep 12 19:40:34 CST 2017

查看端口

[root@sishen_63 ~]# netstat -ln | grep 123

udp        0      0 192.168.1.63:123            0.0.0.0:*                              

udp        0      0 127.0.0.1:123               0.0.0.0:*                              

udp        0      0 0.0.0.0:123                 0.0.0.0:*                              

udp        0      0 fe80::20c:29ff:fec2:2831:123 :::*                                   

udp        0      0 ::1:123                     :::*                                   

udp        0      0 :::123                      :::*

查看是否与上游服务器连接,需要过5分钟

[root@sishen_63 ~]# ntpstat

synchronised to local net at stratum 11
    time correct to within 7948 ms
    polling server every 64 s

查看本地服务器与上游服务器的连接状态

[root@sishen_63 ~]# ntpq -p
      remote           refid      st t when poll reach   delay   offset  jitter

==============================================================================
  0.rhel.pool.ntp .GPS.            1 u   55   64    1  246.016  999.256   0.000
  1.rhel.pool.ntp .INIT.          16 u    -   64    0    0.000    0.000   0.000
  2.rhel.pool.ntp .GPS.            1 u   43   64    1  234.445  1001.88   9.663

*LOCAL(0)        .LOCL.          10 l   53   64    1    0.000    0.000   0.000

注释:

remote:即remote - 本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先。

refid:参考的上一层NTP主机的地址

st:即stratum阶层

poll:下次更新在几秒之后

offset:时间补偿的结果

客户端同步

[root@sishen_64 ~]# ntpdate 192.168.1.63

12 Sep 19:45:51 ntpdate[3266]: step time server 192.168.1.63 offset 220924451.776674 sec

[root@sishen_64 ~]# date

Tue Sep 12 19:45:52 CST 2017

最新文章

  1. 锋利的jQuery--Ajax(读书笔记四)
  2. SQLite学习笔记(十一)&&虚拟机原理
  3. PAT 1003. 我要通过!(20) JAVA
  4. cookie的实例
  5. Docker搭建便捷的开发者环境
  6. Ubuntu 14.04下搭建Python3.4 + PyQt5.3.2 + Eric6.0开发平台
  7. android 项目学习随笔十七(ListView、GridView显示组图)
  8. SAP SD你要知道的透明表
  9. 百度地图 获取矩形point
  10. 用MT.exe将exe中的manifest文件提取出来和将manifest文件放入exe中
  11. GNU Binutils简介及基本用法
  12. Python3基础 list enumerate 将列表的每个元素转换成 带索引值的元组
  13. bootstrap模态框input不能获取焦点并编辑【转】
  14. Java的起源和发展
  15. Linux同时安装python2和Python3
  16. com.mysql.jdbc.PacketTooBigException,及mysql 设置 max_allow_packet
  17. python you-get 下载视频
  18. Using the FutureRequestExecutionService Based on classic (blocking) I/O handle a great number of concurrent connections is more important than performance in terms of a raw data throughput
  19. spark学习地址
  20. 判断不同浏览器,加载不同的css和js文件

热门文章

  1. linux下的文件和文件夹的权限问题
  2. 在Java中如何编写回调函数,以及回调函数的简单应用
  3. LCS的几种求法
  4. 移动web开发适配rem
  5. POJ1321 棋盘问题 —— DFS回溯
  6. 基于Vuejs的搜索匹配功能
  7. maven安装的详细步骤
  8. 在Service里调用AlertDialog
  9. Filter的基本配置
  10. 固定dll的加载基址的方法