服务器系统时间不准确怎么办?

服务器系统时间不准确可能会导致日志错乱、任务调度失败、SSL证书校验错误等问题。以下是解决办法:


🌐 一、同步系统时间的方法

1. 使用 timedatectl 命令(适用于 systemd 系统)

timedatectl set-ntp true # 开启自动同步 timedatectl status # 查看当前时间状态

若未启用 NTP,可先安装 chrony 或 ntp 服务。


2. 安装并使用 chrony(推荐)

# 安装 sudo apt install chrony # Debian / Ubuntu sudo yum install chrony # CentOS / Rocky # 启动并设置开机自启 sudo systemctl enable --now chronyd # 查看同步状态 chronyc tracking


3. 手动设置时间(不推荐,容易飘移)

date -s "2025-07-21 15:00:00" # 手动设置时间


🧭 二、设置时区

确保系统时区正确,避免因为时区差异导致"时间看似不准":

timedatectl list-timezones # 查看可选时区 timedatectl set-timezone Asia/Shanghai


🛠️ 三、硬件时间与系统时间同步(可选)

hwclock -w # 将系统时间写入硬件时钟 hwclock -s # 将硬件时间写入系统时间

相关推荐
有谁看见我的剑了?1 小时前
VMware OVF Tool 工具安装学习
云计算
C_心欲无痕1 小时前
ts - tsconfig.json配置讲解
linux·前端·ubuntu·typescript·json
冰西瓜6002 小时前
国科大2025操作系统高级教程期末回忆版
linux
HIT_Weston2 小时前
93、【Ubuntu】【Hugo】搭建私人博客:面包屑(一)
linux·运维·ubuntu
cuijiecheng20183 小时前
Linux下Beyond Compare过期
linux·运维·服务器
喵叔哟3 小时前
20.部署与运维
运维·docker·容器·.net
HIT_Weston3 小时前
92、【Ubuntu】【Hugo】搭建私人博客:侧边导航栏(六)
linux·运维·ubuntu
CodeAllen嵌入式3 小时前
Windows 11 本地安装 WSL 支持 Ubuntu 24.04 完整指南
linux·运维·ubuntu
期待のcode3 小时前
前后端分离项目 Springboot+vue 在云服务器上的部署
服务器·vue.js·spring boot
AI 智能服务3 小时前
第6课__本地工具调用(文件操作)
服务器·人工智能·windows·php