当前位置:首页>Linux>Linux 服务器时间不同步的影响与修复方法

Linux 服务器时间不同步的影响与修复方法

  • 2026-08-21 02:40:50
Linux 服务器时间不同步的影响与修复方法

Linux 服务器时间不同步的影响与修复方法

一、问题背景

生产环境中,多台服务器之间时间不同步是一个容易被忽视但影响严重的问题。服务器时间偏差可能只有几秒甚至几分钟,但足以导致分布式系统出现各种诡异故障:日志时间戳混乱、监控数据错位、缓存失效、认证失败、数据库主从延迟异常、定时任务错乱等。

时间不同步的原因多种多样:系统时钟漂移、NTP 服务未配置、NTP 服务器不可达、虚拟化环境时钟同步问题、BIOS 电池耗尽、手动修改时间未同步等。

本文从实战角度出发,介绍时间不同步的影响、排查方法、NTP/Chrony 配置、时间同步验证、常见问题处理、风险控制和生产环境注意事项。

二、适用场景

  • 多台服务器组成的分布式系统
  • 数据库主从复制环境
  • 日志收集和分析系统
  • 监控告警系统
  • 缓存集群(Redis、Memcached)
  • 消息队列集群(Kafka、RabbitMQ)
  • 容器和 Kubernetes 集群
  • 需要时间戳验证的认证系统(Kerberos、LDAP、OAuth2)
  • 分布式事务和一致性系统
  • 定时任务和调度系统

三、核心知识点

3.1 时间不同步的影响

3.1.1 日志分析困难

多台服务器日志时间戳不一致,追踪请求链路时无法确定事件先后顺序。

示例:

  • 服务器 A:2026-08-13 10:00:05 接收请求
  • 服务器 B:2026-08-13 09:59:58 处理请求
  • 服务器 C:2026-08-13 10:00:12 返回响应

从时间戳看,B 在接收请求前就已经处理了,显然不合理。实际上 B 的时间慢了 7 秒。

3.1.2 监控数据错位

Prometheus、Zabbix、Grafana 等监控系统依赖时间戳聚合数据。若服务器时间不一致,监控曲线会出现毛刺、断点、数据错位。

示例:

  • 服务器 A 上报 CPU 使用率:10:00:00 -> 50%
  • 服务器 B 上报 CPU 使用率:09:59:50 -> 60%
  • Grafana 汇总时,B 的数据会被认为是 10 秒前的,导致曲线错位

3.1.3 缓存失效

Redis、Memcached 等缓存系统使用 TTL(过期时间)机制。若服务器时间不一致,缓存可能提前失效或延迟失效。

示例:

  • 应用服务器 A 时间:10:00:00,写入缓存,TTL=300 秒,预期 10:05:00 过期
  • 缓存服务器时间:09:59:00,计算过期时间为 10:04:00
  • 实际上缓存在 10:04:00 就过期了,比预期提前 1 分钟

3.1.4 认证失败

Kerberos、LDAP、OAuth2 等认证系统依赖时间戳防止重放攻击。若客户端和服务器时间差超过允许范围(通常 5 分钟),认证会失败。

示例错误:

kinit: Clock skew too great while getting initial credentials

3.1.5 数据库主从延迟异常

MySQL、PostgreSQL 主从复制依赖时间戳判断延迟。若主从服务器时间不一致,延迟监控会显示异常值。

示例:

  • 主库时间:10:00:00,执行 SQL,binlog 记录时间戳 10:00:00
  • 从库时间:09:59:50,接收 binlog,计算延迟 = 09:59:50 - 10:00:00 = -10 秒
  • 监控显示延迟为负数,误报或告警失效

3.1.6 分布式事务异常

分布式事务使用时间戳判断事务顺序和超时。若服务器时间不一致,事务可能被错误回滚或提交。

3.1.7 定时任务错乱

Cron、systemd timer、Kubernetes CronJob 等定时任务依赖系统时间。若时间不准确,任务可能提前执行、延迟执行或重复执行。

示例:

  • 定时任务设置为每天 02:00 执行备份
  • 服务器时间突然快进 1 小时,02:00 被跳过,任务当天不执行
  • 服务器时间突然回退 1 小时,02:00 被经历两次,任务执行两次

3.1.8 SSL 证书验证失败

SSL/TLS 证书有有效期,若服务器时间不准确,证书可能被认为未生效或已过期。

示例错误:

SSL certificate problem: certificate is not yet valid
SSL certificate problem: certificate has expired

3.2 时间同步协议

3.2.1 NTP(Network Time Protocol)

  • 经典的时间同步协议,广泛使用
  • 通过多层时间服务器同步时间
  • 精度可达毫秒级
  • 守护进程:ntpd
  • 适用于传统 Linux 系统

3.2.2 Chrony

  • 新一代时间同步工具,CentOS 7+/RHEL 7+ 默认使用
  • 比 NTP 更快、更准确、更适应网络不稳定环境
  • 精度可达微秒级
  • 守护进程:chronyd
  • 适用于虚拟化环境、移动设备、间歇性网络连接

