arm开发板使用chrony与服务器进行时钟同步

记录自己使用中遇到的坑

参考这位大佬的文章基本基本可以调试通:时间同步 chrony 的服务端和客户端配置 - 简书

我之所以没有调通是因为以下几个点:

一,服务端配置

1.在服务器上,/etc/chrony/chrony.conf 文件中关闭了这几个时钟源

pool ntp.ubuntu.com        iburst maxsources 4
pool 0.ubuntu.pool.ntp.org iburst maxsources 1
pool 1.ubuntu.pool.ntp.org iburst maxsources 1
pool 2.ubuntu.pool.ntp.org iburst maxsources 2

 2.没有打开本地时钟源,默认生成的配置文件是没有这一个选项的

# Serve time even if not synchronized to a time source.
local stratum 10

 3.附上服务器完整的配置文件

# Welcome to the chrony configuration file. See chrony.conf(5) for more
# information about usuable directives.

# This will use (up to):
# - 4 sources from ntp.ubuntu.com which some are ipv6 enabled
# - 2 sources from 2.ubuntu.pool.ntp.org which is ipv6 enabled as well
# - 1 source from [01].ubuntu.pool.ntp.org each (ipv4 only atm)
# This means by default, up to 6 dual-stack and up to 2 additional IPv4-only
# sources will be used.
# At the same time it retains some protection against one of the entries being
# down (compare to just using one of the lines). See (LP: #1754358) for the
# discussion.
#
# About using servers from the NTP Pool Project in general see (LP: #104525).
# Approved by Ubuntu Technical Board on 2011-02-08.
# See http://www.pool.ntp.org/join.html for more information.
pool ntp.ubuntu.com        iburst maxsources 4
pool 0.ubuntu.pool.ntp.org iburst maxsources 1
pool 1.ubuntu.pool.ntp.org iburst maxsources 1
pool 2.ubuntu.pool.ntp.org iburst maxsources 2

# This directive specify the location of the file containing ID/key pairs for
# NTP authentication.
keyfile /etc/chrony/chrony.keys

allow 192.168.2.0/24

# Serve time even if not synchronized to a time source.
local stratum 10


# This directive specify the file into which chronyd will store the rate
# information.
driftfile /var/lib/chrony/chrony.drift
# Uncomment the following line to turn logging on.
#log tracking measurements statistics

# Log files location.
logdir /var/log/chrony

# Stop bad estimates upsetting machine clock.
maxupdateskew 100.0

# This directive enables kernel synchronisation (every 11 minutes) of the
# real-time clock. Note that it can’t be used along with the 'rtcfile' directive.
rtcsync

# Step the system clock instead of slewing it if the adjustment is larger than
# one second, but only in the first three clock updates.
makestep 1 3

 4.这是允许你客户端连接的ip地址范围

allow 192.168.2.0/24

 上面1和2随便打开一个客户端就可以获取到服务器的时间。

二,客户端配置

1.我自己的arm开发板添加了chrony包但是没有生成/etc/chrony.conf配置文件(服务器路径是/etc/chrony/.conf,客户端路径是/etc/chrony.conf,如果不知道它使用哪个路径,运行下chronyd命令看看报错就知道添加到哪个路径)

2.附上服务器完整的配置文件

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#pool ntp.aliyun.com iburst
server 192.168.2.11 iburst

# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift

# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3

# Enable kernel synchronization of the real-time clock (RTC).
rtcsync

# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *

# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2

# Allow NTP client access from local network.
#allow 192.168.2.0/16

# Serve time even if not synchronized to a time source.
#local stratum 10

# Specify file containing keys for NTP authentication.
# keyfile /etc/chrony.keys

# Get TAI-UTC offset and leap seconds from the system tz database.
leapsectz right/UTC

# Specify directory for log files.
logdir /var/log/chrony

# Select which information is logged.
#log measurements statistics tracking

这个配置文件只需要修改为自己的服务器的ip地址即可正常使用

server 192.168.2.11 iburst

附上几个常用的命令:

使用chronyc命令检查当前的时间同步状态和服务器信息:
chronyc sources
查看详细的NTP服务器状态
chronyc sourcestats -v
查看Chrony同步状态:
chronyc tracking

 当出现下面这个信息代表正常连接到服务器,使用date即可查看时间是否同步。

root@T113:/ # chronyc tracking
Reference ID    : C0A80290 (192.168.2.144)
Stratum         : 3
Ref time (UTC)  : Thu Aug 22 00:31:44 2024
System time     : 0.000000987 seconds fast of NTP time
Last offset     : -0.000003760 seconds
RMS offset      : 0.001231070 seconds
Frequency       : 27.770 ppm fast
Residual freq   : -0.002 ppm
Skew            : 0.520 ppm
Root delay      : 0.067885406 seconds
Root dispersion : 0.000886092 seconds
Update interval : 64.3 seconds
Leap status     : Normal

  • 6
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

在嵌入式里摸爬滚打

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值