NTP简单介绍

度娘说:
NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议。
官方安装文档说:
You must install NTP to properly synchronize services among nodes. We recommend that you configure the controller node to reference more accurate (lower stratum) servers and other nodes to reference the controller node.
我说:NTP就是一个同步两个节点之间时间的工具,controller可以设一个高级点的服务器,同步时间;conpute节点就可以与controller node 同步了。

Controller node

1.安装NTP服务

# yum install ntp

2.配置NTP服务
编辑 /etc/ntp.conf

server NTP_SERVER  iburst//配置NTP服务器;配置文件里原本就有很多服务器,直接使用即可。
restrict -4 default kod notrap nomodify
restrict -6 default kod notrap nomodify

注意:restrict default kod nomodify notrap nopeer noquery
这个命令是拒绝默认主机的一切操作。
nomodify; notrap ;nopeer ;noquery
控制节点允许计算节点查询,所以将restrict关键字中去除noquery,nopeer 。
修改后的配置文件

# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).driftfile /var/lib/ntp/drift# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
#restrict default nomodify notrap nopeer noquery//只是配置文件默认的操作restrict -4 default kod notrap nomodify//允许所有IPv4查询
restrict -6 default kod notrap nomodify//允许所有IPv6查询
# 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 //允许本机的所有操作
restrict ::1//允许本机的所有操作# 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.centos.pool.ntp.org iburst   //设置ntp服务器
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst#broadcast 192.168.1.255 autokey    # broadcast server
#broadcastclient            # broadcast client
#broadcast 224.0.1.1 autokey        # multicast server
#multicastclient 224.0.1.1      # multicast client
#manycastserver 239.255.254.254     # manycast server
#manycastclient 239.255.254.254 autokey # manycast client# Enable public key cryptography.
#cryptoincludefile /etc/ntp/crypto/pw# 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# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor

对于该配置文件的详细解释:

http://blog.csdn.net/iloli/article/details/6431757

3.启动NTP服务,并且设置开机自启。

#systemctl enable ntpd.service//开机自启
# systemctl start ntpd.service//启动ntp服务

4.验证
官方文件的操作命令:
1.

[root@controller ~]# ntpq -c peers
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+news.neu.edu.cn 202.118.1.46     2 u   23   64    3   45.755  151.969 140.120
*202.118.1.130   202.118.1.47     2 u   15   64    1   48.615  172.009  15.529

各个指标的解释:

remote: 它指的就是本地机器所连接的远程NTP服务器
refid: 它指的是给远程服务器(202.118.1.130 )提供时间同步的服务器
st: 远程服务器的层级别(stratum). 由于NTP是层型结构,有顶端的服务器,多层的Relay Server再到客户端. 所以服务器从高到低级别可以设定为1-16. 为了减缓负荷和网络堵塞,原则上应该避免直接连接到级别为1的服务器的.
t: 这个…..我也不知道啥意思^_^
when: 我个人把它理解为一个计时器用来告诉我们还有多久本地机器就需要和远程服务器进行一次时间同步
poll: 本地机和远程服务器多少时间进行一次同步(单位为秒). 在一开始运行NTP的时候这个poll值会比较小,那样和服务器同步的频率也就增加了,可以尽快调整到正确的时间范围.之后poll值会逐渐增大,同步的频率也就会相应减小
reach: 这是一个八进制值,用来测试能否和服务器连接.每成功连接一次它的值就会增加
delay: 从本地机发送同步要求到服务器的round trip time
offset: 这是个最关键的值, 它告诉了我们本地机和服务器之间的时间差别. offset越接近于0,我们就和服务器的时间越接近
jitter: 这是一个用来做统计的值. 它统计了在特定个连续的连接数里offset的分布情况. 简单地说这个数值的绝对值越小我们和服务器的时间就越精确

那么大家细心的话就会发现两个问题: 第一我们连接的是0.uk.pool.ntp.org为什么和remote server不一样? 第二那个最前面的+和*都是什么意思呢?

