Rocky Linux 9 配置时间同步服务 chrony

默认 Rocky Linux 9 已使用 chrony 时间服务,所以我们不需要再单独去安装 dnf install -y chrony,只需要配置对应的时间同步服务器即可。

NTP 服务器配置

vi /etc/chronyd.conf
# 添加阿里云NTP服务器
pool ntp1.aliyun.com iburst
pool ntp2.aliyun.com iburst
pool cn.pool.ntp.org iburst
# 允许指定网段访问此时间服务器,不然只允许本地网络
allow 172.16.0.0/16

# 设置时区为亚洲/上海
timedatectl set-timezone Asia/Shanghai

# 配置防火墙,也可以设置允许123/UDP端口
firewall-cmd --add-service=ntp
firewall-cmd --runtime-to-permanent

# 重启时间服务 & 查看服务启动状态
systemctl restart chronyd && systemctl status chronyd

# 设置开机自启动
systemctl enable chronyd

# 验证工作是否正常
[root@localhost ~]# chronyc sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* 120.25.115.20                 2  10   347   815    -54us[  -65us] +/- 4415us
^- 203.107.6.88                  2  10   377   192  -5352us[-5352us] +/-   30ms
^- ntp5.flashdance.cx            2  10   245   725   -858us[ -858us] +/-  173ms
^- tock.ntp.infomaniak.ch        1  10   377   521  +1361us[+1361us] +/-  106ms
^- ntp.wdc1.us.leaseweb.net      2  10   375    91   +409us[ +409us] +/-  229ms
^- time.cloudflare.com           3  10   375   109  +1262us[+1262us] +/-  107ms

NTP 客户端配置

NTP客户端配置与服务器端配置基本相同,但是因为NTP客户端不需要接收来自其他主机的时间同步请求,因此不需要指定allow ***这行。
另外如果您的客户端不是 Rocky Linux 9,那么需要单独安装chrony服务。

# 安装chrony服务
dnf install -y chrony

# 就像`ntpdate`命令一样,我们可以使用`chronyd`命令手动将Linux服务器的时间与远程NTP服务器进行同步。
[root@outline ~]# chronyd -q 'server 172.16.11.141 iburst'
2022-12-02T06:55:47Z chronyd version 3.4 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +SECHASH +IPV6 +DEBUG)
2022-12-02T06:55:47Z Initial frequency -9.614 ppm
2022-12-02T06:55:51Z System clock wrong by -0.000004 seconds (step)
2022-12-02T06:55:51Z chronyd exiting

# 配置服务器参数
vi /etc/chrony.conf
server 172.16.11.141 iburst

# 重启时间服务 & 查看服务启动状态
systemctl restart chronyd && systemctl status chronyd

# 设置开机自启动
systemctl enable chronyd

验证chrony的同步

# 在服务器端查看有哪些客户端通过此NTP服务器进行时钟同步
[root@localhost ~]# chronyc clients
Hostname                      NTP   Drop Int IntL Last     Cmd   Drop Int  Last
===============================================================================
172.16.11.188                 275      0  10   -  1076       0      0   -     -

# 验证系统时间是否已使用chrony同步
[root@outline ~]# chronyc tracking 
Reference ID    : AC100B8D (172.16.11.141)
Stratum         : 4
Ref time (UTC)  : Fri Dec 02 07:01:43 2022
System time     : 0.000000019 seconds fast of NTP time
Last offset     : -0.000016983 seconds
RMS offset      : 0.000016983 seconds
Frequency       : 9.614 ppm slow
Residual freq   : -1.633 ppm
Skew            : 0.089 ppm
Root delay      : 0.006188698 seconds
Root dispersion : 0.001516752 seconds
Update interval : 2.0 seconds
Leap status     : Normal

# 检查chrony来源,列出有关chronyd使用的当前时间源的信息
[root@outline ~]# chronyc sources
210 Number of sources = 1
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* 172.16.11.141                 3   6    37    39   +765ns[  +94us] +/- 4682us

# 列出有关chronyd使用的每个源的漂移速度和偏移估计的信息
[root@outline ~]# 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
==============================================================================
172.16.11.141               6   5   136     +0.306      3.073    +11us    42us

# 默认情况下,NTP 客户端每64秒执行一次时间同步。但是,您可以手动调整时钟而无需等待下一次同步轮询。
[root@outline ~]# chronyc makestep
200 OK
Avatar photo

关于 木子

Founder of the Rocky Linux Chinese community, MVP、VMware vExpert、TVP, advocate for cloud native technologies, with over ten years of experience in site reliability engineering (SRE) and the DevOps field. Passionate about Cloud Computing、Microservices、CI&CD、DevOps、Kubernetes, currently dedicated to promoting and implementing Rocky Linux in Chinese-speaking regions.
用一杯咖啡支持我们,每一篇 [文档] 都经过我们实操,并非从网上一味的copy,期间花费了大量的心思,希望能够帮忙到您。

评论

  1. small_parking
    1年前
    2023-1-19 14:52:50

    挺好的,挺实用的

    • Avatar photo
      博主
      small_parking
      1年前
      2023-1-19 18:27:33

      必须🉐️ @-@ !!!

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