当前位置: 首页 > ai >正文

在Ubuntu下用Chrony做主从机时间同步

主机

下载chrony

sudo apt install chrony

 修改配置文件:
 

sudo gedit /etc/chrony/chrony.conf
# 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.server 192.168.1.1  minpoll 4 maxpoll 10 iburst #将本地作为服务器allow all # 这里允许所有网段的客户端计算机发送的请求local stratum 10 #无法同步时,将本地的时间返回给客户端# This directive specify the location of the file containing ID/key pairs for
# NTP authentication.
keyfile /etc/chrony/chrony.keys# 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

这里直接将主机的时间返回给从机,好处是主机和从机的时间同步效果更好,但是没有和外部时间同步服务器进行同步。如果需要和外部服务器同步的话,将server 192.168.1.1  minpoll 4 maxpoll 10 iburst删掉,并添加以下内容:

server ntp.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp1.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp1.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp10.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp11.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp12.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp2.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp2.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp3.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp3.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp4.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp4.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp5.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp5.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp6.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp6.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp7.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp8.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp9.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst

修改完配置文件后,重启chrony服务

sudo service chrony restart

从机

配置文件:
 

# 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.
server 192.168.31.20 minpoll 4 maxpoll 10 iburst # 这里192.168.31.20是主机的ip,要确保能ping通# 这里记得注释,否则从机会从外部服务器拿时间
#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# 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 #时间偏差超过 1 秒,Chrony 将立即调整时间,最多连续调整 3 次

验证

从机输入:

chronyc tracking

System time          表示的是与主机之间的时间差

Last offset             表示的是上一次时间调整的偏移量

Root delay             从根时间源到本地系统的延迟时间

Root dispersion    从根时间源到本地系统的最大时间偏差

Update interval      Chrony 每隔多少秒会更新一次时间

^*表示正在用的服务器

LastRx是最后一次测量的偏移量  (+20us)

Last是上一次测量的偏移量 (+30us)
sample表示 Chrony 对时间源的测量精度范围。反映了 Chrony 在同步时间时的不确定性。

http://www.xdnf.cn/news/775.html

相关文章:

  • 栈和字符串,力扣.43.字符串相乘力扣1047.删除字符串中的所有相邻重复项力扣.844比较含退格的字符串力扣227.基本计算器II
  • 《马尼拉》桌游期望计算器
  • Ubuntu下展锐刷机工具spd_dump使用说明
  • Python3网络爬虫开发--爬虫基础
  • Java 设计模式心法之第4篇 - 单例 (Singleton) 的正确打开方式与避坑指南
  • 每天学一个 Linux 命令(30):cut
  • 【React】搜索时高亮被搜索选中的文案
  • 大数据系列 | 详解基于Zookeeper或ClickHouse Keeper的ClickHouse集群部署--完结
  • TensorFlow和PyTorch学习原理解析
  • 掌握常见 HTTP 方法:GET、POST、PUT 到 CONNECT 全面梳理
  • FreeRTos学习记录--2.内存管理
  • 华为云获取IAM用户Token的方式及适用分析
  • 潞晨科技将暂停DeepSeek API服务,AI大模型技术红利普惠化与市场竞争白热化叠加,内卷恶果,开始显现!
  • 在线查看【免费】 dcm、drawio,dcm wps文件格式网站
  • Spring Boot集成Keycloak
  • 颠覆传统!毫秒级响应的跨平台文件同步革命,远程访问如本地操作般丝滑
  • 从“堆料竞赛”到“体验深耕”,X200 Ultra和X200s打响手机价值升维战
  • 【锂电池容量特征提取】NASA数据集锂电池容量特征提取(Matlab完整源码)
  • Java中 关于编译(Compilation)、类加载(Class Loading) 和 运行(Execution)的详细区别解析
  • Linux网络编程 多进程UDP聊天室:共享内存与多进程间通信实战解析
  • 四元数转旋转矩阵
  • 极狐GitLab CEO 柳钢受邀出席 2025 全球机器学习技术大会
  • Halcon应用:相机标定之应用
  • Shell脚本-变量的分类
  • 使用c++调用deepseek的api(附带源码)
  • 深度解析算法之位运算
  • 突破传统!SEARCH-R1如何让LLM与搜索引擎协同推理?
  • 使用SystemWeaver生成SOME/IP ETS ARXML的完整实战指南
  • FastGPT Docker Compose本地部署与硅基流动免费AI接口集成指南
  • Kubernetes相关的名词解释Metrics Server组件(7)