温馨提示×

centos怎么同步时间戳

小樊
44
2026-08-18 09:17:36
栏目: 智能运维

CentOS 上同步系统时间(时间戳)通常有两种常见方式:使用 NTP(ntp/ntpdate使用 chronyd(CentOS 7/8 默认)。下面按版本和场景说明。


一、CentOS 7 / 8 / Stream(推荐 chronyd

1. 查看当前时间

timedatectl

2. 启用并启动 chronyd

systemctl enable chronyd
systemctl start chronyd

3. 手动同步时间

chronyc -a makestep

4. 确认同步状态

chronyc tracking

chronyc sources

5. 设置时区(如需要)

timedatectl list-timezones | grep Asia
timedatectl set-timezone Asia/Shanghai

二、CentOS 6 或老系统(使用 ntp)

1. 安装 ntp

yum install -y ntp

2. 同步时间

ntpdate pool.ntp.org

3. 启动 ntpd 服务

service ntpd start
chkconfig ntpd on

三、一次性强制同步(通用)

date
ntpdate -u ntp.aliyun.com

常见 NTP 服务器:

  • ntp.aliyun.com
  • pool.ntp.org
  • time.windows.com

四、硬件时间(BIOS 时间)同步

查看硬件时间

hwclock

系统时间写入硬件时间

hwclock --systohc

五、常见问题排查

1. 时间不同步

timedatectl status

确认:

  • NTP enabled: yes
  • NTP synchronized: yes

2. 虚拟机时间漂移

  • 开启 chronyd
  • 或关闭虚拟机时间同步后由系统自行同步

六、推荐配置(生产环境)

timedatectl set-ntp true
timedatectl set-timezone Asia/Shanghai

如果你能告诉我:

  • CentOS 版本
  • 是否虚拟机 / 物理机
  • 是否离线环境

我可以给你更精确的同步方案。

0