在 CentOS 系统中校准时间戳(系统时间)可以通过 NTP(网络时间协议) 或 手动设置 来完成。以下是常用方法:
CentOS 7/8 默认可能未安装 NTP:
yum install -y ntp
systemctl start ntpd
systemctl enable ntpd
ntpdate pool.ntp.org
ntpq -p
CentOS 7 以后默认使用 chrony 替代 ntpd。
yum install -y chrony
systemctl start chronyd
systemctl enable chronyd
chronyc -a makestep
chronyc sources
timedatectl
timedatectl set-ntp true
timedatectl set-timezone Asia/Shanghai
date -s "2026-01-21 15:30:00"
hwclock --systohc
hwclock --systohc # 系统时间 → 硬件时间
hwclock --hctosys # 硬件时间 → 系统时间
timedatectl list-timezones | grep Shanghai
| 场景 | 推荐方式 |
|---|---|
| CentOS 7/8 | chrony |
| 老系统 | ntp |
| 临时调整 | timedatectl / date |
如果你能告诉我 CentOS 版本(6/7/8) 或 物理机/虚拟机,我可以给你更精确的方案。