当前位置: 首页 > 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.zskr.cn/news/3621.html

相关文章:

  • ECT-OS-JiuHuaShan框架元推理,就是普罗米修斯主义,穷神知化
  • UI/UX 桌面操作系统应该做好的几个功能
  • 完整教程:1.1 汽车运行滚动阻力
  • 鸿蒙用户首选项数据持久化
  • 基于Transformer的预训练大语言模型,如何区分文本位置?
  • UE RPC介绍
  • JS监听DOM元素的变化
  • CF1485F Copy or Prefix Sum
  • 云斗八月银组做题记录
  • 题解:P3323 [SDOI2015] 旅行计划
  • GAS_Aura-Implementing Auto Running
  • 深入解析:PostgreSQL 视图与物化视图(View / Materialized View)详解
  • win11专业版如何设置窗口不叠加的问题
  • JBoltAI:解锁企业AI应用开发新范式,驱动数智化升级核心引擎
  • kmp
  • NKOJ全TJ计划——NP11793
  • JBoltAI函数调用技术:自然语言即可查询数据库,重构企业数据交互方式
  • 题解:CF645B Mischievous Mess Makers
  • NKOJ全TJ计划——NP11792
  • 完整教程:Photo Lab PRO 图片编辑器 功能解锁版
  • Ubuntu 18.04 虚拟机 VScode无法正常输入中文解决办法
  • qoj1847 Elephants
  • 基于ArcGIS的通用界址点导入导出工具设计与实现
  • python 函数作用域
  • 文献阅读 | AutoCodeBench
  • Idea win 快捷键大全
  • VSCode+neovim工作环境快速构建
  • 25.9.12随笔联考总结
  • macos
  • 算法复杂度