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

日志对不上别乱查!服务器时间飘了,chronyd 一键校准全网时钟。

Linux 时间管理

系统时间设置

date 命令

# 设置语言为英语[root@server ~11:34:50]# LANG=en_US.utf8 dateFri Jul2413:29:06 CST2026# 中文语言代码为zh_CN.utf-8# 设置为特定时间,时间字符串必须是英文格式[root@server ~13:29:41]# date -s '2022年 11月 11日 星期四 11:30:10 CST'date: 无效的日期"2022年 11月 11日 星期四 11:30:10 CST"[root@server ~13:29:55]# date -s 'Thu Nov 11 11:30:59 CST 2022'20221111日 星期五11:30:59 CST

hwclock 命令

# 读取硬件时钟[root@server ~13:58:18]# hwclock -r2026年07月24日 星期五13时59分46秒-0.600207# 将硬件时钟时间设置与系统时间一致[root@server ~13:59:45]# hwclock -w# 将系统时间设置与硬件时钟时间一致[root@server ~14:00:26]# hwclock -s

timedatectl 命令

[root@server ~14:00:34]# timedatectlLocal time: 五2026-07-2414:01:02 CST Universal time: 五2026-07-24 06:01:02 UTC RTC time: 五2026-07-24 06:01:02 Time zone: Asia/Shanghai(CST, +0800)NTP enabled:yesNTP synchronized: no RTCinlocalTZ: no DST active: n/a# RTC real time clock,也就是硬件时钟时间。# NTP enabled: yes,代表对时服务chronyd应开机自启。# 关闭自动对时[root@server ~14:01:09]# timedatectl set-ntp no[root@server ~14:01:47]# timedatectlLocal time: 五2026-07-2414:02:00 CST Universal time: 五2026-07-24 06:02:00 UTC RTC time: 五2026-07-24 06:02:00 Time zone: Asia/Shanghai(CST, +0800)NTP enabled: no NTP synchronized: no RTCinlocalTZ: no DST active: n/a[root@server ~14:02:00]# timedatectl set-time '2022-11-10 11:42:54'# 如果自动对时未关闭,显示如下[root@server ~11:43:24]# timedatectl set-time '2022-11-10 11:42:54'Failed tosettime: Automatictimesynchronization is enabled# 设置时区root@server ~11:43:26]# timedatectl set-timezone Asia/Shanghaitimedatectl set-timezone Asia/Shanghai

tzselect 命令

查询时区名称。

[root@server ~14:07:04]# tzselectPlease identify a location so thattimezone rules can besetcorrectly. Pleaseselecta continent or ocean.1)Africa2)Americas3)Antarctica4)Arctic Ocean5)Asia6)Atlantic Ocean7)Australia8)Europe9)Indian Ocean10)Pacific Ocean11)none - I want to specify thetimezone using the Posix TZ format.#? 5Pleaseselecta country.1)Afghanistan18)Israel35)Palestine2)Armenia19)Japan36)Philippines3)Azerbaijan20)Jordan37)Qatar4)Bahrain21)Kazakhstan38)Russia5)Bangladesh22)Korea(North)39)Saudi Arabia6)Bhutan23)Korea(South)40)Singapore7)Brunei24)Kuwait41)Sri Lanka8)Cambodia25)Kyrgyzstan42)Syria9)China26)Laos43)Taiwan10)Cyprus27)Lebanon44)Tajikistan11)East Timor28)Macau45)Thailand12)Georgia29)Malaysia46)Turkmenistan13)Hong Kong30)Mongolia47)United Arab Emirates14)India31)Myanmar(Burma)48)Uzbekistan15)Indonesia32)Nepal49)Vietnam16)Iran33)Oman50)Yemen17)Iraq34)Pakistan#? 9Pleaseselectone of the followingtimezone regions.1)Beijing Time2)Xinjiang Time#? 1The following information has been given: China Beijing Time ThereforeTZ='Asia/Shanghai'will be used. Localtimeis now: Fri Jul2414:08:09 CST2026. Universal Time is now: Fri Jul2406:08:09 UTC2026. Is the above information OK?1)Yes2)No#? 1You canmakethis change permanentforyourself by appending the lineTZ='Asia/Shanghai';exportTZ to thefile'.profile'inyour home directory;thenlog out and loginagain. Here is that TZ value again, thistimeon standard output so that you can use the /bin/tzselectcommandinshell scripts: Asia/Shanghai

windows 自动对时

自动对时-chronyd 服务

# 安装软件包root@server ~14:08:11]# yum install chrony# 修改对时服务器[root@server ~14:09:11]# vim /etc/chrony.conf# 与时间池对时# 时间池是包含多个时间服务器的服务器组pool2.rocky.pool.ntp.org iburst# 与单个服务器 ntp.aliyun.com 对时server ntp.aliyun.com iburst# 启用并启动chronyd服务[root@server ~17:08:59]# systemctl enable chronyd --now# 如果之前已经启动,需要重启[root@centos7 ~]# systemctl restart chronyd# 验证对时情况[root@server ~17:09:46]# chronyc sources -v210Number of sources=9.-- Source mode'^'=server,'='=peer,'#'=localclock. / .- Source state'*'=current synced,'+'=combined ,'-'=not combined,|/'?'=unreachable,'x'=timemay beinerror,'~'=timetoo variable.||.- xxxx[yyyy]+/- zzzz||Reachability register(octal)-.|xxxx=adjusted offset,||Log2(Polling interval)--.||yyyy=measured offset,||\||zzzz=estimated error.||||\MS Name/IP address Stratum Poll Reach LastRx Last sample===============================================================================^? ntp.wdc2.us.leaseweb.net060- +0ns[+0ns]+/- 0ns ^- ntp.ams1.nl.leaseweb.net361717-15ms[-15ms]+/- 109ms ^? ntp6.flashdance.cx272020-12ms[-11ms]+/- 141ms ^- tock.ntp.infomaniak.ch161719+3195us[+4975us]+/- 116ms ^-119.28.206.193261719-7566us[-5786us]+/- 62ms ^? ntp6.flashdance.cx060- +0ns[+0ns]+/- 0ns ^?2001:da8:215:4020::118:1>060- +0ns[+0ns]+/- 0ns ^?2408:4006:119b:800:5cbf:>060- +0ns[+0ns]+/- 0ns ^*203.107.6.88261717+72us[+1852us]+/- 21ms

补充:vim 高级用法

vim 高级用法,可视化模式: 功能1:批量增加内容,例如注释多行内容

  1. 光标定位到目标位置,ctrl+v
  2. 向下移动光标,按需选中多行
  3. I 进行插入,写入#
  4. esc

功能2:列删除,例如批量解除注释 1. 光标定位到目标位置,ctrl+v 2. 向下移动光标,按需选中多行 3. x或d

功能3:列复制并粘贴,例如批量增加主机名后缀 1. 光标定位到目标位置,ctrl+v 2. 向下移动光标(可以上下左右同时移动,选冲矩形块),按需选中 3. y复制 4. 光标定位到目标位置,p粘贴

部署时间服务器

chrony 既可以作为客户端,也可以作为服务端(为客户端提供对时服务)。

服务端

[root@server ~13:39:43]# vim /etc/chrony.conf# 最后添加两条记录# 配置监听地址bindaddress10.1.8.10# 配置允许哪些网段主机同步allow10.1.8.0/24[root@server ~13:41:18]# systemctl restart chronyd# 停止防火墙服务[root@server ~13:42:00]# systemctl stop firewalld.service

必须确保服务端的时间的准确性、有效性。

客户端

# 修改对时服务器[root@server ~13:42:12]# vim /etc/chrony.conf# 与单个服务器 10.1.8.10 对时server10.1.8.10 iburst[root@client ~13:45:30]# systemctl restart chronyd[root@client ~13:45:51]# chronyc sources -v210Number of sources=1.-- Source mode'^'=server,'='=peer,'#'=localclock. / .- Source state'*'=current synced,'+'=combined ,'-'=not combined,|/'?'=unreachable,'x'=timemay beinerror,'~'=timetoo variable.||.- xxxx[yyyy]+/- zzzz||Reachability register(octal)-.|xxxx=adjusted offset,||Log2(Polling interval)--.||yyyy=measured offset,||\||zzzz=estimated error.||||\MS Name/IP address Stratum Poll Reach LastRx Last sample===============================================================================^? server.xiaoma.cloud060- +0ns[+0ns]+/- 0ns

全文总结

分清系统时间(软件)和硬件时钟(主板 hwclock);date 管理系统时间,hwclock 实现两者互相同步。
CentOS7 首选 timedatectl 统一管理时区、时间、NTP 状态;设置中国时区:timedatectl set-timezone Asia/Shanghai。
线上环境禁止随意手动 date 改时间,统一使用 chronyd 自动对时,避免时间跳跃引发业务故障。
内网隔离环境,可以搭建 chrony 时间服务器,所有内网设备统一同步内网标准时间。
双系统时间相差 8 小时,使用 timedatectl set-local-rtc 1 解决冲突。

http://www.jsqmd.com/news/1258005/

相关文章:

  • AMD推出Helios AI机架系统,正面挑战英伟达
  • 深入解析TI KeyStone II EDMA3控制器:架构、配置与性能优化实战
  • 完全免费的MySQL数据库管理神器:SQLyog社区版终极使用指南
  • 28-其他神级插件推荐指南
  • 2026 年现阶段,怀仁专业的小型石牌坊制造厂怎么联系,别再花大钱!这小石牌坊如何帮你省下万元? - 企业官方推荐【认证】
  • 2026年新消息:解析安吉县行业知名的工装服务团队一都装饰设计 - 装修教育财税推荐2026
  • 2026年现阶段盐田正规老酒回收平台推荐:全发石材店老酒回收服务解析 - 装修教育财税推荐2026
  • MSP430FR6xx超低功耗MCU焊盘与钢网设计实战指南
  • 显卡驱动彻底清理指南:使用Display Driver Uninstaller(DDU)三步解决驱动冲突问题
  • AI编程工具如何降低技术门槛:从NBA选秀预测看未来开发模式变革
  • GTA5线上小助手:3大核心功能彻底改变您的洛圣都冒险体验
  • Linux线程编程核心技术与实战优化
  • 2026年售前智能客服软件厂商推荐,助力企业提升客户服务 - 品牌排行榜
  • Patreon裁员20%,共涉及93名员工
  • 重构合作伙伴 ROI:除了销售额,这 3 个指标才是增长晴雨表
  • 2026年什么牌子的养生壶质量好又实惠?看这篇就够了 - 品牌排行榜
  • Loopweave音频无缝循环工具:从原理到批量处理实战指南
  • AI如何提升论文写作效率:从选题到定稿的全流程优化
  • 2026年江苏靠谱技工学校大揭秘! - 品牌排行榜
  • Listen1跨平台音乐聚合扩展:歌词显示功能的3大技术挑战与解决方案
  • 微信聊天记录本地解密终极指南:3分钟解锁你的数字记忆宝库
  • BLIP:Bootstrapping Language-Image Pre-training
  • DeepSeek LeetCode 3710. 最大划分因子 Rust实现
  • 使用pymodbus实现Modbus TLS加密通信:从证书生成到生产部署
  • 29-主题选择与安装-找到你的审美
  • 芜湖本地防水补漏精选TOP5推荐:正规漏水检测维修公司上门师傅推荐:厕所/棚顶/屋面/飘窗/阳台/地下室/厨房渗漏水精准测漏维修(2026最新) - 即刻修防水
  • 2026芜湖漏水检测维修本地口碑榜TOP5权威推荐-专业仪器精准测漏-正规防水补漏公司推荐:卫生间/厨房/屋顶/阳台/外墙渗漏水检测师傅上门 - 安佳防水
  • 如何快速创建个性化桌面宠物:DyberPet开源框架完全指南
  • 2026类似于OpenClaw的定制化系统有哪些?高性价比OpenClaw替代方案商测评
  • 腾讯混元3D 2.0+ComfyUI:单图生成3D模型的低门槛实战指南