侧边栏壁纸
博主头像
学海无涯博主等级

有疑问可发邮件zp@wlzs.cn。

  • 累计撰写 330 篇文章
  • 累计创建 89 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

使用RockyLinux搭建ntp服务器

利刃
2025-09-06 / 0 评论 / 0 点赞 / 2 阅读 / 11206 字
温馨提示:
本文最后更新于 2025-09-06,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

概述

因内网设备时间有异常,需要有一个统一的时间管理服务器,用于内网设备的时间同步。

步骤

安装chrony

[root@zabbix ~]# dnf -y install chrony
上次元数据过期检查:2:05:35 前,执行于 2025年09月06日 星期六 07时42分04秒。
软件包 chrony-4.1-1.el8.x86_64 已安装。
依赖关系解决。
====================================================================================================================================================================================================
 软件包                                       架构                                         版本                                                  仓库                                          大小
====================================================================================================================================================================================================
升级:
 chrony                                       x86_64                                       4.5-2.el8_10                                          baseos                                       354 k

事务概要
====================================================================================================================================================================================================
升级  1 软件包

总下载:354 k
下载软件包:
chrony-4.5-2.el8_10.x86_64.rpm                                                                                                                                      232 kB/s | 354 kB     00:01    
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                                                232 kB/s | 354 kB     00:01     
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                                                                                                                     1/1 
  运行脚本: chrony-4.5-2.el8_10.x86_64                                                                                                                                                          1/1 
  运行脚本: chrony-4.5-2.el8_10.x86_64                                                                                                                                                          1/2 
  升级    : chrony-4.5-2.el8_10.x86_64                                                                                                                                                          1/2 
警告:/etc/chrony.conf 已建立为 /etc/chrony.conf.rpmnew 

  运行脚本: chrony-4.5-2.el8_10.x86_64                                                                                                                                                          1/2 
  运行脚本: chrony-4.1-1.el8.x86_64                                                                                                                                                             2/2 
  清理    : chrony-4.1-1.el8.x86_64                                                                                                                                                             2/2 
  运行脚本: chrony-4.1-1.el8.x86_64                                                                                                                                                             2/2 
  验证    : chrony-4.5-2.el8_10.x86_64                                                                                                                                                          1/2 
  验证    : chrony-4.1-1.el8.x86_64                                                                                                                                                             2/2 

已升级:
  chrony-4.5-2.el8_10.x86_64                                                                                                                                                                        

完毕!

公网NTP服务器

域名 提供单位 单位类型/备注
ntp.aliyun.com 阿里巴巴集团(阿里云) 云服务提供商
ntp.tencent.com 腾讯公司 科技/互联网公司
time.aws.com 亚马逊(Amazon Web Services) 云服务提供商
time.windows.com 微软(Microsoft) 科技公司
time.apple.com 苹果公司(Apple Inc.) 科技公司
time.cloudflare.com Cloudflare 公司 网络服务与安全公司
time.ys7.com 萤石网络(EZVIZ,海康威视旗下) 安防与物联网公司
ntp.ntsc.ac.cn 中国科学院国家授时中心 科研机构(国家级时间服务机构)
ntp.sjtu.edu.cn 上海交通大学 高等教育机构
ntp.fudan.edu.cn 复旦大学 高等教育机构
ntp.neu.edu.cn 东北大学(Northeastern University) 高等教育机构
time.jmu.edu.cn 集美大学(Jimei University) 高等教育机构

配置chrony的时间服务器源

vi /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 2.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
# 允许所有的主机进行连接
allow all

# 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
# 在下方添加可以使用的服务器地址 用于和网络上的服务器进行时间同步
server ntp.aliyun.com iburst
server ntp.tencent.com iburst 
server time.aws.com iburst 
server time.windows.com iburst 
server time.apple.com iburst 
server time.cloudflare.com  iburst 
server time.ys7.com iburst 
server ntp.ntsc.ac.cn iburst 
server ntp.sjtu.edu.cn iburst 
server ntp.fudan.edu.cn iburst 
server ntp.neu.edu.cn iburst 
server time.jmu.edu.cn iburst

image.png

启动服务

systemctl start chronyd
systemctl enable chronyd

查看服务器连接状态

[root@zabbix ~]# chronyc sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* 203.107.6.88                  2   6    17     4  -5658us[  -12ms] +/-   17ms
^+ 106.55.184.199                2   6    17     4   +773us[-6018us] +/-   44ms
^- ec2-54-81-127-33.compute>     4   6    17     5  +8150us[+1359us] +/-  127ms
^- 52.231.114.183                3   6    71     0    -13ms[  -13ms] +/-   96ms
^? twtpe2-ntp-002.aaplimg.c>     1   6    17     3    +14ms[  +14ms] +/- 7984ms
^- time.cloudflare.com           3   6    17     3  +5040us[+5040us] +/-  110ms
^- 101.71.30.225                 3   6    17     4   -757us[ -757us] +/-   62ms
^+ 103.41.165.238                3   6    17     5   -404us[-7196us] +/-   34ms
^- twtpe2-ntp-001.aaplimg.c>     1   6    17     3    +19ms[  +19ms] +/-   45ms
^+ reuters.fudan.edu.cn          1   6    17     5  +5842us[ -950us] +/-   26ms
^+ time.neu.edu.cn               2   6    17     4  +1263us[-5529us] +/-   16ms
^- 210.34.128.32                 3   6    17     5  +7634us[ +843us] +/-   92ms
  • ^*: 当前正在使用的同步源(203.107.6.88 )
  • ^+: 可接受的备份源(103.41.165.238)
  • ^-: 当前被排除的源(202.120.127.191)
  • Stratum: 层级(数字越小越接近参考时钟)
  • Poll: 轮询间隔(10 表示 2^10=1024 秒)
  • Reach: 可达性(377 八进制 = 11111111 二进制,表示最近 8 次查询都成功)
  • Last sample: 最后的时间偏移量样本

查看端口开放状态

[root@zabbix ~]# ss -unlp | grep 123
UNCONN 0      0            0.0.0.0:123        0.0.0.0:*    users:(("chronyd",pid=2678406,fd=8))         
UNCONN 0      0               [::]:123           [::]:*    users:(("chronyd",pid=2678406,fd=9)) 

防火墙放行端口

[root@zabbix ~]# firewall-cmd --zone=public --add-port=123/udp --permanent 
success
[root@zabbix ~]# firewall-cmd --reload
success

网络设备测试

<HX01>dis clock 
2024-04-05 07:12:59
Friday
Time Zone(UTC) : UTC
[HX01] ntp-service  unicast-server 172.17.6.250
Warning: The NTP IPv4 server function is disabled. Run the undo server disable command to enable the IPv4 server function.
Warning: The NTP IPv6 server function is disabled. Run the undo IPv6 server disable command to enable the IPv6 server function.
[HX01]dis clock
2025-09-06 02:31:24
Saturday
Time Zone(UTC) : UTC
[HX01]clock timezone beijing add 8
[HX01]dis clock                   
2025-09-06 10:31:40+08:00
Saturday
Time Zone(beijing) : UTC+08:00
0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区