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

服务器系统时间不准确可能会导致日志错乱、任务调度失败、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 # 将硬件时间写入系统时间

相关推荐
用户03284722207015 小时前
如何搭建本地yum源(上)
运维
Aloys_Code19 小时前
逆向一个被遗忘的DVD游戏格式:从DES加密到Rust模拟器
游戏·模拟器·retroarch·复古游戏·native32·sunplus·赤刃·钢铁风暴
金銀銅鐵1 天前
用 Python 实现 Take-Away 游戏
python·游戏
金銀銅鐵2 天前
用 Pygame 实现 15 puzzle
python·数学·游戏
A小辣椒2 天前
TShark:Wireshark CLI 功能
linux
A小辣椒2 天前
TShark:基础知识
linux
AlfredZhao2 天前
OCI 明明分配了 200G 系统盘,为什么 df 只看到 30G?
linux·oci
AlfredZhao3 天前
vi 删除指定范围的行,不用再反复按 dd
linux·vi
用户9718356334663 天前
银河麒麟 KY10 申威(SW64) 安装 nginx-1.16.1-2.p01.ky10.sw_64.rpm 详细步骤
linux
猪脚踏浪3 天前
linux 拷贝文件或目录到指定的位置
linux