我有大约20台linux服务器,我想把它们所有的时钟同步到一个NTP服务器上,NTP服务器和我的服务器在同一个机架上切换。没有东西是虚拟化的。
我们的管理员很难让各种机器上的时钟同步比大约500毫秒更接近。我已经猜到了,这个职位意味着我们应该能够将linux同步到离源和彼此不到2ms的地方。
我对NTP的期望是否不合理?对于管理员应该做什么/检查有什么提示吗?
发布于 2010-11-19 23:23:56
我拥有一家托管公司,而我们正是这样做的。我们是如何做到这一点的。
首先,您需要一个NTP主源。所以你的一个Linux服务器将成为主服务器。我会创建一个名为time.example.com的DNS记录(假设example.com是域)。这样,如果您的主机移动,您不需要更新其他19个服务器。
在主服务器上,需要有一个适当配置的ntp.conf文件。
下面是我们的一个主文件/etc/ntp.conf文件的样子。注意,这是一个具有私有地址空间(RFC1918)的数据中心,使用172.17.x.x,因此您需要进行相应的调整。如果您需要多个主服务器,请创建多个DNS A记录,每个记录具有不同的IP,如果需要的话,可以获得一些容错性。
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
server 0.north-america.pool.ntp.org
server 1.north-america.pool.ntp.org
server 2.north-america.pool.ntp.org
server 3.north-america.pool.ntp.org
# Logging & Stats
statistics loopstats
statsdir /var/log/ntp/
filegen peerstats file peers type day link enable
filegen loopstats file loops type day link enable
# Drift file. Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()'ing
# it to the file.
#
driftfile /etc/ntp/drift
broadcastdelay 0.008
restrict default noquery nomodify
restrict 0.north-america.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
restrict 1.north-america.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
restrict 2.north-america.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
restrict 3.north-america.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
# Allow LAN to query us
restrict 172.17.0.0 mask 255.255.0.0 nomodify notrap
# Trust ourselves. :-)
restrict 127.0.0.1现在,在每个客户机上,我们有一个/etc/ntp.conf文件,如下所示:
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
server time.example.com
# Drift file. Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()'ing
# it to the file.
driftfile /etc/ntp/drift
multicastclient # listen on default 224.0.1.1
broadcastdelay 0.008
# Don't serve time or stats to anyone else by default (more secure)
restrict default noquery nomodify
restrict time.example.com mask 255.255.255.255 nomodify notrap noquery
# Allow LAN to query us
restrict 172.17.0.0 mask 255.255.0.0 nomodify notrap
# Trust ourselves. :-)
restrict 127.0.0.1使用ntpq命令查看与其同步的服务器。它为您提供了配置时间服务器的列表,以及您的服务器正在经历的延迟、偏移和抖动。为了进行正确的同步,延迟和偏移值应为非零,抖动值应小于100。
同样在我们的客户端节点上,我们有一个rc脚本(/etc/rc.d/rc.local),它在启动NTPD守护进程之前同步时钟。这是重要的部分..。它们依赖于秩序。
将客户端时钟与主时间源/usr/sbin/ntpdate -b time.example.com同步
启动NTPD守护进程,允许在启动期间进行大量时间调整./usr/sbin/ntpd -g -x
最后,根据您的设置,您需要编写防火墙规则,以允许您的time.example.com主机通过UDP端口到达公共互联网。下面是一个典型的和适当放置的IPTables规则
iptables -t nat -A POSTROUTING -o $PUB_IF -p udp -dport 123 -j伪装
其中PUB_IF是公共接口(eth0,eth1,什么的)
发布于 2010-11-19 21:22:49
正确配置的NTP将在几毫秒内实现同步。我总是确保每个NTP客户端至少与三个NTP服务器通信。
使用ntpq -p来监视状态-它应该给出为什么您没有得到更好的同步。
发布于 2010-11-19 20:43:59
我不确定wheather你能实现如此少的时间同步,但正确的ntp服务器的配置将使服务器同步几乎10-20毫秒,我已经在我的服务器上做了。尽量减少漂移时间。这并不是不可能的,但是在设置了NTP服务器并将所有服务器指向该NTP服务器并第一次手动同步启动时间之后,可以减少差异b/w服务器的时间。
https://serverfault.com/questions/204082
复制相似问题