当前位置:   article > 正文

openEuler 22.03 (LTS-SP1)服务器用ntpd同步GPS时间服务器的案例_openeuler ntp

openeuler ntp

本文记录了openEuler 22.03 (LTS-SP1)的二级时间服务器用chronyd不能自动同步GPS时间服务器,改用ntpd同步GPS时间服务器成功的案例

一、环境简述

1、本环境中有两台GPS一级时间服务器,IP如下:

192.168.188.66

192.168.188.74

2、有一台openeuler系统的服务器拟作为网络中的二级时间服务器对全网进行授时

系统版本:

  1. [root@localhost ~]# cat /etc/os-release
  2. NAME="openEuler"
  3. VERSION="22.03 (LTS-SP1)"
  4. ID="openEuler"
  5. VERSION_ID="22.03"
  6. PRETTY_NAME="openEuler 22.03 (LTS-SP1)"
  7. ANSI_COLOR="0;31"

 IP地址:192.168.168.33

二、问题现象

1、使用chronyd进行时间服务器同步设置

配置如下:

  1. [root@localhost ~]# egrep -v "^#|^$" /etc/chrony.conf
  2. server 192.168.188.66 iburst
  3. server 192.168.188.74 iburst
  4. driftfile /var/lib/chrony/drift
  5. makestep 1.0 3
  6. rtcsync
  7. allow 192.0.0.0/8
  8. local stratum 10
  9. keyfile /etc/chrony.keys
  10. logdir /var/log/chrony
  11. log measurements statistics tracking
2、启动服务
  1. [root@localhost ~]# systemctl start chronyd
  2. [root@localhost ~]# systemctl status chronyd
  3. ● chronyd.service - NTP client/server
  4. Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
  5. Active: active (running) since Fri 2024-06-21 20:37:38 CST; 5s ago
  6. Docs: man:chronyd(8)
  7. man:chrony.conf(5)
  8. Process: 392366 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)
  9. Main PID: 392368 (chronyd)
  10. Tasks: 1 (limit: 2469658)
  11. Memory: 360.0K
  12. CGroup: /system.slice/chronyd.service
  13. └─ 392368 /usr/sbin/chronyd
  14. Jun 21 20:37:38 irmsogg1733 systemd[1]: Starting NTP client/server...
  15. Jun 21 20:37:38 irmsogg1733 chronyd[392368]: chronyd version 4.1 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASY>
  16. Jun 21 20:37:38 irmsogg1733 chronyd[392368]: Initial frequency -46.668 ppm
  17. Jun 21 20:37:38 irmsogg1733 systemd[1]: Started NTP client/server.

服务正常启动

3、检查服务器同步情况
  1. [root@localhost ~]# chronyc sourcestats -v
  2. .- Number of sample points in measurement set.
  3. / .- Number of residual runs with same sign.
  4. | / .- Length of measurement set (time).
  5. | | / .- Est. clock freq error (ppm).
  6. | | | / .- Est. error in freq.
  7. | | | | / .- Est. offset.
  8. | | | | | | On the -.
  9. | | | | | | samples. \
  10. | | | | | | |
  11. Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev
  12. ==============================================================================
  13. 192.168.188.66 0 0 0 +0.000 2000.000 +0ns 4000ms
  14. 192.168.188.74 0 0 0 +0.000 2000.000 +0ns 4000ms
  15. [root@localhost ~]# chronyc sources -v
  16. .-- Source mode '^' = server, '=' = peer, '#' = local clock.
  17. / .- Source state '*' = current best, '+' = combined, '-' = not combined,
  18. | / 'x' = may be in error, '~' = too variable, '?' = unusable.
  19. || .- xxxx [ yyyy ] +/- zzzz
  20. || Reachability register (octal) -. | xxxx = adjusted offset,
  21. || Log2(Polling interval) --. | | yyyy = measured offset,
  22. || \ | | zzzz = estimated error.
  23. || | | \
  24. MS Name/IP address Stratum Poll Reach LastRx Last sample
  25. ===============================================================================
  26. ^? 192.168.188.66 0 8 0 - +0ns[ +0ns] +/- 0ns
  27. ^? 192.168.188.74 0 8 0 - +0ns[ +0ns] +/- 0ns

经长时间观察,服务器前面始终为?,发现无法完成自动同步将服务器状态转为“*”或“-”。