3.2.3 时间源(Time Source)

  • Stratum 0:原子钟、GPS 时钟等硬件时钟源
  • Stratum 1:直接连接 Stratum 0 的服务器
  • Stratum 2:从 Stratum 1 同步时间的服务器
  • Stratum 3:从 Stratum 2 同步时间的服务器
  • 层级越低,精度越高
  • 生产环境通常使用 Stratum 2 或 Stratum 3 服务器

常用公共 NTP 服务器:

  • 阿里云:
    ntp.aliyun.com
  • 腾讯云:
    time1.cloud.tencent.com
  • 国家授时中心:
    ntp.ntsc.ac.cn
  • NTP Pool:
    pool.ntp.org
  • Google:
    time.google.com
  • Cloudflare:
    time.cloudflare.com

3.3 时区与 UTC

3.3.1 UTC(Coordinated Universal Time)

  • 协调世界时,国际标准时间
  • 不受时区和夏令时影响
  • 系统内部时间通常使用 UTC
  • Unix 时间戳是自 1970-01-01 00:00:00 UTC 以来的秒数

3.3.2 本地时间

  • 根据时区转换的时间
  • 中国大陆:UTC+8(东八区)
  • 美国东部:UTC-5(冬季)或 UTC-4(夏季)
  • 应用显示时间通常使用本地时间

3.3.3 时区配置

  • 时区配置文件:/etc/localtime
  • 时区数据库:/usr/share/zoneinfo/
  • 中国时区:Asia/Shanghai

3.4 系统时钟类型

3.4.1 硬件时钟(RTC, Real-Time Clock)

  • BIOS/UEFI 中的硬件时钟
  • 由主板电池供电,系统关机后仍运行
  • 精度较低,会漂移
  • 查看命令:hwclock

3.4.2 系统时钟(System Clock)

  • Linux 内核维护的时钟
  • 系统启动时从硬件时钟读取初始值
  • 运行过程中由内核维护
  • 精度较高
  • 查看命令:date

3.4.3 时钟同步方向

  • 通常 NTP/Chrony 同步系统时钟
  • 系统时钟定期写入硬件时钟(避免重启后时间回退)
  • 手动同步:hwclock --systohc(系统时钟 -> 硬件时钟)
  • 手动同步:hwclock --hctosys(硬件时钟 -> 系统时钟)

四、整体排查思路

1. 确认时间不同步现象(日志错乱、监控异常、认证失败)
2. 检查当前系统时间和时区
3. 检查硬件时钟
4. 检查 NTP/Chrony 服务状态
5. 检查 NTP/Chrony 配置
6. 检查时间源可达性
7. 检查时间偏差大小
8. 若时间偏差较小,等待自动同步
9. 若时间偏差较大,手动同步或重启服务
10. 验证时间同步是否正常
11. 配置监控告警
12. 记录问题和处理过程

五、实战步骤

5.1 检查当前时间状态

5.1.1 查看系统时间

bash
date

输出示例:

2026年 08月 13日 星期三 10:23:45 CST

或使用标准格式:

bash
date"+%Y-%m-%d %H:%M:%S"

输出示例:

2026-08-13 10:23:45

5.1.2 查看硬件时钟

bash
hwclock --show

bash
hwclock -r

输出示例:

2026-08-13 10:23:50.123456+08:00

5.1.3 比较系统时钟和硬件时钟

bash
hwclock --compare

或手动比较:

bash
echo"System time: $(date '+%Y-%m-%d %H:%M:%S')"
echo"Hardware time: $(hwclock --show)"

5.1.4 查看时区

bash
timedatectl

输出示例:

      Local time: 三 2026-08-13 10:23:45 CST
  Universal time: 三 2026-08-13 02:23:45 UTC
        RTC time: 三 2026-08-13 02:23:45
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

重点字段:

  • Local time:本地时间
  • Universal time:UTC 时间
  • Time zone:时区
  • NTP enabled:NTP 是否启用
  • NTP synchronized:是否已同步

或查看时区文件:

bash
ls -l /etc/localtime

输出示例:

lrwxrwxrwx 1 root root 33 Jan  1  2023 /etc/localtime -> /usr/share/zoneinfo/Asia/Shanghai

5.1.5 检查多台服务器时间差

在多台服务器上执行:

bash
for host in server1 server2 server3; do
echo -n "$host: "
  ssh $host"date '+%Y-%m-%d %H:%M:%S'"
done

输出示例:

server1: 2026-08-13 10:23:45
server2: 2026-08-13 10:24:12
server3: 2026-08-13 10:23:38

判断逻辑:

  • server2 比 server1 快 27 秒
  • server3 比 server1 慢 7 秒
  • 时间偏差超过 5 秒,需要修复

5.2 检查 NTP/Chrony 服务状态

5.2.1 检查系统使用的时间同步工具

CentOS/RHEL 7+、Ubuntu 18.04+ 默认使用 Chrony:

bash
systemctl status chronyd

CentOS/RHEL 6、Ubuntu 16.04 及更早版本使用 NTP:

bash
systemctl status ntpd

bash
service ntpd status

5.2.2 查看 Chrony 同步状态

bash
chronyc tracking

输出示例:

