首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CentOS 7中的NTP同步

CentOS 7中的NTP同步
EN

Unix & Linux用户
提问于 2016-03-05 08:47:37
回答 3查看 10.4K关注 0票数 1

我在CentOS 7机器(虚拟机器)上配置了NTP服务器,并配置了客户端的ntp.conf文件(也是虚拟的并运行CentOS 7)。当我在客户机上使用"systemctl (re)start ntpd“显式启动/重新启动ntpd服务时,NTP同步工作得很好。但是,当我试图通过更改服务器上的时间来测试“自动”同步时,客户端既不会收到“通知”,也不会更新他们的时钟(时钟在ntpd上一次重新启动时保持同步)。我甚至试图从客户端的ntp.conf文件中更改轮询频率,但似乎没有什么效果。我真的很感谢你的帮助。

PS:以下是来自服务器和一个客户端的ntp.conf文件:

服务器:

代码语言:javascript
复制
# 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

# 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
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 127.127.1.0

fudge 127.127.1.0 stratum 1

#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

客户端:

代码语言:javascript
复制
# 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

# 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
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 192.168.1.38 #This is the ip address of the server

#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
EN

回答 3

Unix & Linux用户

发布于 2016-03-05 12:13:03

我认为您还必须取消对服务器上的restrict行的注释,以使ntp在该网络中可用。然后重新启动ntpd

代码语言:javascript
复制
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

在客户端,还可以将iburst添加到服务器配置行,这将加快初始时钟同步并重新启动ntpd

代码语言:javascript
复制
server 192.168.1.38 iburst

使用ntpq -p,您可以列出服务器以及是否建立了连接。

票数 2
EN

Unix & Linux用户

发布于 2016-03-05 21:23:04

关于您的配置的几个注意事项:

我使用的一个一般规则是:

  • 不要将ntp服务器放在虚拟机上
  • 不要信任ntp服务器上的本地时钟。

您将使用隔离网络(因此无法联系到池服务器)。你可能得依赖硬件时钟了。但是尝试将ntp服务器从VM中取出。

对于客户端,在VM中,我总是在ntp.conf中作为第一行:

代码语言:javascript
复制
tinker panic 0

这样,当有一个大的时间偏移时,NTP就不会恐慌。

票数 2
EN

Unix & Linux用户

发布于 2016-03-05 09:19:46

在(Re)启动期间,您可能没有与ntpd同步,但是通过使用ntpdate (您可以检查/etc/sysconfig/ntpdate是否存在)。

此外,他的客户可能对自己的时钟有一些信任,不会做出任何突然的跳跃。ntpd,如果在主时钟中遇到突然的变化(也就是那些对你来说很明显的变化),就会假设主时钟有故障,并继续自己的时间。

由于你没有解释你为什么要这么做,所以如果你不必这样做的话,除了不要和ntp玩以外,很难给出建议。

您还应该反复检查chronyd和/或systemd的时间同步不干扰您的实验。

票数 0
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/267771

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档