4、检查一级服务器授时能力
  1. [root@localhost ~]# chronyc activity -v
  2. 200 OK
  3. 2 sources online
  4. 0 sources offline
  5. 0 sources doing burst (return to online)
  6. 0 sources doing burst (return to offline)
  7. 0 sources with unknown address
  8. [root@localhost ~]# chronyc tracking -v
  9. Reference ID : 7F7F0101 ()
  10. Stratum : 10
  11. Ref time (UTC) : Fri Jun 21 11:31:11 2024
  12. System time : 0.000000004 seconds slow of NTP time
  13. Last offset : +0.000000000 seconds
  14. RMS offset : 0.000000000 seconds
  15. Frequency : 44.979 ppm slow
  16. Residual freq : +0.000 ppm
  17. Skew : 0.000 ppm
  18. Root delay : 0.000000000 seconds
  19. Root dispersion : 0.000000000 seconds
  20. Update interval : 0.0 seconds
  21. Leap status : Normal

 可以看到两个时间服务器源是在线的,但tracking信息不正常

5、手动同步时间测试
  1. [root@localhost ~]# ntpdate 192.168.188.66
  2. 21 Jun 19:19:21 ntpdate[391367]: adjust time server 192.168.188.66 offset +0.017640 sec
  3. [root@localhost ~]# ntpdate 192.168.188.74
  4. 21 Jun 19:19:34 ntpdate[391368]: adjust time server 192.168.188.74 offset +0.012333 sec
  5. [root@localhost ~]# chronyc -a makestep
  6. 200 OK

 手动测试一级时间服务器时间同步正常,授时端口也正常,看来chronyd与该GPS时间服务器同步存在什么问题。

三、问题处理

1、卸载chronyd

考虑到一级GPS时间服务器能正常授时,chronyd又无法完成与一级GPS时间服务器的自动同步,于是卸载chronyd,改用ntpd进行尝试(ntpd和chronyd都能启动ntp时间服务器,同时运行是有冲突的,最好只保留一个)。

  1. [root@localhost ~]# yum remove chrony
  2. Dependencies resolved.
  3. =======================================================================================================================================
  4. Package Architecture Version Repository Size
  5. =======================================================================================================================================
  6. Removing:
  7. chrony x86_64 4.1-3.oe2203sp1 @openEuler2203SP1LTS 435 k
  8. Removing unused dependencies:
  9. libedit x86_64 3.1-29.oe2203sp1 @openEuler2203SP1LTS 232 k
  10. timedatex x86_64 0.6-3.oe2203sp1 @openEuler2203SP1LTS 52 k
  11. Transaction Summary
  12. =======================================================================================================================================
  13. Remove 3 Packages
  14. Freed space: 718 k
  15. Is this ok [y/N]: y
  16. Running transaction check
  17. Transaction check succeeded.
  18. Running transaction test
  19. Transaction test succeeded.
  20. Running transaction
  21. Preparing : 1/1
  22. Running scriptlet: chrony-4.1-3.oe2203sp1.x86_64 1/1
  23. Running scriptlet: chrony-4.1-3.oe2203sp1.x86_64 1/3
  24. Removed /etc/systemd/system/multi-user.target.wants/chronyd.service.
  25. Erasing : chrony-4.1-3.oe2203sp1.x86_64 1/3
  26. warning: /etc/chrony.conf saved as /etc/chrony.conf.rpmsave
  27. Running scriptlet: chrony-4.1-3.oe2203sp1.x86_64 1/3
  28. Erasing : libedit-3.1-29.oe2203sp1.x86_64 2/3
  29. Running scriptlet: timedatex-0.6-3.oe2203sp1.x86_64 3/3
  30. Unit /etc/systemd/system/timedatex.service is masked, ignoring.
  31. Erasing : timedatex-0.6-3.oe2203sp1.x86_64 3/3
  32. Running scriptlet: timedatex-0.6-3.oe2203sp1.x86_64 3/3
  33. Verifying : chrony-4.1-3.oe2203sp1.x86_64 1/3
  34. Verifying : libedit-3.1-29.oe2203sp1.x86_64 2/3
  35. Verifying : timedatex-0.6-3.oe2203sp1.x86_64 3/3
  36. Removed:
  37. chrony-4.1-3.oe2203sp1.x86_64 libedit-3.1-29.oe2203sp1.x86_64 timedatex-0.6-3.oe2203sp1.x86_64
  38. Complete!
