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
相关推荐
wangjialelele6 分钟前
一文读懂 Redis 持久化与事务
linux·数据库·redis·bootstrap
Linux蓝魔10 分钟前
麒麟官方yum源配置V10SP2-V10SP3-V10SP3-2403
大数据·linux·运维
helloliyh11 分钟前
linux 删除指定日期目录(包括目录下文件)
linux·运维·服务器
半个俗人22 分钟前
06.Linux用户权限相关命令
linux·运维·服务器
小宇的天下23 分钟前
Calibre LVS Circuit Comparison(1)
linux·数据库·lvs
涛声依旧3931624 分钟前
构建部署kubernetes所需主机
linux·运维·云原生·容器·kubernetes
淼淼爱喝水35 分钟前
OpenEuler 系统下 Ansible 环境部署与连通性测试完整步骤
linux·开发语言·php·openeuler
KuYouRan38 分钟前
ubuntu22.04用RTX2060显卡玩steam游戏
linux·其他·ubuntu·游戏
叠叠乐1 小时前
linux.service 自起文件want和After意思
linux
Ricky_Theseus1 小时前
SPOOLING 系统详解
linux·服务器·数据库