Reference ID    : 5.6.7.8 (ntp.aliyun.com)
Stratum         : 3
Ref time (UTC)  : Wed Aug 13 02:23:45 2026
System time     : 0.000000123 seconds fast of NTP time
Last offset     : +0.000000089 seconds
RMS offset      : 0.000000234 seconds
Frequency       : 12.345 ppm slow
Residual freq   : +0.001 ppm
Skew            : 0.123 ppm
Root delay      : 0.012345678 seconds
Root dispersion : 0.000123456 seconds
Update interval : 64.5 seconds
Leap status     : Normal

重点字段:

  • Reference ID:当前时间源
  • Stratum:层级,数值越小越精确
  • System time:系统时间与 NTP 时间的偏差
  • Last offset:上次同步的时间偏差
  • Leap status:闰秒状态,Normal 表示正常

判断逻辑:

  • System time 接近 0,说明时间已同步
  • Stratum 为 16 或 Reference ID 为 0.0.0.0,说明未同步到有效时间源

查看时间源列表:

bash
chronyc sources

输出示例:

210 Number of sources = 4
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* ntp.aliyun.com                 2   6   377    32   +123us[ +156us] +/-   12ms
^- time1.cloud.tencent.com        2   6   377    33   +234us[ +267us] +/-   15ms
^- ntp.ntsc.ac.cn                 1   6   377    34   -345us[ -312us] +/-   18ms
^- time.google.com                1   6   377    35   +456us[ +489us] +/-   25ms

字段说明:

  • ^*:当前使用的时间源
  • ^-:备用时间源
  • ^?:不可达的时间源
  • ^x:被排除的时间源
  • Stratum:时间源层级
  • Reach:最近 8 次查询的成功率(八进制),377 表示全部成功
  • LastRx:上次接收响应的时间(秒)
  • Last sample:时间偏差

查看详细同步信息:

bash
chronyc sourcestats

输出示例:

210 Number of sources = 4
Name/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev
===============================================================================
ntp.aliyun.com             16  10   642     +0.123      0.234  +123us   345us
time1.cloud.tencent.com    16   9   641     +0.234      0.345  +234us   456us
ntp.ntsc.ac.cn             16   8   640     -0.345      0.456  -345us   567us
time.google.com            16   7   639     +0.456      0.567  +456us   678us

5.2.3 查看 NTP 同步状态

bash
ntpq -p

输出示例:

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntp.aliyun.com  .GPS.            1 u   32   64  377    12.345    0.123   0.234
+time1.cloud.ten .GPS.            1 u   33   64  377    15.456    0.234   0.345
-ntp.ntsc.ac.cn  .GPS.            1 u   34   64  377    18.567   -0.345   0.456
-time.google.com .GOOG.           1 u   35   64  377    25.678    0.456   0.567

字段说明:

  • *:当前使用的时间源
  • +:备用时间源
  • -:已连接但未使用的时间源
  • x:被排除的时间源
  • st:Stratum 层级
  • reach:最近 8 次查询的成功率(八进制)
  • delay:往返延迟(毫秒)
  • offset:时间偏差(毫秒)
  • jitter:抖动(毫秒)

查看同步状态:

bash
ntpstat

输出示例:

synchronised to NTP server (5.6.7.8) at stratum 2
   time correct to within 12 ms
   polling server every 64 s

unsynchronised
   polling server every 8 s

若显示 unsynchronised,说明未同步。

5.3 配置 Chrony 时间同步

5.3.1 安装 Chrony

CentOS/RHEL:

bash
yum install -y chrony

Ubuntu/Debian:

bash
apt-get install -y chrony

5.3.2 配置 Chrony

编辑配置文件:

bash
vi /etc/chrony.conf

CentOS/RHEL 配置文件位置:/etc/chrony.conf

Ubuntu/Debian 配置文件位置:/etc/chrony/chrony.conf

配置示例:

conf
# 时间源配置,优先使用国内 NTP 服务器
server ntp.aliyun.com iburst
server time1.cloud.tencent.com iburst
server ntp.ntsc.ac.cn iburst
server pool.ntp.org iburst

# 本地时间源(当网络不可达时使用,Stratum 设为 10)
local stratum 10

# 允许大幅度调整时间(首次同步时)
makestep 1.0 3

# 记录时钟偏差
driftfile /var/lib/chrony/drift

# 允许哪些客户端查询时间(若本机作为 NTP 服务器)
# allow 192.168.1.0/24

# 日志目录
logdir /var/log/chrony

配置项说明:

  • server:时间源,iburst 表示启动时快速同步
  • pool:时间源池,自动选择多个服务器
  • local stratum 10:本地时钟作为备用时间源
  • makestep 1.0 3:若时间偏差超过 1 秒,前 3 次更新时直接调整(而非缓慢调整)
  • driftfile:记录时钟偏差,用于系统重启后快速同步
  • allow:允许哪些客户端查询时间(若本机作为 NTP 服务器)

5.3.3 启动 Chrony 服务

bash
systemctl start chronyd
systemctl enable chronyd

验证服务状态:

bash
systemctl status chronyd

输出示例:

● chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2026-08-13 10:23:45 CST; 5s ago
 Main PID: 12345 (chronyd)
   CGroup: /system.slice/chronyd.service
           └─12345 /usr/sbin/chronyd

