centos 7 ntp

﹏ヽ暗。殇╰゛Y 2023-11-01 06:52 275阅读 0赞

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

服务数量上,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

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

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

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

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

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

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

  1. ntpdate[19479]: no server suitable for synchronization found

发表评论

表情:
评论列表 (有 0 条评论,275人围观)

还没有评论,来说两句吧...

相关阅读

    相关 centos 7 ntp

    程序员近来摊上个自动化运维的项目。 服务数量上,NTP客户端有两个,服务端只有一个。客户端分别是ntpd和ntpdate,服务端只有ntpd。 ntpd的配置文件/e

    相关 centos7 ntp时间同步

    一 应用场景 公司分配给你两台服务器,要求你使他们时间同步,有人问为什么要时间同步?如果一个集群中,时间相差很大,那么会出现很多诡异的问题,你也不想在一个无法解决的问题上浪费

    相关 centos7 ntp设置 时间同步

    一 应用场景 公司分配给你两台服务器,要求你使他们时间同步,有人问为什么要时间同步?如果一个集群中,时间相差很大,那么会出现很多诡异的问题,你也不想在一个无法解决的问题上浪费