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

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

为什么我要记录这个文章?

因为这玩意很简单,花了我几乎一天的时间.

总是报错,尝试修改配置,继续报错,再我几乎绝望,想吐槽 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 真好用.

标签:10.100,centos,ntp,server,conf,org,ntpd

来源: https://www.cnblogs.com/ayanmw/p/12872495.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值