在 CentOS 中“替换系统时间”通常指 手动修改系统时间 或 更换时间同步方式(NTP)。下面按常见场景给你说明。
date 命令(推荐)date -s "2026-01-21 15:30:00"
然后同步到硬件时钟(防止重启失效):
hwclock --systohc
timedatectl(CentOS 7+)查看当前时间状态:
timedatectl
设置时间:
timedatectl set-time "2026-01-21 15:30:00"
⚠️ 如果报错:
Failed to set time: Automatic time synchronization is enabled.
先关闭 NTP:
timedatectl set-ntp false
再设置时间。
timedatectl list-timezones | grep Shanghai
timedatectl set-timezone Asia/Shanghai
或老版本:
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yum install -y chrony
systemctl enable chronyd
systemctl start chronyd
查看同步状态:
chronyc sources -v
yum install -y ntp
service ntpd start
chkconfig ntpd on
编辑配置:
vi /etc/chrony.conf
示例:
server ntp.aliyun.com iburst
server cn.pool.ntp.org iburst
重启:
systemctl restart chronyd
✅ 没执行:
hwclock --systohc
✅ 建议:
✅ 时区不是 Asia/Shanghai
| 需求 | 推荐方式 |
|---|---|
| 临时改时间 | date -s |
| 永久改时间 | timedatectl + hwclock |
| 生产环境 | chrony |
| 改时区 | timedatectl set-timezone |
如果你能说明:
我可以给你更精确的方案。