Aug 13 10:23:45 server1 systemd[1]: Starting NTP client/server...
Aug 13 10:23:45 server1 chronyd[12345]: chronyd version 3.4 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +SECHASH +IPV6 +DEBUG)
Aug 13 10:23:45 server1 systemd[1]: Started NTP client/server.
Aug 13 10:23:50 server1 chronyd[12345]: Selected source ntp.aliyun.com
Aug 13 10:23:50 server1 chronyd[12345]: System clock was stepped by 5.234567 seconds

重点关注:

  • Active: active (running):服务运行中
  • Selected source ntp.aliyun.com:已选择时间源
  • System clock was stepped by 5.234567 seconds:时间已调整

5.3.4 手动强制同步

若时间偏差较大,等待自动同步较慢,可以手动强制同步。

停止 chronyd 服务:

bash
systemctl stop chronyd

手动同步:

bash
chronyd -q 'server ntp.aliyun.com iburst'

输出示例:

2026-08-13T02:23:45Z chronyd version 3.4 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +SECHASH +IPV6 +DEBUG)
2026-08-13T02:23:50Z System clock was stepped by 5.234567 seconds

重启 chronyd 服务:

bash
systemctl start chronyd

验证同步结果:

bash
chronyc tracking

5.4 配置 NTP 时间同步

5.4.1 安装 NTP

CentOS/RHEL:

bash
yum install -y ntp

Ubuntu/Debian:

bash
apt-get install -y ntp

5.4.2 配置 NTP

编辑配置文件:

bash
vi /etc/ntp.conf

配置示例:

conf
# 禁用默认服务器
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
# server 3.centos.pool.ntp.org iburst

# 配置国内 NTP 服务器
server ntp.aliyun.com iburst
server time1.cloud.tencent.com iburst
server ntp.ntsc.ac.cn iburst
server pool.ntp.org iburst

# 允许本地时钟作为备用时间源
server 127.127.1.0
fudge 127.127.1.0 stratum 10

# 限制访问控制
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1

# 允许哪些客户端查询时间(若本机作为 NTP 服务器)
# restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# 时钟偏差记录文件
driftfile /var/lib/ntp/drift

# 日志文件
logfile /var/log/ntp.log

配置项说明:

  • server:时间源,iburst 表示启动时快速同步
  • restrict:访问控制,default 限制所有外部访问
  • driftfile:记录时钟偏差
  • logfile:日志文件

5.4.3 启动 NTP 服务

bash
systemctl start ntpd
systemctl enable ntpd

验证服务状态:

bash
systemctl status ntpd

5.4.4 手动强制同步

停止 ntpd 服务:

bash
systemctl stop ntpd

手动同步:

bash
ntpdate ntp.aliyun.com

输出示例:

13 Aug 10:23:45 ntpdate[12345]: step time server 5.6.7.8 offset 5.234567 sec

重启 ntpd 服务:

bash
systemctl start ntpd

验证同步结果:

bash
ntpq -p

5.5 配置时区

5.5.1 查看当前时区

bash
timedatectl

bash
date +"%Z %z"

输出示例:

CST +0800

5.5.2 设置时区为中国上海

使用 timedatectl

bash
timedatectl set-timezone Asia/Shanghai

或手动创建软链接:

bash
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

验证:

bash
timedatectl

5.5.3 常用时区

  • 中国:Asia/Shanghai
  • 美国东部:America/New_York
  • 美国西部:America/Los_Angeles
  • 英国:Europe/London
  • 日本:Asia/Tokyo
  • UTC:UTC

查看所有可用时区:

bash
timedatectl list-timezones

5.6 同步系统时钟和硬件时钟

5.6.1 将系统时钟写入硬件时钟

bash
hwclock --systohc

bash
hwclock -w

验证:

bash
hwclock --show
date

5.6.2 将硬件时钟读取到系统时钟

bash
hwclock --hctosys

bash
hwclock -s

5.7 配置 systemd-timesyncd(轻量级时间同步)

systemd-timesyncd 是 systemd 提供的轻量级时间同步服务,适用于桌面或轻量级服务器。

5.7.1 启用 systemd-timesyncd

bash
systemctl start systemd-timesyncd
systemctl enable systemd-timesyncd

5.7.2 配置时间源

编辑配置文件:

bash
vi /etc/systemd/timesyncd.conf

配置示例:

ini
[Time]
NTP=ntp.aliyun.com time1.cloud.tencent.com ntp.ntsc.ac.cn
FallbackNTP=pool.ntp.org

重启服务:

bash
systemctl restart systemd-timesyncd

验证:

bash
timedatectl status

输出示例:

               Local time: 三 2026-08-13 10:23:45 CST
           Universal time: 三 2026-08-13 02:23:45 UTC
                 RTC time: 三 2026-08-13 02:23:45
                Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

查看同步状态:

bash
timedatectl timesync-status

输出示例:

       Server: 5.6.7.8 (ntp.aliyun.com)
Poll interval: 32s (min: 32s; max 34min 8s)
         Leap: normal
      Version: 4
      Stratum: 2
    Reference: GPS
    Precision: 1us (-24)
Root distance: 12.345ms (max: 5s)
       Offset: +123us
        Delay: 12.345ms
       Jitter: 234us
 Packet count: 8

5.8 虚拟化环境时间同步

