centos 7 ntp

程序员近来摊上个自动化运维的项目。

服务数量上,NTP客户端有两个,服务端只有一个。客户端分别是ntpd和ntpdate,服务端只有ntpd。

  • ntpd的配置文件/etc/ntp.conf
  • ntpdate的配置文件/etc/ntp/step-tickers

作为客户端:
ntpdate {{server}}又被称为手动同步,与cron结合可以实现自动同步,缺点是容易造成断秒,并且与ntpd占用相同端口(反亲和)。
ntpd方式为持续跟踪,所以又被称为自动同步,缺点是当时间差距过大(据说10分钟),无法跟踪。

内网和网关同步、网关和时钟同步,这种情况下网关只能用ntpd。
/etc/ntp.conf配置,主要就两条:
(作为客户端)我要和谁同步:server {{ server }}
(作为服务端)允许谁和我同步: restrict {{ ip }} mask {{ netmask }} {{ flags }}
(同时客户服务端)额外还有个,我的层级:fudge {{ server }} stratum {{ level }}
fudge对于纯客户端来说没有意义,只有在同时作为客户端和服务端的时候才有意义。

例子:
网关同时客户服务端的配置:
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1
restrict 172.28.15.0 mask 255.255.255.0 nomodify notrap
server 172.28.11.10
fudge 172.28.11.10 stratum 8
includefile /etc/ntp/crypto/pw
disable monitor

纯客户端的配置:
driftfile /var/lib/ntp/drift # 频飘,ppm单位
restrict default nomodify notrap nopeer noquery # 写不写这行都一样。所有主机不能变更我的时间、不能peer我、也不能查询
restrict 127.0.0.1 # lo接口可以随便
restrict ::1 # lo接口随便
server 172.28.15.15
fudge 172.28.15.15 stratum 10 # 必须大于NTP服务器的层级。0为最高级
restrict 172.28.15.15 nomodify notrap noquery # server不能变更和查询我的时间。
includefile /etc/ntp/crypto/pw # 包括配置文件
disable monitor # 与安全有关

flag之一的notrap不知道啥意思,不能陷阱我?

配置文件搞好后,以内网纯客户端为例:
ntpdate {{ server }} # 手动修改本地时间与服务器同步
service ntpd restart # 启动本地ntpd

> $ ntpq -p
>      remote           refid      st t when poll reach   delay   offset  jitter
> ==============================================================================
>  172.28.15.15    172.28.11.10     4 u   29   64    1    0.964   -0.617   0.000

remote一栏前面是空格,表示没有同步上。同步需要一分钟左右。

> $ ntpq -p
>      remote           refid      st t when poll reach   delay   offset  jitter
> ==============================================================================
> *172.28.15.15    172.28.11.10     4 u   17   64   77    0.864   -1.800   0.643

remote一栏前面是*表示同步上了。
还可以用netstat看:

> $ ntpstat 
> synchronised to NTP server (172.28.15.15) at stratum 5   
> time correct to within 64 ms    polling server every 64 s

只有当{{ server }}开启了ntpd服务时,才能实现ntpdate {{ server }},如果{{ server }}没开ntpd:

 ntpdate[19479]: no server suitable for synchronization found
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值