Centos服务器时间调整
1. 安装并配置 chrony 时间同步服务
# 安装 chrony
yum install -y chrony
# 编辑配置文件,替换为国内 NTP 服务器
sed -i.bak '/^pool/d' /etc/chrony.conf
cat >> /etc/chrony.conf << EOF
pool ntp.aliyun.com iburst
pool time1.aliyun.com iburst
pool time2.aliyun.com iburst
EOF
# 重启 chrony 服务并设置开机自启
systemctl restart chronyd
systemctl enable chronyd
# 强制同步时间
chronyc -a makestep2. 同步硬件时钟(RTC)与系统时间
硬件时钟(RTC)是主板上的时钟,重启后系统会读取它,因此必须与系统时间一致:
# 将系统时间写入硬件时钟
hwclock -w
# 验证硬件时钟是否同步
hwclock -r3. 验证配置结果
# 检查 NTP 同步状态
timedatectl
# 检查 chrony 同步源
chronyc sources -v预期输出:
NTP enabled: yes
NTP synchronized: yes
RTC time 与 Local time 相差在几秒内