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

记录自己使用中遇到的坑

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

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

一,服务端配置

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

bash 复制代码
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.没有打开本地时钟源,默认生成的配置文件是没有这一个选项的

bash 复制代码
# Serve time even if not synchronized to a time source.
local stratum 10

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

bash 复制代码
# 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地址范围

bash 复制代码
allow 192.168.2.0/24

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

二,客户端配置

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

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

bash 复制代码
# 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地址即可正常使用

bash 复制代码
server 192.168.2.11 iburst

附上几个常用的命令:

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

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

bash 复制代码
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
相关推荐
银氨溶液1 小时前
DNS解析域名详解
linux·服务器·apache·域名解析
阿瑾06181 小时前
【Linux】进程间通信——System V共享内存
linux·运维·服务器
leSerein_1 小时前
【Docker】docker的一些常用命令
linux·运维·docker·容器
不会代码的小徐1 小时前
Shell脚本监控Centos 7系统运行状态
linux·运维·centos
十一吖i1 小时前
uniapp实现下拉刷新
linux·服务器·uni-app
SofterICer2 小时前
Test-Specification-v2_3_1-1
linux·运维·服务器
baidu_375528812 小时前
ubuntu20.04/22.04/24.04 docker 容器安装方法
linux·c语言·c++·嵌入式硬件
顶点元2 小时前
Linux TCP服务器和客户端学习
linux·tcp/ip
Flying_Fish_roe2 小时前
linux-用户与权限管理-文件权限
linux·运维·服务器
Betty’s Sweet2 小时前
[Linux]:动静态库
linux·动态库·静态库