当前位置:   article > 正文

chrony服务配置_chrony.conf

chrony.conf

1、chrony服务

chrony 是网络时间协议 (NTP) 的通用实现。它可以将系统时钟与 NTP 服务器、参考时钟(例如 GPS 接收器)以及使用手表和键盘的手动输入同步。它还可以作为 NTPv4 (RFC 5905) 服务器和对等点运行,为网络中的其他计算机提供时间服务。

它旨在在广泛的条件下运行良好,包括间歇性网络连接、严重拥塞的网络、不断变化的温度(普通计算机时钟对温度很敏感)以及不能连续运行或在虚拟机上运行的系统。

通过 Internet 同步的两台机器之间的典型精度在几毫秒内;在 LAN 上,精度通常为几十微秒。使用硬件时间戳或硬件参考时钟,亚微秒精度可能是可能的。

chrony 中包含两个程序,chronyd 是一个可以在引导时启动的守护进程,chronyc 是一个命令行界面程序,可用于监视 chronyd 的性能并在其运行时更改各种操作参数。

centos7+ 支持chrony时间同步配置,ntp在centos8上已经不再支持了
chrony相比ntp时间同步配置更简单高效,它是一个开源的软件能保持系统始终与服务器时间同步。

2、OS测试环境介绍

Server端:RedHat8.2- 172.20.10.6

Client端:CentOS8.3- 172.20.10.7

本次测试为最小化系统安装,配置本地yum源后安装chrony服务(服务端客户端均安装该服务,如下)

  1. [root@centos8-3 ~]# yum install -y chrony
  2. Last metadata expiration check: 0:00:05 ago on Tue 15 Jun 2021 08:02:45 PM CST.
  3. Dependencies resolved.
  4. =================================================================================================================================================================
  5. Package Architecture Version Repository Size
  6. =================================================================================================================================================================
  7. Installing:
  8. chrony x86_64 3.5-1.el8 centos8-OS 271 k
  9. Installing weak dependencies:
  10. timedatex x86_64 0.5-3.el8 centos8-OS 32 k
  11. Transaction Summary
  12. =================================================================================================================================================================
  13. Install 2 Packages
  14. Total size: 303 k
  15. Installed size: 731 k
  16. Downloading Packages:
  17. Running transaction check
  18. Transaction check succeeded.
  19. Running transaction test
  20. Transaction test succeeded.
  21. Running transaction
  22. Preparing : 1/1
  23. Installing : timedatex-0.5-3.el8.x86_64 1/2
  24. Running scriptlet: timedatex-0.5-3.el8.x86_64 1/2
  25. Running scriptlet: chrony-3.5-1.el8.x86_64 2/2
  26. Installing : chrony-3.5-1.el8.x86_64 2/2
  27. Running scriptlet: chrony-3.5-1.el8.x86_64 2/2
  28. Verifying : chrony-3.5-1.el8.x86_64 1/2
  29. Verifying : timedatex-0.5-3.el8.x86_64 2/2
  30. Installed:
  31. chrony-3.5-1.el8.x86_64 timedatex-0.5-3.el8.x86_64
  32. Complete!

3、server与client端配置

(1)server端配置以及解释说明

  1. [root@RedHat8-2 ~]# cat /etc/chrony.conf
  2. # Use public servers from the pool.ntp.org project.
  3. # Please consider joining the pool (http://www.pool.ntp.org/join.html).
  4. #pool 2.rhel.pool.ntp.org iburst --注释这行,外网时间服务器的网址
  5. server 172.20.10.6 iburst --添加这行,表示与本机同步时间(视情况自行更改)
  6. # Record the rate at which the system clock gains/losses time.
  7. driftfile /var/lib/chrony/drift
  8. # Allow the system clock to be stepped in the first three updates
  9. # if its offset is larger than 1 second.
  10. makestep 1.0 3
  11. # Enable kernel synchronization of the real-time clock (RTC).
  12. rtcsync
  13. # Enable hardware timestamping on all interfaces that support it.
  14. #hwtimestamp *
  15. # Increase the minimum number of selectable sources required to adjust
  16. # the system clock.
  17. #minsources 2
  18. # Allow NTP client access from local network.
  19. allow 172.20.10.0/28 -->>允许哪些服务器或客户端到这台时间服务器来同步时间。必须配置
  20. # Serve time even if not synchronized to a time source.
  21. local stratum 10 -->>该行注释取消掉不然NTP synchronized: 为no 取消掉后变为 NTP synchronized:yes
  22. # Specify file containing keys for NTP authentication.
  23. keyfile /etc/chrony.keys
  24. # Get TAI-UTC offset and leap seconds from the system tz database.
  25. leapsectz right/UTC
  26. # Specify directory for log files.
  27. logdir /var/log/chrony
  28. # Select which information is logged.
  29. #log measurements statistics tracking