第一个问题不难理解,因为NTP提供给我们的是一个cluster
server所以每次连接的得到的服务器都有可能是不一样.同样这也告诉我们了在指定NTP Server的时候应该使用hostname而不是IP

第二个问题和第一个相关,既然有这么多的服务器就是为了在发生问题的时候其他的服务器还可以正常地给我们提供服务.那么如何知道这些服务器的状态呢?
这就是第一个记号会告诉我们的信息

*它告诉我们远端的服务器已经被确认为我们的主NTP Server,我们系统的时间将由这台机器所提供
+ 它将作为辅助的NTP Server和带有号的服务器一起为我们提供同步服务. 当号服务器不可用时它就可以接管
- 远程服务器被clustering algorithm认为是不合格的NTP Server x 远程服务器不可用

2.`

[root@controller ~]#  ntpq -c assocind assid status  conf reach auth condition  last_event cnt
===========================================================
  1  3104  961a   yes   yes  none  sys.peer    sys_peer  1
  2  3105  943a   yes   yes  none candidate    sys_peer  3
`

官方文档上,可以用这两个命令验证有没有正确安装ntp,
我在学习的时候还接触到别的好用的验证命令。

# watch ntpq -p//与 ntpq -c peers效果差不多
#ntpstat
synchronisedpolling server every 64 s//可以显示最近有没有成功同步;能同步肯定没问题,没同步也可能只是暂时没成功。

compute node

1.安装NTP服务

# yum install ntp

2.配置文件
文件是: /etc/ntp.conf

server controller  iburst////将设置NTP服务器的字段全部注释,加入controller作为服务器

3.启动NTP服务,并且设置开机自启。

# systemctl enable ntpd.service
# systemctl start ntpd.service

4.验证
官方文件的操作命令:

[root@computer_node ~]#  ntpq -c peersremote           refid      st t when poll reach   delay   offset  jitter
==============================================================================controller      .XFAC.          16 u    -   64    0    0.000    0.000   0.000

注意:compute节点的服务器是controller,但是如上图显示,状态是有问题的。正确的st是0~15,我造成这个样子的原因是controller node 没有启动。

 ntpq -c assocind assid status  conf reach auth condition  last_event cnt
===========================================================
  1  4034  8011   yes    no  none    reject    mobilize  1

同样这样的显示也是错误的,原因也是controller node 没有启动。
官方文档的正确样例:

同 controller node一样,可以用 watch ntpq -p与
ntpstat 查看状态。

问题

用ntpdate –d时有错误信息如下:

transmit(192.168.11.3)  transmit(192.168.11.3) transmit(1192.168.11.3) transmit192.168.11.3) transmit(192.168.11.3)
192.168.11.3: Server dropped: no data server 192.168.11.3, port 123  ..... 

后来我又用tcpdump抓包,发现只有客户端到服务器的请求消息,没有消息回应,后来发现是防火墙没关。
关闭防火墙请参照小白装openstack(一) 网络配置