5.8.1 VMware 虚拟机

VMware Tools 提供时间同步功能,可能与 NTP/Chrony 冲突。

检查 VMware Tools 时间同步是否启用:

bash
vmware-toolbox-cmd timesync status

禁用 VMware Tools 时间同步:

bash
vmware-toolbox-cmd timesync disable

编辑虚拟机配置文件(需要在 ESXi 主机或 vCenter 上操作):

tools.syncTime = "FALSE"
time.synchronize.continue = "FALSE"
time.synchronize.restore = "FALSE"
time.synchronize.resume.disk = "FALSE"
time.synchronize.shrink = "FALSE"
time.synchronize.tools.startup = "FALSE"
time.synchronize.tools.enable = "FALSE"
time.synchronize.resume.host = "FALSE"

5.8.2 KVM/QEMU 虚拟机

确保虚拟机使用 kvm-clock 时钟源:

bash
cat /sys/devices/system/clocksource/clocksource0/current_clocksource

输出应为:

kvm-clock

若不是,手动设置:

bash
echo"kvm-clock" > /sys/devices/system/clocksource/clocksource0/current_clocksource

持久化配置(编辑 grub 配置):

bash
vi /etc/default/grub

添加内核参数:

GRUB_CMDLINE_LINUX="... clocksource=kvm-clock"

更新 grub:

bash
grub2-mkconfig -o /boot/grub2/grub.cfg

重启系统。

5.8.3 Docker 容器

Docker 容器使用宿主机时间,无需单独配置 NTP。

确保宿主机时间准确即可。

5.8.4 Kubernetes Pod

Kubernetes Pod 使用宿主机时间,无需单独配置 NTP。

确保所有 Kubernetes 节点时间同步。

5.9 配置 NTP 服务器(内网时间源)

若内网无法访问外网 NTP 服务器,可以配置内网 NTP 服务器。

5.9.1 选择一台服务器作为 NTP 服务器

假设 192.168.1.10 作为 NTP 服务器,该服务器可以访问外网。

配置 Chrony:

bash
vi /etc/chrony.conf

配置示例:

conf
# 时间源(外网)
server ntp.aliyun.com iburst
server time1.cloud.tencent.com iburst

# 允许内网客户端查询时间
allow 192.168.1.0/24

# 本地时间源(当网络不可达时)
local stratum 10

makestep 1.0 3
driftfile /var/lib/chrony/drift
logdir /var/log/chrony

重启服务:

bash
systemctl restart chronyd

开放防火墙端口(NTP 使用 UDP 123):

bash
firewall-cmd --permanent --add-service=ntp
firewall-cmd --reload

或使用 iptables:

bash
iptables -A INPUT -p udp --dport 123 -j ACCEPT

5.9.2 配置内网客户端

其他服务器配置 Chrony,时间源指向内网 NTP 服务器:

bash
vi /etc/chrony.conf

配置示例:

conf
# 时间源(内网 NTP 服务器)
server 192.168.1.10 iburst

makestep 1.0 3
driftfile /var/lib/chrony/drift
logdir /var/log/chrony

重启服务:

bash
systemctl restart chronyd

验证同步:

bash
chronyc sources

输出应显示内网 NTP 服务器。

六、常用命令汇总

6.1 查看时间

bash
# 查看系统时间
date
date"+%Y-%m-%d %H:%M:%S"

# 查看硬件时钟
hwclock --show
hwclock -r

# 查看时区和同步状态
timedatectl
timedatectl status

6.2 Chrony 命令

bash
# 查看同步状态
chronyc tracking
chronyc sources
chronyc sourcestats

# 手动强制同步
chronyd -q 'server ntp.aliyun.com iburst'

# 服务管理
systemctl status chronyd
systemctl start chronyd
systemctl stop chronyd
systemctl restart chronyd
systemctl enable chronyd

6.3 NTP 命令

bash
# 查看同步状态
ntpq -p
ntpstat

# 手动强制同步
ntpdate ntp.aliyun.com

# 服务管理
systemctl status ntpd
systemctl start ntpd
systemctl stop ntpd
systemctl restart ntpd
systemctl enable ntpd

6.4 时区命令

bash
# 查看时区
timedatectl
date +"%Z %z"

# 设置时区
timedatectl set-timezone Asia/Shanghai

# 查看所有可用时区
timedatectl list-timezones

6.5 系统时钟与硬件时钟同步

bash
# 系统时钟 -> 硬件时钟
hwclock --systohc
hwclock -w

# 硬件时钟 -> 系统时钟
hwclock --hctosys
hwclock -s

6.6 手动设置时间

bash
# 设置系统时间
date -s "2026-08-13 10:23:45"

# 或使用 timedatectl
timedatectl set-time "2026-08-13 10:23:45"

# 同步到硬件时钟
hwclock --systohc

风险提示:

  • 手动设置时间会导致时间跳变,可能影响业务
  • 手动设置后应立即配置 NTP/Chrony,避免时间再次漂移

七、配置示例

7.1 Chrony 完整配置示例

/etc/chrony.conf

conf
# 时间源配置
server ntp.aliyun.com iburst
server time1.cloud.tencent.com iburst
server ntp.ntsc.ac.cn iburst
server pool.ntp.org iburst

