Linux   发布时间:2022-04-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用NTP将一组Linux服务器同步到一个公共时间源大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我有20个左右的 Linux服务器,我想将所有时钟同步到一个NTP服务器,它与我的服务器位于同一个机架和交换机中.什么都没有虚拟化. 我们的管理员无法在同步的各种机器上获得超过500毫秒的时钟.我猜对了,this post意味着我们应该能够让linux盒子在源和对方的2毫秒内同步. 我对NTP的期望是否不合理?关于管理员应该做什么/检查的任何提示? 我拥有一家托管公司,我们正是这样做的.以下是我们
我有20个左右的 Linux服务器,我想将所有时钟同步到一个NTP服务器,它与我的服务器位于同一个机架和交换机中.什么都没有虚拟化.

我们的管理员无法在同步的各种机器上获得超过500毫秒的时钟.我猜对了,this post意味着我们应该能够让linux盒子在源和对方的2毫秒内同步.

我对NTP的期望是否不合理?关于管理员应该做什么/检查的任何提示

解决方法

我拥有一家托管公司,我们正是这样做的.以下是我们如何实现这一目标.

首先,您需要一个NTP主源.因此,您的一台Linux服务器将成为主服务器.我将创建一个名为time.example.com的DNS A记录(假设example.com是域).这样,如果你的主人移动你不需要更新其他19个服务器.

在主服务器上,您需要具有适当配置的ntp.conf文件.

这是我们的主/etc/ntp.conf文件之一.请注意,这是一个使用172.17.x.x的私有地址空间(RFC1918)的数据中心,因此您需要相应地进行调整.如果您需要多个主服务器,请创建多个具有不同IP的DNS A记录,以便在需要时获得一些容错能力.

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,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端口访问公共Internet.这是一个典型且适当放置的IPTables规则

iptables -t nat -A POSTROUTING -o $PUB_IF -p udp –dport 123 -j MASQUERADE

PUB_IF是公共接口(eth0,eth1,等等)

大佬总结

以上是大佬教程为你收集整理的使用NTP将一组Linux服务器同步到一个公共时间源全部内容,希望文章能够帮你解决使用NTP将一组Linux服务器同步到一个公共时间源所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: