在 Debian 上搭建或使用 LNMP(Linux + Nginx + MySQL/MariaDB + PHP) 时如果出现卡顿、响应慢、负载高,通常是配置、资源、或环境问题。下面按常见原因 → 排查方法 → 解决办法来讲。
top
htop
编辑:
/etc/nginx/nginx.conf
worker_processes auto;
worker_connections 1024;
改完:
nginx -t
systemctl restart nginx
location ~* \.(jpg|css|js|png)$ {
expires 7d;
}
/etc/php/*/fpm/pool.d/www.conf
关键参数:
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
查看:
ps aux | grep php-fpm
重启:
systemctl restart php8.2-fpm
slowlog = /var/log/php-fpm-slow.log
request_slowlog_timeout = 5s
然后看哪个 PHP 文件慢。
Debian 默认 MariaDB 可能吃内存。
编辑:
/etc/mysql/mariadb.conf.d/50-server.cnf
示例(低内存):
innodb_buffer_pool_size = 128M
max_connections = 50
重启:
systemctl restart mariadb
SHOW PROCESSLIST;
或开启慢日志:
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 1
free -h
swapon --show
没有就开:
fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
iostat -x 1
如果是 HDD + 高并发,基本必卡。
如果你用的是 lnmp.org 一键包:
建议:
./lnmp wp
或手动降配置
你可以直接贴:
top 截图或输出我可以直接告诉你改哪几个参数。