CentOS 出现“时间戳不对(时间快了/慢了/时区不对)”通常是时间同步、时区设置或硬件时钟(RTC)问题。下面按最常见原因 → 排查 → 解决给你说明。
系统时区不对,看起来时间就“偏了”。
timedatectl
重点看:
Time zoneLocal timeUniversal time✅ 中国应该看到:
Time zone: Asia/Shanghai (CST, +0800)
❌ 如果是 UTC 或 America/New_York 就不对
解决方法:
timedatectl set-timezone Asia/Shanghai
系统时间没和互联网同步,时间会越来越不准。
timedatectl status
看:
NTP enabled: yes
NTP synchronized: yes
❌ 若不是 yes,说明没同步
解决方法(CentOS 7/8/Stream):
# 安装 chrony
yum install -y chrony
# 启动并设置开机自启
systemctl enable chronyd
systemctl start chronyd
# 同步时间
chronyc -a makestep
验证:
chronyc sources
系统重启后时间就恢复错误,通常是主板 BIOS 时间不对。
查看硬件时间:
hwclock
与系统时间对比:
date
同步方法:
系统时间 → 硬件时间:
hwclock --systohc
硬件时间 → 系统时间:
hwclock --hctosys
如果之前手动执行过:
date -s "2024-01-01 10:00:00"
又没有同步,时间会漂移。
✅ 正确做法:不要手动改时间,用 NTP
虚拟机常见:
VMware:
vmware-toolbox-cmd timesync enable
KVM / Cloud: 启用 chrony 即可
# 1. 看当前时间与时区
timedatectl
# 2. 看是否 NTP 同步
timedatectl | grep NTP
# 3. 看硬件时间
hwclock
# 4. 看同步源
chronyc sources
timedatectl set-timezone Asia/Shanghai
yum install -y chrony
systemctl enable chronyd
systemctl start chronyd
chronyc -a makestep
hwclock --systohc
CentOS 时间不对 = 时区错 OR 没开 NTP OR 硬件时钟错
如果你愿意,可以把下面命令的输出贴出来,我可以直接帮你判断是哪一类问题:
timedatectl
date
hwclock