# 本地时间源(备用)
local stratum 10

# 允许大幅度调整时间
makestep 1.0 3

# 时钟偏差记录
driftfile /var/lib/chrony/drift

# 允许客户端查询时间(若作为 NTP 服务器)
allow 192.168.1.0/24

# RTC 同步
rtcsync

# 日志目录
logdir /var/log/chrony

# 日志记录
log measurements statistics tracking

7.2 NTP 完整配置示例

/etc/ntp.conf

conf
# 时间源配置
server ntp.aliyun.com iburst
server time1.cloud.tencent.com iburst
server ntp.ntsc.ac.cn iburst
server pool.ntp.org iburst

# 本地时钟作为备用
server 127.127.1.0
fudge 127.127.1.0 stratum 10

# 访问控制
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1

# 允许客户端查询时间(若作为 NTP 服务器)
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# 时钟偏差记录
driftfile /var/lib/ntp/drift

# 日志文件
logfile /var/log/ntp.log

# 统计信息
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

7.3 systemd-timesyncd 配置示例

/etc/systemd/timesyncd.conf

ini
[Time]
NTP=ntp.aliyun.com time1.cloud.tencent.com ntp.ntsc.ac.cn
FallbackNTP=pool.ntp.org
RootDistanceMaxSec=5
PollIntervalMinSec=32
PollIntervalMaxSec=2048

7.4 /etc/fstab 挂载时间相关文件系统

确保 /etc/fstab 中未将文件系统挂载为 noatime(会影响时间戳):

bash
# 错误示例
/dev/sda1  /data  ext4  defaults,noatime  0 0

# 正确示例
/dev/sda1  /data  ext4  defaults,relatime  0 0

八、日志与指标观察方法

8.1 查看 Chrony 日志

bash
journalctl -u chronyd -f

bash
tail -f /var/log/chrony/measurements.log
tail -f /var/log/chrony/statistics.log
tail -f /var/log/chrony/tracking.log

8.2 查看 NTP 日志

bash
journalctl -u ntpd -f

bash
tail -f /var/log/ntp.log

8.3 查看系统日志

bash
dmesg | grep -i "time\|clock\|ntp\|chrony"
bash
grep -i "time\|clock\|ntp\|chrony" /var/log/messages | tail -n 50

8.4 监控时间偏差

Prometheus 监控时间偏差(需要 Node Exporter):

promql
node_timex_offset_seconds

查询时间同步状态:

promql
node_timex_sync_status

设置告警规则:

yaml
groups:
-name:time_sync
rules:
-alert:TimeNotSynchronized
expr:node_timex_sync_status!=1
for:5m
labels:
severity:warning
annotations:
summary:"Time not synchronized on {{ $labels.instance }}"
description:"NTP sync status is {{ $value }}"

-alert:TimeOffsetTooLarge
expr:abs(node_timex_offset_seconds)>0.05
for:5m
labels:
severity:warning
annotations:
summary:"Time offset too large on {{ $labels.instance }}"
description:"Time offset is {{ $value }} seconds"

8.5 定期检查时间偏差

编写脚本定期检查多台服务器时间偏差:

bash
#!/bin/bash
# check_time_sync.sh

SERVERS="server1 server2 server3 server4"
REF_TIME=$(date +%s)
MAX_OFFSET=5

for server in$SERVERSdo
  SERVER_TIME=$(ssh $server"date +%s" 2>/dev/null)
