页首Html代码

返回顶部

centos linux ntp.conf 配置中 fudge 参数找不到

你看到的这个文章来自于http://www.cnblogs.com/ayanmw

最近服务器被迫关机了一次,突然想把时间同步服务搞一搞 (内网 环境,无法连接互联网)

为什么我要记录这个文章?
因为这玩意很简单,花了我几乎一天的时间.
总是报错,尝试修改配置,继续报错,再我几乎绝望,想吐槽 linux ntpd 垃圾的时候,它突然生效了,
只是因为加了一个配置interface listen 10.100.2.242,也或许是因为刚好需要等待的时间到了.
我就不明白了,为什么网上都说要等几分钟才能生效呢? 我用ntpdate -d -v $IP 来同步,为什么给我
报错,我还不知道该怎么修改.
活该 linux 这么难用.

ntpd 服务器配置(10.100.2.242)

vim ntp.conf

# 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
restrict 10.100.2.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.1 burst true prefer
#fudge 127.127.1.1 stratum 8
interface listen 10.100.2.242
#... 省略后面的了

关键的地方在于:

针对指定局域网网段是生效
restrict 10.100.2.0 mask 255.255.255.0 nomodify notrap
设置服务器自己作为单独的一个ntpd 服务器来提供服务
server 127.127.1.1 burst true prefer
再上述配置增加后,还不生效,神奇的,我找到了下面的几乎无人提及配置,貌似生效了
interface listen 10.100.2.242
这个在man手册都没看到,怎么了?
fudge 127.127.1.1 stratum 0

fudge参数貌似不生效

ntpd --version
ntpd 4.2.6p5

根据 ntp.org 的记录,最新版本是4.2.8pX 系列, 这应该是版本问题了;

ntp 客户端配置 (10.100.2.243-249) 全部使用10.100.2.242的时间配置

客户端就简单了,当测试ok,我就批量操作了:

yum install ntpd -y
sed -i 's/^server/#server/g' /etc/ntp.conf 
line=`grep "#server" /etc/ntp.conf -n|tail -n 1|cut -d ':' -f 1`
if test -z "$line";then echo "not found server ";return;fi
sed -i -e "$line a server 10.100.2.242 prefer iburst" /etc/ntp.conf 
systemctl enable ntpd||chkconfig --level 345 ntpd on
systemctl restart ntpd||service ntpd restart
ntpstat ; ntpq -p; ntpdate -d
date
ntpdate -v -d 10.100.2.242
date

终于生效了,开启各种ntpd服务,最好不要用crontab来写ntpdate的定时命令,ntpdate只适合手动运行.

后来又查了一下,原来windows的w32time服务也是支持ntpd的, 既可以配置为ntpd server,也可以作为ntp client
链接ntpd server(不管是win还是linux的,通通支持),最关键的,配置很简单,使用很简单.

所以 linux 真好用.

REF: http://doc.ntp.org/
ntp.conf:很少有人提及的事
ntp的interface listen配置,绑定监听

转载请注明出处:http://www.cnblogs.com/ayanmw 我会很高兴的!

posted @   ayanmw  阅读(2485)  评论(2编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
历史上的今天:
2014-05-11 【已解决】Android微信开放平台,申请移动应用的 应用签名 如何获取

页脚Html代码

点击右上角即可分享
微信分享提示