RHCE 配置chrony

目录

1.chrony服务器

2.配置chrony

使其使用其他ntp服务器同步时间

查看时间服务器状态(ntp)timedatestatus

查看时间源状态 sources

跟踪当前同步状态 tracking

查看 ntp_servers 状态 sourcestats

查看 ntp_servers 是否在线  activity

 强制同步下系统时钟(也可重启服务)

 配置一个不可用的时间源

3.配置chrony 两台机器

查看状态


  • 1.chrony服务器

Chrony是一个开源自由的网络时间协议 NTP 的客户端和服务器软软件。它能让计算机保持系统时钟与时钟服务器(NTP)同步,因此让你的计算机保持精确的时间,Chrony也可以作为服务端软件为其他计算机提供时间同步服务。

Chrony由两个程序组成,分别是chronyd和chronyc

2.配置chrony

  • 使其使用其他ntp服务器同步时间

[root@192 ~]# rpm -qa | grep chrony
chrony-3.5-1.el8.x86_64
[root@192 ~]# vim /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#pool 2.rhel.pool.ntp.org iburst 
 #池    时间服务器地址       突发  
server ntp.aliyun.com      iburst
        #阿里云时间服务器地址

local stratum 10
当外部时间服务器不可用时,采用本地时间作为同步标准

[root@192 ~]# systemctl restart chronyd    #重启服务
  • 查看时间服务器状态(ntp)timedatestatus

[root@192 ~]# vim /etc/chrony.conf
[root@192 ~]# timedatectl status
               Local time: Sun 2022-09-18 05:32:25 EDT
           Universal time: Sun 2022-09-18 09:32:25 UTC
                 RTC time: Sun 2022-09-18 09:32:25
                Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes       #是否和写入时间服务器同步
              NTP service: active    #ntp服务是否开启
          RTC in local TZ: no

 System clock synchronized: yes       #是否和写入时间服务器同步
              NTP service: active    #ntp服务是否开启

  • 查看时间源状态 sources

[root@192 ~]# chronyc sources -v
210 Number of sources = 1

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* 203.107.6.88                  2   6   377    60   +671us[ +761us] +/-   40ms

* 表示chronyd当前同步到的源。

+ 表示可接受的信号源,与选定的信号源组合在一起。

- 表示被合并算法排除的可接受源。

? 指示已失去连接性或其数据包未通过所有测试的源。它也显示在启动时,直到从中至少收集了3个样本为止。

x 表示chronyd认为是虚假行情的时钟(即,其时间与大多数其他来源不一致)。

〜 表示时间似乎具有太多可变性的来源。

  • 跟踪当前同步状态 tracking

[root@192 ~]# chronyc tracking -v
Reference ID    : CB6B0658 (203.107.6.88)
Stratum         : 3
Ref time (UTC)  : Sun Sep 18 09:37:42 2022
System time     : 0.000442720 seconds fast of NTP time
Last offset     : +0.000742311 seconds
RMS offset      : 0.002190648 seconds
Frequency       : 4.251 ppm slow
Residual freq   : +0.268 ppm
Skew            : 10.283 ppm
Root delay      : 0.073850594 seconds
Root dispersion : 0.004093553 seconds
Update interval : 64.2 seconds
Leap status     : Normal

stratum:显示了来源的层,如其最近收到的样本中所报告的那样。层1表示一台具有本地连接的参考时钟的计算机。与第1层计算机同步的计算机位于第2层。与第2层计算机同步的计算机位于第3层,依此类推。

  • 查看 ntp_servers 状态 sourcestats

[root@192 ~]# chronyc sourcestats -v
210 Number of sources = 1
                             .- Number of sample points in measurement set.
                            /    .- Number of residual runs with same sign.
                           |    /    .- Length of measurement set (time).
                           |   |    /      .- Est. clock freq error (ppm).
                           |   |   |      /           .- Est. error in freq.
                           |   |   |     |           /         .- Est. offset.
                           |   |   |     |          |          |   On the -.
                           |   |   |     |          |          |   samples. \
                           |   |   |     |          |          |             |
Name/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev
==============================================================================
203.107.6.88               19  11   979     +0.122      6.602  +7128ns  2435us
  • 查看 ntp_servers 是否在线  activity

[root@192 ~]# chronyc activity -v
200 OK
1 sources online   #当前有一个时间源
0 sources offline
0 sources doing burst (return to online)
0 sources doing burst (return to offline)
0 sources with unknown address
  •  强制同步下系统时钟(也可重启服务)

[root@192 ~]# chronyc -a makestep

 配置一个不可用的时间源

[root@192 ~]# vim /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#pool 2.rhel.pool.ntp.org iburst
#server ntp.aliyun.com iburst
server s1a.time.edu.cn iburst  #不可用

[root@192 ~]# systemctl restart chronyd     启用
[root@192 ~]# timedatectl    查看状态
               Local time: Sun 2022-09-18 05:52:03 EDT
           Universal time: Sun 2022-09-18 09:52:03 UTC
                 RTC time: Sun 2022-09-18 09:52:03
                Time zone: America/New_York (EDT, -0400)
System clock synchronized: no
              NTP service: active
          RTC in local TZ: no

[root@192 ~]# chronyc sources -v

^? st0-bupt-1.ntp.edu.cn         0   7     0     -     +0ns[   +0ns] +/-    0ns

[root@192 ~]# chronyc sourcestats -v
time.buptnet.edu.cn         0   0     0     +0.000   2000.000     +0ns  4000ms

[root@192 ~]# chronyc tracking -v   查看ntp详细信息
Reference ID    : 00000000 ()
Stratum         : 0




3.配置chrony 两台机器

服务器端
[root@192 ~]# vim /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#pool 2.rhel.pool.ntp.org iburst
#server time1.aliyun.com iburst
server s1a.time.edu.cn iburst   不可用
allow 192.168.27.0/24    开启允许
local stratum 10        开启
客户端
[root@localhost ~]# vim /etc/chrony.conf
server 192.168.27.129  iburst
       服务器IP地址
  • 查看状态

客户端
root@localhost ~]# timedatectl
               Local time: Sun 2022-09-18 07:04:28 EDT
           Universal time: Sun 2022-09-18 11:04:28 UTC
                 RTC time: Sun 2022-09-18 11:04:29
                Time zone: America/New_York (EDT, -0400)
System clock synchronized: no
              NTP service: active
          RTC in local TZ: no

[root@localhost ~]# chronyc sources -v
^* 192.168.27.129               10   6    17    48    -24us[ -322us] +/-  347us

[root@localhost ~]# chronyc tracking -v
Reference ID    : C0A81B81 (192.168.27.129)
Stratum         : 11   服务器是10 客户端加1

服务器
[root@192 ~]# chronyc tracking -v
Reference ID    : 7F7F0101 ()
Stratum         : 10

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值