在 CentOS 系统中,如果出现时间戳错误(比如 date 显示时间不对、日志时间错乱、证书失效、定时任务异常等),通常可以按下面步骤排查和处理。
date
timedatectl
查看:
现象:时间数值对,但比本地时间差几小时。
查看当前时区:
timedatectl
设置为中国时区:
timedatectl set-timezone Asia/Shanghai
或手动软链(老版本):
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
现象:date 显示年份/月份/小时都不对。
手动设置时间(不推荐长期使用):
date -s "2026-01-21 15:30:00"
或:
timedatectl set-time "2026-01-21 15:30:00"
⚠️ 修改后建议同步硬件时钟:
hwclock --systohc
现象:重启后又变回错误时间。
查看硬件时间:
hwclock --show
同步系统时间到硬件:
hwclock --systohc
从硬件同步到系统:
hwclock --hctosys
CentOS 7/8 推荐用 chrony
yum install -y ntp
systemctl enable ntpd
systemctl start ntpd
yum install -y chrony
systemctl enable chronyd
systemctl start chronyd
手动同步:
chronyc makestep
查看同步状态:
timedatectl status
看到 System clock synchronized: yes 即正常。
常见于:
解决方法:
systemctl restart chronyd
VMware 工具:
vmware-toolbox-cmd timesync enable
如:
✅ 先修正时间,再重启相关服务
systemctl restart docker
systemctl restart kubelet
timedatectl set-timezone Asia/Shanghai
systemctl enable chronyd
systemctl start chronyd
chronyc makestep
✅ 时区正确
✅ 系统时间正确
✅ 硬件时间正确
✅ NTP/chrony 已同步
如果你能贴出:
cat /etc/redhat-release)timedatectl 输出我可以帮你精准定位是哪一类时间戳错误。