小白装openstack(二) 安装NTP服务

7 篇文章 0 订阅
6 篇文章 0 订阅

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.
#crypto

includefile /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 assoc

ind 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
synchronised
   polling 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 peers
     remote           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 assoc

ind 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(一) 网络配置

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值