2、安装ntpd
  1. [root@localhost ~] # yum install ntp
  2. Last metadata expiration check: 0:51:16 ago on Fri 21 Jun 2024 07:47:25 PM CST.
  3. Dependencies resolved.
  4. =======================================================================================================================================
  5. Package Architecture Version Repository Size
  6. =======================================================================================================================================
  7. Installing:
  8. ntp x86_64 4.2.8p15-7.oe2203sp1 openEuler2203SP1LTS 619 k
  9. Installing dependencies:
  10. autogen x86_64 5.18.16-3.oe2203sp1 openEuler2203SP1LTS 469 k
  11. libedit x86_64 3.1-29.oe2203sp1 openEuler2203SP1LTS 92 k
  12. ntp-help noarch 4.2.8p15-7.oe2203sp1 openEuler2203SP1LTS 1.3 M
  13. Installing weak dependencies:
  14. ntpstat noarch 0.6-4.oe2203sp1 openEuler2203SP1LTS 11 k
  15. timedatex x86_64 0.6-3.oe2203sp1 openEuler2203SP1LTS 29 k
  16. Transaction Summary
  17. =======================================================================================================================================
  18. Install 6 Packages
  19. Total download size: 2.4 M
  20. Installed size: 5.3 M
  21. Is this ok [y/N]: y
  22. Downloading Packages:
  23. (1/6): libedit-3.1-29.oe2203sp1.x86_64.rpm 19 MB/s | 92 kB 00:00
  24. (2/6): autogen-5.18.16-3.oe2203sp1.x86_64.rpm 29 MB/s | 469 kB 00:00
  25. (3/6): ntpstat-0.6-4.oe2203sp1.noarch.rpm 9.3 MB/s | 11 kB 00:00
  26. (4/6): ntp-4.2.8p15-7.oe2203sp1.x86_64.rpm 24 MB/s | 619 kB 00:00
  27. (5/6): timedatex-0.6-3.oe2203sp1.x86_64.rpm 3.7 MB/s | 29 kB 00:00
  28. (6/6): ntp-help-4.2.8p15-7.oe2203sp1.noarch.rpm 42 MB/s | 1.3 MB 00:00
  29. ---------------------------------------------------------------------------------------------------------------------------------------
  30. Total 63 MB/s | 2.4 MB 00:00
  31. Running transaction check
  32. Transaction check succeeded.
  33. Running transaction test
  34. Transaction test succeeded.
  35. Running transaction
  36. Preparing : 1/1
  37. Running scriptlet: timedatex-0.6-3.oe2203sp1.x86_64 1/6
  38. Installing : timedatex-0.6-3.oe2203sp1.x86_64 1/6
  39. Running scriptlet: timedatex-0.6-3.oe2203sp1.x86_64 1/6
  40. Unit /etc/systemd/system/timedatex.service is masked, ignoring.
  41. Installing : ntp-help-4.2.8p15-7.oe2203sp1.noarch 2/6
  42. Installing : libedit-3.1-29.oe2203sp1.x86_64 3/6
  43. Installing : autogen-5.18.16-3.oe2203sp1.x86_64 4/6
  44. Installing : ntpstat-0.6-4.oe2203sp1.noarch 5/6
  45. Running scriptlet: ntp-4.2.8p15-7.oe2203sp1.x86_64 6/6
  46. Installing : ntp-4.2.8p15-7.oe2203sp1.x86_64 6/6
  47. Running scriptlet: ntp-4.2.8p15-7.oe2203sp1.x86_64 6/6
  48. Verifying : autogen-5.18.16-3.oe2203sp1.x86_64 1/6
  49. Verifying : libedit-3.1-29.oe2203sp1.x86_64 2/6
  50. Verifying : ntp-4.2.8p15-7.oe2203sp1.x86_64 3/6
  51. Verifying : ntp-help-4.2.8p15-7.oe2203sp1.noarch 4/6
  52. Verifying : ntpstat-0.6-4.oe2203sp1.noarch 5/6
  53. Verifying : timedatex-0.6-3.oe2203sp1.x86_64 6/6
  54. Installed:
  55. autogen-5.18.16-3.oe2203sp1.x86_64 libedit-3.1-29.oe2203sp1.x86_64 ntp-4.2.8p15-7.oe2203sp1.x86_64
  56. ntp-help-4.2.8p15-7.oe2203sp1.noarch ntpstat-0.6-4.oe2203sp1.noarch timedatex-0.6-3.oe2203sp1.x86_64
  57. Complete!
3、配置ntpd
  1. [root@localhost chrony]# egrep -v "^#|^$" /etc/ntp.conf
  2. driftfile /var/lib/ntp/drift
  3. restrict default nomodify notrap nopeer noepeer noquery
  4. restrict source nomodify notrap noepeer noquery
  5. restrict 127.0.0.1
  6. restrict ::1
  7. server 192.168.188.66 iburst
  8. server 192.168.188.74 iburst
  9. tos maxclock 5
  10. includefile /etc/ntp/crypto/pw
  11. keys /etc/ntp/keys
 4、启动ntpd