if [ $? -eq 0 ]; then
    OFFSET=$((SERVER_TIME - REF_TIME))
    ABS_OFFSET=${OFFSET#-}
if [ $ABS_OFFSET -gt $MAX_OFFSET ]; then
echo"WARNING: $server time offset is $OFFSET seconds"
else
echo"OK: $server time offset is $OFFSET seconds"
fi
else
echo"ERROR: Cannot connect to $server"
fi
done

配置 cron 定期执行:

bash
crontab -e

添加:

0 * * * * /root/scripts/check_time_sync.sh >> /var/log/time_sync_check.log 2>&1

九、排查路径

1. 发现时间相关问题(日志错乱、认证失败、监控异常)
   ↓
2. 检查系统时间和时区
   ↓
3. 检查硬件时钟
   ↓
4. 检查多台服务器时间差
   ↓
5. 若时间偏差较大:
   - 检查 NTP/Chrony 服务是否运行
   - 检查配置文件是否正确
   - 检查时间源是否可达
   - 检查防火墙是否阻止 NTP 端口
   ↓
6. 若服务未运行:
   - 启动服务
   - 配置开机自启
   ↓
7. 若服务运行但未同步:
   - 检查时间源配置
   - 检查网络连通性
   - 检查防火墙规则
   - 手动强制同步
   ↓
8. 若是虚拟化环境:
   - 检查虚拟化平台时间同步配置
   - 禁用虚拟化平台时间同步,使用 NTP/Chrony
   ↓
9. 验证时间同步是否正常
   ↓
10. 配置监控告警
   ↓
11. 记录问题和处理过程

十、风险提醒

10.1 时间突变风险

  • 大幅度调整时间可能导致应用异常、数据库事务失败、日志错乱
  • 时间回退可能导致定时任务重复执行
  • 时间快进可能导致定时任务跳过执行
  • 建议使用 makestep 配置,仅在启动时大幅度调整,运行中缓慢调整

10.2 时区配置风险

  • 错误的时区配置可能导致应用显示时间错误
  • 修改时区后需要重启应用使其生效
  • 数据库时区与系统时区不一致可能导致数据错误

10.3 NTP/Chrony 冲突

  • 不要同时运行 ntpd 和 chronyd
  • 虚拟化平台时间同步可能与 NTP/Chrony 冲突
  • systemd-timesyncd 与 chronyd/ntpd 冲突

10.4 防火墙阻止

  • NTP 使用 UDP 123 端口,防火墙可能阻止
  • 云服务器安全组可能阻止 NTP 流量
  • 配置前检查网络连通性

10.5 时间源不可达

  • 公共 NTP 服务器可能被墙或限速
  • 内网环境无法访问外网 NTP 服务器
  • 建议配置多个时间源,增加冗余

10.6 虚拟化环境特殊风险

  • 虚拟机时间同步依赖宿主机
  • 虚拟化平台时间同步与 NTP/Chrony 冲突
  • 虚拟机暂停/恢复可能导致时间跳变

十一、验证方式

11.1 验证时间同步状态

Chrony:

bash
chronyc tracking
chronyc sources

NTP:

bash
ntpq -p
ntpstat

确认:

  • NTP synchronized: yes
  • 时间偏差接近 0
  • 时间源状态正常

11.2 验证多台服务器时间一致

bash
for host in server1 server2 server3; do
echo -n "$host: "
  ssh $host"date '+%Y-%m-%d %H:%M:%S.%N'"
done

确认时间偏差在 1 秒以内。

11.3 验证时区配置

bash
timedatectl

确认 Time zone 正确。

11.4 验证硬件时钟

bash
hwclock --show
date

确认硬件时钟和系统时钟一致。

11.5 验证业务是否恢复

  • 检查业务日志时间戳是否正常
  • 检查监控数据是否正常
  • 检查认证是否成功
  • 检查定时任务是否正常执行

十二、回滚方案

12.1 恢复原时间源配置

若新配置的时间源有问题:

bash
vi /etc/chrony.conf
# 恢复原配置
systemctl restart chronyd

12.2 恢复原时区

bash
timedatectl set-timezone <原时区>

bash
ln -sf /usr/share/zoneinfo/<原时区> /etc/localtime

12.3 停止 NTP/Chrony 服务

若时间同步导致问题:

bash
systemctl stop chronyd
systemctl disable chronyd

手动设置时间:

bash
date -s "2026-08-13 10:23:45"
hwclock --systohc

风险提示:

  • 停止时间同步后,时间会持续漂移
  • 仅作为临时应急措施

12.4 重启服务器

若时间问题导致系统异常:

bash
reboot

重启后检查时间和 NTP/Chrony 状态。

十三、生产环境注意事项

13.1 操作前准备

  • 通知相关人员,说明操作内容和可能影响
  • 确认当前时间和时区
  • 确认业务对时间敏感程度
  • 准备回滚方案
  • 选择业务低峰期操作

13.2 操作中监控

  • 实时观察时间变化
  • 实时观察业务日志
  • 实时观察监控数据
  • 准备好回滚命令

13.3 操作后验证

  • 验证时间同步状态
  • 验证时区配置
  • 验证业务是否正常
  • 持续观察一段时间,确认无异常

13.4 文档与记录

  • 记录操作时间、操作人、操作命令
  • 记录修改前后的配置
  • 记录遇到的问题和解决方法
  • 更新运维文档

13.5 预防措施

  • 建立时间同步监控告警
  • 定期检查时间偏差
  • 配置多个时间源,增加冗余
  • 内网部署 NTP 服务器
  • 统一所有服务器时区
  • 定期检查 NTP/Chrony 服务状态
  • 虚拟化环境禁用虚拟化平台时间同步
  • 文档化时间同步配置

十四、常见问题处理

14.1 chronyd 服务启动失败

检查配置文件语法:

bash
chronyd -d

查看错误日志:

bash
journalctl -u chronyd -xe

常见错误:

  • 配置文件语法错误
  • 端口被占用(ntpd 与 chronyd 冲突)
  • 权限问题

14.2 时间源不可达

检查网络连通性:

bash
ping -c 4 ntp.aliyun.com

检查 DNS 解析:

bash
nslookup ntp.aliyun.com

检查防火墙:

bash
telnet ntp.aliyun.com 123

或使用 nc

bash
nc -u -v ntp.aliyun.com 123

检查时间源状态:

bash
chronyc sources -v

若所有时间源都不可达,检查:

  • 网络连接
  • DNS 配置
  • 防火墙规则
  • 安全组配置(云服务器)

14.3 时间偏差过大,无法同步

chrony 默认拒绝同步偏差超过 1000 秒的时间(除非配置了 makestep)。

手动强制同步:

bash
systemctl stop chronyd
chronyd -q 'server ntp.aliyun.com iburst'
systemctl start chronyd

或直接设置时间:

bash
systemctl stop chronyd
ntpdate ntp.aliyun.com
systemctl start chronyd

14.4 虚拟机时间频繁漂移

原因:

  • 虚拟化平台时间同步与 NTP/Chrony 冲突
  • 虚拟机 CPU 调度不均导致时钟漂移

解决:

  • 禁用虚拟化平台时间同步
  • 使用 kvm-clock(KVM)或 VMware Tools 时间同步(VMware)
  • 增加 NTP/Chrony 同步频率

14.5 Docker 容器时间不同步

Docker 容器使用宿主机时间,容器内无法修改时间。

解决:

  • 确保宿主机时间准确
  • 重启容器使其同步宿主机时间
bash
docker restart <container_id>

14.6 时区显示错误

应用显示时间与系统时间不一致,可能是应用时区配置问题。

检查应用时区配置:

Java 应用:

bash
-Duser.timezone=Asia/Shanghai

Python 应用:

python
import os
os.environ['TZ'] = 'Asia/Shanghai'

Node.js 应用:

bash
TZ=Asia/Shanghai node app.js

14.7 ntpd 与 chronyd 冲突

不要同时运行 ntpd 和 chronyd。

停止 ntpd:

bash
systemctl stop ntpd
systemctl disable ntpd

启动 chronyd:

bash
systemctl start chronyd
systemctl enable chronyd

14.8 systemd-timesyncd 与 chronyd 冲突

停止 systemd-timesyncd:

bash
systemctl stop systemd-timesyncd
systemctl disable systemd-timesyncd

启动 chronyd:

bash
systemctl start chronyd
systemctl enable chronyd

十五、总结

服务器时间不同步是分布式系统中容易被忽视但影响严重的问题,会导致日志混乱、监控错位、认证失败、数据库异常、定时任务错乱等。

核心流程:

  1. 检查系统时间、硬件时钟、时区
  2. 检查 NTP/Chrony 服务状态
  3. 配置时间源
  4. 启动时间同步服务
  5. 验证同步状态
  6. 配置监控告警

关键要点:

  • 时间偏差超过 5 秒就可能影响业务
  • 使用 Chrony 而非 NTP(CentOS 7+/Ubuntu 18.04+)
  • 配置多个时间源,增加冗余
  • 内网环境部署内网 NTP 服务器
  • 统一所有服务器时区(建议 Asia/Shanghai 或 UTC)
  • 虚拟化环境禁用虚拟化平台时间同步
  • 大幅度调整时间可能导致业务异常,建议配置 makestep 仅在启动时调整
  • 定期检查时间偏差,配置监控告警

常见场景:

  • 新服务器未配置 NTP/Chrony:安装并配置
  • 时间源不可达:更换时间源或配置内网 NTP 服务器
  • 虚拟机时间漂移:禁用虚拟化平台时间同步,使用 NTP/Chrony
  • 时间偏差过大:手动强制同步
  • Docker 容器时间不同步:确保宿主机时间准确
  • 时区配置错误:设置正确时区

风险控制:

  • 大幅度调整时间前通知相关人员
  • 选择业务低峰期操作
  • 准备回滚方案
  • 操作后充分验证

预防机制:

  • 建立时间同步监控告警
  • 定期检查时间偏差
  • 标准化时间同步配置
  • 文档化时间同步流程
  • 新服务器初始化时配置时间同步

通过本文的完整流程,可以系统化地解决服务器时间不同步问题,确保分布式系统的稳定性和数据一致性。

文末福利

今天给大家分享一份超级牛掰的Linux学习笔记,足足有1456页!是一位Linux运维大佬整理分享的,分享是获得大佬同意的,大家有需要的尽管收藏起来!

笔记介绍

这份笔记非常全面且详细,从Linux基础到shell脚本,再到防火墙、数据库、日志服务管理、Nginx、高可用集群、Redis、虚拟化、Docker等等,与其说Linux学习笔记,不如说是涵盖了运维各个核心知识。

并且图文并茂,代码清晰,每一章下面都有更具体详细的内容,十分适合Linux运维学习参考!

笔记展示

笔记下载

扫描下方二维码,回复暗号1456页Linux笔记“,即可100%免费领取成功

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-08-21 13:38:35 HTTP/2.0 GET : https://f.mffb.com.cn/a/510391.html
  2. 运行时间 : 0.521930s [ 吞吐率:1.92req/s ] 内存消耗:4,561.78kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=2538cb21cb4f35a64ae33aa209d924f2
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000707s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.001333s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.033389s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.057446s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.001838s ]
  6. SELECT * FROM `set` [ RunTime:0.001814s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.001523s ]
  8. SELECT * FROM `article` WHERE `id` = 510391 LIMIT 1 [ RunTime:0.105426s ]
  9. UPDATE `article` SET `lasttime` = 1787290715 WHERE `id` = 510391 [ RunTime:0.068769s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 67 LIMIT 1 [ RunTime:0.003847s ]
  11. SELECT * FROM `article` WHERE `id` < 510391 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.015302s ]
  12. SELECT * FROM `article` WHERE `id` > 510391 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.005020s ]
  13. SELECT * FROM `article` WHERE `id` < 510391 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.012009s ]
  14. SELECT * FROM `article` WHERE `id` < 510391 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.027217s ]
  15. SELECT * FROM `article` WHERE `id` < 510391 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.030759s ]
0.526750s