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
相关推荐
A小辣椒4 小时前
TShark:基础知识
linux
AlfredZhao6 小时前
OCI 明明分配了 200G 系统盘,为什么 df 只看到 30G?
linux·oci
AlfredZhao21 小时前
vi 删除指定范围的行,不用再反复按 dd
linux·vi
用户9718356334661 天前
银河麒麟 KY10 申威(SW64) 安装 nginx-1.16.1-2.p01.ky10.sw_64.rpm 详细步骤
linux
猪脚踏浪1 天前
linux 拷贝文件或目录到指定的位置
linux
摇滚侠2 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
bush42 天前
嵌入式linux学习记录十四、术语
linux·嵌入式
载数而行5202 天前
Linux 11 动态监控指令top
linux
不会C语言的男孩2 天前
Linux 系统编程 · 第 8 章:进程基础
linux·c语言
古城小栈2 天前
Unix 与 Linux 异同小叙
linux·服务器·unix