Linux与运维

CentOS 7 Crontab 定时任务执行时间偏差的根源与排错

在 CentOS 7 设置了每天凌晨 2:00 执行备份的 Crontab 任务,却发现实际在上午 10:00 才运行(偏差整整 8 小时)。这是由于 crond 守护进程未同步系统时区变更所致。


一、 核心根因与解决步骤

  1. 修改系统时区后未重启 crond: 修改 timedatectl 之后,正在运行的 crond 依然沿用启动时的 UTC 零时区。

查看 crontab 实际执行日志确认:

sudo tail -f /var/log/cron

重启 crond 服务使时区立即对齐:

sudo systemctl restart crond