小白装openstack(二) 安装NTP服务相关推荐

  1. Linux离线安装NTP服务,内网环境下配置本地时间同步

    参考文章:Linux离线安装NTP服务,无外网环境下配置本地时间同步 | 航行学园 1.常用命令 rpm -qa | grep ntp #查询已安装的ntp版本信息等 rpm -e --nodeps ...

  2. linux系统上安装ntp服务,linux时间同步ntp服务的安装与配置

    NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议. 1.安装ntp服务,要使用时间同步.那么服务端与客户端都需要使用如下命令安装NTP软件包 ...

  3. linux ntp rpm包下载,centos7.5 离线安装ntp服务

    一.先查看ntp是否已经安装:rpm -q ntp 二.查看系统版本 三.下载ntp组件 centos7.5版本 #从https://pkgs.org/download/ntp 下载rpm包 ntp- ...

  4. REDHAT7 安装NTP服务

    1.使用root用户登录linux: 2.如果系统没有联网yum源,需要将LINUX安装盘挂载到本地,并设置本地yum源 在/etc/yum.repos.d下建立iso.repo 内容如下: [iso ...

  5. 在树莓派是安装并配置NTP服务

    我们都知道树莓派的小巧和省电节省空间等太多的优势,这里就不一一列举了,那么树莓派就需要长时间的运行,可以7×24的方式运行,那么我们就把树莓派当作一个小的服务器来运行,可以跑一些小的应用,例如可以在局 ...

  6. CentOS7时间同步NTP服务安装及配置

    目录 一 说明 二 服务安装 1.查询是否已安装NTP服务 2.在线安装 3.离线安装 三 使用NTPD方式同步时间 1.参数配置 2.启动 四.使用定时同步方式 1.手动执行时间同步 2.定时同步时 ...

  7. 安装时间同步ntp服务,过程中报错no module named urlgrabber.grabber

    安装时间同步脚本需要安装ntp服务,但是安装过程中报错如下截图 yum -y install ntp ntpdate 原因是系统初始化脚本,编译python ,bin程序是放在这个目录下的.平台这边把 ...

  8. centos7 校正linux系统时间_基于centos7系统部署NTP服务及配置时间定时同步

    概述 linux服务器在提供服务时,要和其他机器进行请求的交互,实际生产环境中,可能因为时间不同步,导致了服务异常. 下面介绍下怎么部署NTP服务来解决这个问题. ps:强烈吐槽下头条这个新排版功能, ...

  9. linux ntp时间立即同步命令_记一次生产环境部署NTP服务及配置时间同步

    概述 linux服务器在提供服务时,要和其他机器进行请求的交互,实际生产环境中,可能因为时间不同步,导致了服务异常. 下面介绍下怎么部署NTP服务来解决这个问题. ps:强烈吐槽下头条这个新排版功能, ...

最新文章

  1. 关于虚拟化技术软硬件兼容问题的探讨
  2. 冒泡排序,斐波拉契迭代、生成器
  3. NVIDIA Jetson Xavier NX上导入tensorflow报错:AttributeError: module ‘wrapt‘ has no attribute ‘ObjectProxy‘
  4. 如何写一个好的方法-读Clean Code 有感
  5. 计算机科学与技术及应用,计算机科学与技术的应用及发展趋向
  6. 神经架构搜索(Neural Architecture Search,NAS)介绍
  7. 第五节 系统调用的三个层次(下) ——20135203齐岳
  8. js 跨域深入理解与解决方法
  9. php函数end,PHP end()函数
  10. 为什么使用事务?如何实现声明式事务?
  11. 向日葵,teamviewer
  12. 模拟高清和数字高清摄像机的区别,全局快门CMOS 图像传感器,Interline Transfer CCD图像传感器
  13. 需求与商业模式分析-6-五个课题
  14. 更改文件夹目录、硬盘、U盘的图标
  15. HTML页面嵌入视频无法播放的常见原因
  16. 基于三点说构成的夹角提取特征点
  17. 中国电信 smgp java_smgp.java~1~ 源代码在线查看 - 中国电信小灵通短信平台SP端程序 资源下载 虫虫电子下载站...
  18. 小程序解码wx.getUserInfo中的decryptData数据
  19. XXXXX was compiled with optimization - stepping may behave oddly; variables may not be available.
  20. 9、MyBatis的动态SQL

热门文章

  1. 如何使用sql语句算两经纬度的距离
  2. 练习:尼姆游戏(聪明版/傻瓜式•人机对战)
  3. Control Egress Traffic
  4. java jsoup解析开彩网api接口json数据实例
  5. (附源码)计算机毕业设计SSM流浪动物救助系统
  6. 架构专家李伟山:电商系统之订单系统
  7. 关于图像打印的思考.
  8. Gluster 常用操作命令
  9. Excel中怎么把一数列数据,用逗号隔开合并到一行
  10. 微信支付服务器端php,APP微信支付php服务端函数方法