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

基于chrony的NTP校时配置方法

基本原理描述

1.1 原理

在离线的局域网内,存在不少于2台服务器。

选择一台服务器作为时间基准,配置为NTP Server;

其他服务器向时间基准服务器同步,配置为NTP Client

1.2 描述

配置方法

2.1 NTP Server配置方法

1) 首先,确保操作系统防火墙关闭。

通过执行sudo systemctl status firewalld命令查看;

若未关闭,则执行

sudo systemctl stop firewalld

sudo systemctl disable firewalld

进行防火墙关闭。

2) 检查chronyd服务是否安装和激活

通过执行sudo systemctl status chronyd命令查看;

若未安装和激活,则执行以下命令

安装命令: sudo yum install chronyd

激活命令: sudo systemclt start chronyd

sudo systemctl enable chronyd

3) 更改配置文件,配置为server模式

编辑文件/etc/chrony.conf

内容如下:

 

# Use public servers from the pool.ntp.org project.# Please consider joining the pool (http://www.pool.ntp.org/join.html).#pool pool.ntp.org iburstserver ntp.ntsc.ac.cn iburstserver ntp1.aliyun.com iburst#server cn.pool.ntp.org 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.0.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

 

 

 

4) 重新运行服务,自动加载更新的配置文件

sudo systemctl restart chronyd

5) 激活服务

运行命令: chronyc activity

应有类似如下返回

200 OK

0 sources online

0 sources offline

0 sources doing burst (return to online)

0 sources doing burst (return to offline)

2 sources with unknown address

 

6) 查看同步源

执行命令 chronyc sources

因为离线,返回如下

210 Number of sources = 0

MS Name/IP address         Stratum Poll Reach LastRx Last sample               

 

7) 查看同步情况

执行命令 chronyc tracking

返回如下:

Reference ID    : 7F7F0101 ()

Stratum         : 10

Ref time (UTC)  : Sat Sep 13 03:05:36 2025

System time     : 0.000000000 seconds fast of NTP time

Last offset     : +0.000000000 seconds

RMS offset      : 0.000000000 seconds

Frequency       : 0.000 ppm slow

Residual freq   : +0.000 ppm

Skew            : 0.000 ppm

Root delay      : 0.000000000 seconds

Root dispersion : 0.000000000 seconds

Update interval : 0.0 seconds

Leap status     : Normal

 

 

2.2 NTP Client配置方法

1) 首先,确保操作系统防火墙关闭。

通过执行sudo systemctl status firewalld命令查看;

若未关闭,则执行

sudo systemctl stop firewalld

sudo systemctl disable firewalld

进行防火墙关闭。

2) 检查chronyd服务是否安装和激活

通过执行sudo systemctl status chronyd命令查看;

若为安装和激活,则执行以下命令

安装命令 sudo yum install chronyd

激活命令 sudo systemclt start chronyd

sudo systemctl enable chronyd

3) 更改配置文件,配置为server模式

编辑文件/etc/chrony.conf

内容如下:

 

# Use public servers from the pool.ntp.org project.# Please consider joining the pool (http://www.pool.ntp.org/join.html).#pool pool.ntp.org iburst# 注意以下是server的ip地址server 192.168.1.86 iburstserver ntp.ntsc.ac.cn iburstserver ntp1.aliyun.com iburst#server cn.pool.ntp.org 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.0.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

 

 

4) 重新运行服务,自动加载更新的配置文件

sudo systemctl restart chronyd

5) 激活服务

运行命令 chronyc activity

应有类似如下返回

200 OK

0 sources online

0 sources offline

0 sources doing burst (return to online)

0 sources doing burst (return to offline)

2 sources with unknown address

 

6) 查看同步源

执行命令 chronyc sources

返回如下,应该有serverip地址

210 Number of sources = 1

MS Name/IP address         Stratum Poll Reach LastRx Last sample               

===============================================================================

^* 192.168.1.86                 10   6    17     6  +4489ns[  +14us] +/-   35us

 

7) 查看同步情况

执行命令 chronyc tracking

返回如下:

Reference ID    : C0A80156 (192.168.1.86)

Stratum         : 11

Ref time (UTC)  : Sat Sep 13 03:10:51 2025

System time     : 0.000000002 seconds slow of NTP time

Last offset     : +0.000009667 seconds

RMS offset      : 0.000009667 seconds

Frequency       : 3.457 ppm fast

Residual freq   : +0.000 ppm

Skew            : 174.367 ppm

Root delay      : 0.000068986 seconds

Root dispersion : 0.006962806 seconds

Update interval : 2.0 seconds

Leap status     : Normal

 

http://www.wxhsa.cn/company.asp?id=2649

相关文章:

  • windows能过注册表修改c盘默认目录
  • ECT-OS-JiuHuaShan框架元推理,就是普罗米修斯主义,穷神知化
  • UI/UX 桌面操作系统应该做好的几个功能
  • 完整教程:1.1 汽车运行滚动阻力
  • 鸿蒙用户首选项数据持久化
  • 基于Transformer的预训练大语言模型,如何区分文本位置?
  • UE RPC介绍
  • part 5
  • GAS_Aura-Code Clean Up
  • 最强大模型评测工具EvalScope
  • JS监听DOM元素的变化
  • CF1485F Copy or Prefix Sum
  • 拉格朗日反演定理(LIFT)
  • 云斗八月银组做题记录
  • 详细介绍:24年秋招-京东-后端开发岗-第1批笔试总结
  • 深入解析:中国AI云市场报告:阿里云份额达35.8%,高于2至4名总和
  • 关于前端的一些疑问整理2(选择器)
  • 模拟散列表(哈希表)
  • 题解:P3323 [SDOI2015] 旅行计划
  • GAS_Aura-Implementing Auto Running
  • 暑假周进度总结
  • 万能欧几里得算法
  • test
  • 直播软件源码,聊聊Java的异常机制问题 - 云豹科技
  • 调度引擎pefect
  • 我的编码规范
  • 静态库与动态库
  • 谷歌浏览器正规下载地址
  • RoPE使用复数乘法的原因
  • 2025 项目管理到底用什么软件?