CentOS - 夜间特定时间 CPU 使用率高

Web*_*ons 5 centos cpu-usage sar

我有一个负载很小的 CentOS-5 服务器。“sar”命令的典型输出如下所示:

02:20:01 PM       CPU     %user     %nice   %system   %iowait    %steal     %idle
02:30:01 PM       all      0.63      0.00      1.23      0.31      0.00     97.84
02:40:01 PM       all      0.92      0.32      1.34      0.45      0.00     96.97
02:50:01 PM       all      0.76      0.00      0.93      0.77      0.00     97.54
03:00:01 PM       all      0.41      0.00      0.72      0.15      0.00     98.72
03:10:01 PM       all      0.78      0.32      1.49      1.83      0.00     95.58
03:20:01 PM       all      0.27      0.00      0.50      0.62      0.00     98.61
Run Code Online (Sandbox Code Playgroud)

但是,我观察到每天晚上 4 点 10 分,CPU 使用率非常高。除了一个月中的几天外,这种情况几乎每天晚上都会发生。“sar”命令显示如下:

03:00:01 AM       all      0.10      0.00      0.10      0.11      0.00     99.68
03:10:01 AM       all      0.08      0.32      0.18      0.21      0.00     99.21
03:20:01 AM       all      0.03      0.00      0.03      0.19      0.00     99.76
03:30:01 AM       all      0.01      0.00      0.02      0.06      0.00     99.91
03:40:02 AM       all      0.75      0.32      3.21     15.43      0.00     80.28
03:50:01 AM       all      0.95      0.00      3.43      9.25      0.00     86.36
04:00:01 AM       all      0.69      0.00      3.79      4.86      0.00     90.66
04:10:01 AM       all     22.38      0.54      4.47     30.92      0.00     41.69
04:20:01 AM       all      2.99      0.02      4.58      4.95      0.00     87.46
04:30:01 AM       all      0.34      0.00      0.61     13.22      0.00     85.83
04:40:01 AM       all      0.05      0.32      0.17      0.52      0.00     98.95
04:50:01 AM       all      0.22      0.00      0.36      0.11      0.00     99.32
05:00:01 AM       all      0.23      0.00      0.36      0.12      0.00     99.28
Run Code Online (Sandbox Code Playgroud)

我如何确定导致 CPU 使用率和 iowait 等出现峰值的原因。我检查了 /var/log/messages 但无法确定。那时没有其他 cron 作业或其他设置要运行的东西。由于这是在 %user 下显示的,我只能确定它是某个用户进程。我怎样才能准确地确定原因?

eww*_*ite 7

这是cron.daily脚本运行的时间...默认情况下,它每天凌晨 4:00 后运行。

/etc/crontabs

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily <-- THIS ONE!!
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
Run Code Online (Sandbox Code Playgroud)

而在/etc/cron.daily

罪魁祸首可能是您的mlocate.cron,它updatedb在某些系统上运行并且可能非常密集:

#!/bin/sh
nodevs=$(< /proc/filesystems awk '$1 == "nodev" { print $2 }')
renice +19 -p $$ >/dev/null 2>&1
/usr/bin/updatedb -f "$nodevs"
Run Code Online (Sandbox Code Playgroud)


Tom*_*ton 2

可能是一个 cron 作业 - 可能“ locatedb”正在更新?

添加您自己的“ps”一晚上的 cron 输出可能有助于发现罪魁祸首。