在 Linux 里常说的“慢日志”通常有几种不同场景,下面按最常见三类给你一套定位思路和命令。
uptime
top
htop
关注:
iostat -x 1
重点关注:
%util 接近 100%await / svctm 很大free -h
vmstat 1
sar -u -r -d -n DEV 1 3
(需安装 sysstat)
SHOW VARIABLES LIKE 'slow_query_log';
SHOW VARIABLES LIKE 'slow_query_log_file';
SHOW VARIABLES LIKE 'long_query_time';
SET GLOBAL slow_query_log = ON;
SET GLOBAL long_query_time = 1;
tail -f /var/log/mysql/slow.log
mysqldumpslow -s t /var/log/mysql/slow.log
在 nginx.conf 中:
log_format main '$request_time $upstream_response_time $request';
access_log /var/log/nginx/access.log main;
查看慢请求:
awk '$1 > 1 {print}' /var/log/nginx/access.log
top # 谁占资源
iostat # 是否 IO 慢
netstat # 是否网络卡
dmesg # 是否有硬件/内核异常
journalctl -p err
如果你能告诉我:
我可以直接给你针对性的定位命令和排查流程。