使用NTP将一组Linux服务器同步到一个公共时间源

前端之家收集整理的这篇文章主要介绍了使用NTP将一组Linux服务器同步到一个公共时间源前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有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记录,以便在需要时获得一些容错能力.

  1. server 127.127.1.0 # local clock
  2. fudge 127.127.1.0 stratum 10
  3.  
  4. server 0.north-america.pool.ntp.org
  5. server 1.north-america.pool.ntp.org
  6. server 2.north-america.pool.ntp.org
  7. server 3.north-america.pool.ntp.org
  8.  
  9.  
  10. # Logging & Stats
  11. statistics loopstats
  12. statsdir /var/log/ntp/
  13. filegen peerstats file peers type day link enable
  14. filegen loopstats file loops type day link enable
  15.  
  16. # Drift file. Put this in a directory which the daemon can write to.
  17. # No symbolic links allowed,either,since the daemon updates the file
  18. # by creating a temporary in the same directory and then rename()'ing
  19. # it to the file.
  20. #
  21. driftfile /etc/ntp/drift
  22. broadcastdelay 0.008
  23.  
  24. restrict default noquery nomodify
  25.  
  26. restrict 0.north-america.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
  27. restrict 1.north-america.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
  28. restrict 2.north-america.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
  29. restrict 3.north-america.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
  30.  
  31. # Allow LAN to query us
  32. restrict 172.17.0.0 mask 255.255.0.0 nomodify notrap
  33.  
  34. # Trust ourselves. :-)
  35. restrict 127.0.0.1

现在在每个客户端上,我们有一个/etc/ntp.conf文件,如下所示:

  1. server 127.127.1.0 # local clock
  2. fudge 127.127.1.0 stratum 10
  3. server time.example.com
  4.  
  5. # Drift file. Put this in a directory which the daemon can write to.
  6. # No symbolic links allowed,since the daemon updates the file
  7. # by creating a temporary in the same directory and then rename()'ing
  8. # it to the file.
  9.  
  10. driftfile /etc/ntp/drift
  11. multicastclient # listen on default 224.0.1.1
  12. broadcastdelay 0.008
  13.  
  14. # Don't serve time or stats to anyone else by default (more secure)
  15.  
  16. restrict default noquery nomodify
  17.  
  18. restrict time.example.com mask 255.255.255.255 nomodify notrap noquery
  19.  
  20. # Allow LAN to query us
  21. restrict 172.17.0.0 mask 255.255.0.0 nomodify notrap
  22.  
  23. # Trust ourselves. :-)
  24. 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,等等)

猜你在找的Linux相关文章