chronyd

chronyd

https://chrony-project.org/doc/4.1/chrony.conf.html

无时钟源配置可参考 : Isolated networks

通过互联网同步的两台机器之间的典型精度在几毫秒内;

在 LAN 上,精度通常为数十微秒。

使用硬件时间戳或硬件参考时钟,亚微秒精度是可能的。

How do I make an NTP server?

By default, chronyd does not operate as an NTP server. You need to add an allow directive to the chrony.conf file in order for chronyd to open the server NTP port and respond to client requests.

allow 192.168.1.0/24

An allow directive with no specified subnet allows access from all IPv4 and IPv6 addresses.

Is chronyd allowed to step the system clock?

By default, chronyd adjusts the clock gradually by slowing it do

By default, chronyd adjusts the clock gradually by slowing it down or speeding it up. If the clock is too far from the true time, it will take a long time to correct the error. The System time value printed by the chronyc’s tracking command is the remaining correction that needs to be applied to the system clock.

makestep 1 3

the clock would be stepped in the first three updates if its offset was larger than one second. Normally, it is recommended to allow the step only in the first few updates, but in some cases (e.g. a computer without an RTC or virtual machine which can be suspended and resumed with an incorrect time) it might be necessary to allow the step on any clock update. The example above would change to

makestep 1 -1
# 精确显示时间
date '+%Y-%m-%d %H:%M:%S.%3N'
# 将系统时间调整为当前时间加上 3 秒
sudo date -s @$(($(date +%s) + 3))
# 查看服务器时间和NTP server偏差 
chronyc tracking
# 查看时间同步源,使用可选参数 -v 来包括详细信息
chronyc sources
chronyc sources -v
# 显示有多少NTP源在线/离线
chronyc activity
# 立即手动同步时间(需要chronyd服务运行)
chronyc makestep

chronyc clients

# 像 ntpdate 一样手动同步时间 使用参数 -q (运行服务执行后停止服务)
chronyd -q 'pool time.windows.com iburst'
# 临时添加一台时间同步服务地址(不会写入配置中),chronyc sources
chronyc add server time.windows.com
# 最后一步,将当前时间和日期写入BIOS,避免重启后失效
hwclock -w
# 显示 BIOS 中实际的时间
hwclock --localtime

timedatectl set-ntp yes

# 默认情况下,系统配置为使用UTC,也可使用本地时间
timedatectl set-local-rtc true   # 将RTC设置为本地时间
timedatectl set-local-rtc false  # 将RTC设置为UTC

你可能感兴趣的:(单片机,stm32,嵌入式硬件)