[root@localhost chrony]# systemctl start ntpd
5、查看服务状态
  1. [root@localhost chrony]# systemctl status ntpd
  2. ● ntpd.service - Network Time Service
  3. Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
  4. Active: active (running) since Fri 2024-06-21 20:40:16 CST; 2min 38s ago
  5. Main PID: 392489 (ntpd)
  6. Tasks: 2 (limit: 2469658)
  7. Memory: 1.6M
  8. CGroup: /system.slice/ntpd.service
  9. └─ 392489 /usr/sbin/ntpd -u ntp:ntp -g
  10. Jun 21 20:40:16 localhost ntpd[392489]: Listen and drop on 1 v4wildcard 0.0.0.0:123
  11. Jun 21 20:40:16 localhost ntpd[392489]: Listen normally on 2 lo 127.0.0.1:123
  12. Jun 21 20:40:16 localhost ntpd[392489]: Listen normally on 3 bond0 192.168.168.33:123
  13. Jun 21 20:40:16 localhost ntpd[392489]: Listen normally on 4 lo [::1]:123
  14. Jun 21 20:40:16 localhost ntpd[392489]: Listening on routing socket on fd #23 for interface updates
  15. Jun 21 20:40:16 localhost ntpd[392489]: kernel reports TIME_ERROR: 0x41: Clock Unsynchronized
  16. Jun 21 20:40:16 localhost ntpd[392489]: kernel reports TIME_ERROR: 0x41: Clock Unsynchronized
  17. Jun 21 20:40:16 localhost systemd[1]: Started Network Time Service.
 6、检查时间同步情况
  1. [root@localhost chrony]# ntpq -p
  2. remote refid st t when poll reach delay offset jitter
  3. ==============================================================================
  4. +192.168.188.66 .GPS. 1 u 11 64 77 1.705 +15.730 12.199
  5. *192.168.188.74 .GPS. 1 u 8 64 77 1.670 +16.038 12.284

 发现ntpd能够正常跟踪一级GPS时间服务器,相关数据显示正常。

7、使能ntpd让其开机启动
  1. [root@localhost chrony]# systemctl enable ntpd
  2. Created symlink /etc/systemd/system/multi-user.target.wants/ntpd.service → /usr/lib/systemd/system/ntpd.service.
8、通过网内其它主机进行时间同步测试

其它主机chronyd将时间服务器设置为二级服务器192.168.168.33进行同步测试

  1. [root@localhost2 ~]# chronyc sources -v
  2. .-- Source mode '^' = server, '=' = peer, '#' = local clock.
  3. / .- Source state '*' = current best, '+' = combined, '-' = not combined,
  4. | / 'x' = may be in error, '~' = too variable, '?' = unusable.
  5. || .- xxxx [ yyyy ] +/- zzzz
  6. || Reachability register (octal) -. | xxxx = adjusted offset,
  7. || Log2(Polling interval) --. | | yyyy = measured offset,
  8. || \ | | zzzz = estimated error.
  9. || | | \
  10. MS Name/IP address Stratum Poll Reach LastRx Last sample
  11. ===============================================================================
  12. ^* 192.168.168.33 2 6 377 17 -4658us[-7129us] +/- 11ms

可以看到,能正确获取到时间,且显示二级服务器192.168.168.33处于第二层。

9、检查时间获取情况
  1. [root@localhost2 ~]# chronyc tracking -v
  2. Reference ID : 0AE31121 (192.168.168.33)
  3. Stratum : 3
  4. Ref time (UTC) : Fri Jun 21 14:13:29 2024
  5. System time : 0.000004623 seconds fast of NTP time
  6. Last offset : +0.000003086 seconds
  7. RMS offset : 0.000103144 seconds
  8. Frequency : 16.338 ppm slow
  9. Residual freq : +0.001 ppm
  10. Skew : 0.072 ppm
  11. Root delay : 0.001930163 seconds
  12. Root dispersion : 0.007009792 seconds
  13. Update interval : 64.7 seconds
  14. Leap status : Normal
10、用时间同步检查工具检查

可以看到 二级服务器192.168.168.33是从一级时间服务器192.168.188.74获取的时间,与“ntpq -p”检查结果一致,确认二级时间服务器自动同步GPS时间服务器并进行分发的配置ok,运行完成正常。

四、问题分析

网络中的GPS一级时间服务器启用时间较早,估计使用了较早的时间协议。chronyd对比ntpd能更快地且更准确地同步系统时钟,但ntp更多的NTP运行协议,它支持RFC 5905的所有操作模式,包括广播、多播和manycast服务器/客户端,它还支持自动密钥协议(RFC 5906)来使用公钥加密对服务器进行身份验证,因此本例可能就是因为chronyd不能完全支持GPS一级时间服务器的NTP协议,而使用ntpd则能较好地运行。

附:本文中相关配置详解见《ntpd和chronyd时间服务器配置样例及详解》

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

闽ICP备14008679号