启动chrony服务并进行检查

  1. 启动chronyd
  2. [root@RedHat8-2 ~]# systemctl start chronyd
  3. 加入开机自启
  4. [root@RedHat8-2 ~]# systemctl enable chronyd
  5. 检查
  6. [root@RedHat8-2 ~]# netstat -antulp|grep chronyd
  7. udp 0 0 0.0.0.0:123 0.0.0.0:* 7745/chronyd
  8. udp 0 0 127.0.0.1:323 0.0.0.0:* 7745/chronyd
  9. udp6 0 0 ::1:323 :::* 7745/chronyd
  10. [root@RedHat8-2 ~]# ss -antulp|grep chronyd
  11. udp UNCONN 0 0 0.0.0.0:123 0.0.0.0:* users:(("chronyd",pid=7745,fd=9))
  12. udp UNCONN 0 0 127.0.0.1:323 0.0.0.0:* users:(("chronyd",pid=7745,fd=7))
  13. udp UNCONN 0 0 [::1]:323 [::]:* users:(("chronyd",pid=7745,fd=8))

(2)client端配置

  1. [root@centos8-3 ~]# cat /etc/chrony.conf
  2. # Use public servers from the pool.ntp.org project.
  3. # Please consider joining the pool (http://www.pool.ntp.org/join.html).
  4. #pool 2.centos.pool.ntp.org iburst
  5. server 172.20.10.6 iburst -->>添加该行,表示到这台服务器去同步时间

启动chronyd并加入开机自启

  1. [root@centos8-3 ~]# systemctl start chronyd
  2. [root@centos8-3 ~]# systemctl enable chronyd

4、查看状态

  1. [root@centos8-3 ~]# timedatectl
  2. Local time: Tue 2021-06-15 16:45:10 CST
  3. Universal time: Tue 2021-06-15 08:45:10 UTC
  4. RTC time: Tue 2021-06-15 16:45:10
  5. Time zone: Asia/Shanghai (CST, +0800)
  6. System clock synchronized: yes --表示已同步完成
  7. NTP service: active
  8. RTC in local TZ: no

5、查看时间源信息

服务端

  1. [root@RedHat8-2 ~]# chronyc sources -v
  2. 210 Number of sources = 1
  3. .-- Source mode '^' = server, '=' = peer, '#' = local clock.
  4. / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
  5. | / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
  6. || .- xxxx [ yyyy ] +/- zzzz
  7. || Reachability register (octal) -. | xxxx = adjusted offset,
  8. || Log2(Polling interval) --. | | yyyy = measured offset,
  9. || \ | | zzzz = estimated error.
  10. || | | \
  11. MS Name/IP address Stratum Poll Reach LastRx Last sample
  12. ===============================================================================
  13. ^? RedHat8-2.localdomain 0 7 377 - +0ns[ +0ns] +/- 0ns

客户端

  1. [root@centos8-3 ~]# chronyc sources -v
  2. 210 Number of sources = 1
  3. .-- Source mode '^' = server, '=' = peer, '#' = local clock.
  4. / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
  5. | / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
  6. || .- xxxx [ yyyy ] +/- zzzz
  7. || Reachability register (octal) -. | xxxx = adjusted offset,
  8. || Log2(Polling interval) --. | | yyyy = measured offset,
  9. || \ | | zzzz = estimated error.
  10. || | | \
  11. MS Name/IP address Stratum Poll Reach LastRx Last sample
  12. ===============================================================================
  13. ^* 172.20.10.6 11 6 177 50 +2087ns[ -33us] +/- 227ms

6、测试

测试说明,对服务端进行手动更改时间,查看客户端是否同步

(1)查看客户端与服务端当前时间

  1. 服务端
  2. [root@RedHat8-2 ~]# date
  3. Tue Jun 15 16:43:22 CST 2021
  4. 客户端
  5. [root@centos8-3 ~]# date
  6. Tue Jun 15 16:43:22 CST 2021

(2)手动更改服务端时间

  1. [root@RedHat8-2 ~]# date
  2. Tue Jun 15 17:14:03 CST 2021
  3. [root@RedHat8-2 ~]# date -s "2021-6-15 18:00:00"
  4. Tue Jun 15 18:00:00 CST 2021

(3)等待客户端自动同步(测试同步时间较为缓慢)

  1. [root@centos8-3 ~]# chronyc sources -v
  2. 210 Number of sources = 1
  3. .-- Source mode '^' = server, '=' = peer, '#' = local clock.
  4. / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
  5. | / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
  6. || .- xxxx [ yyyy ] +/- zzzz
  7. || Reachability register (octal) -. | xxxx = adjusted offset,
  8. || Log2(Polling interval) --. | | yyyy = measured offset,
  9. || \ | | zzzz = estimated error.
  10. || | | \
  11. MS Name/IP address Stratum Poll Reach LastRx Last sample
  12. ===============================================================================
  13. ^~ 172.20.10.6 11 6 37 11 -2716s[ -2716s] +/- 265ms
  14. [root@centos8-3 ~]# date
  15. Tue Jun 15 17:16:44 CST 2021
  16. [root@centos8-3 ~]# timedatectl
  17. Local time: Tue 2021-06-15 17:16:53 CST
  18. Universal time: Tue 2021-06-15 09:16:53 UTC
  19. RTC time: Tue 2021-06-15 09:17:19
  20. Time zone: Asia/Shanghai (CST, +0800)
  21. System clock synchronized: yes
  22. NTP service: active
  23. RTC in local TZ: no
  24. [root@centos8-3 ~]# date
  25. Tue Jun 15 18:06:49 CST 2021

在测试中发现个问题 同步时间较为缓慢不过成功的进行了同步

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/845097
推荐阅读
相关标签
  

闽ICP备14008679号