大数据

Centos时间同步

✅ 推荐方案:使用 chrony(CentOS 7+ 默认推荐)

1. 安装 chrony(如未安装)

sudo yum install -y chrony
# 或 CentOS 8/9 使用 dnf
# sudo dnf install -y chrony

2. 编辑 chrony 配置文件

sudo vim /etc/chrony.conf

将默认的 server 行注释掉,添加阿里云 NTP 服务器:

# 注释掉原来的 server 行(如:server 0.centos.pool.ntp.org iburst)
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst

# 使用阿里云 NTP 服务器
server ntp.aliyun.com iburst

阿里云官方提供的公网 NTP 地址:

  • ntp.aliyun.com
  • ntp1.aliyun.com ~ ntp7.aliyun.com

3. 启动并启用 chronyd 服务

sudo systemctl start chronyd
sudo systemctl enable chronyd

4. 检查同步状态

# 查看时间同步状态
chronyc tracking

# 查看当前使用的 NTP 源
chronyc sources -v

# 立即手动同步(可选)
sudo chronyc makestep

如果看到 System time 正在同步,且 sources 中显示 ^*(表示当前同步源),说明已成功。