在 Debian 上监控 LNMP(Linux + Nginx + MySQL/MariaDB + PHP),一般从 系统资源、服务状态、日志、性能 四个层面来做。下面给你一套常用且实用的监控方案,从“基础 → 进阶 → 自动化”逐步说明。
top
htop # 推荐(需安装)
安装 htop:
apt update
apt install htop
free -h
df -h
du -sh /*
iftop
安装:
apt install iftop
systemctl status nginx
nginx -t
systemctl status mariadb
mysqladmin status
systemctl status php-fpm
# 或
systemctl status php8.2-fpm
ss -lntp
netstat -lntp
LNMP 常见端口:
/var/log/nginx/access.log
/var/log/nginx/error.log
实时查看错误:
tail -f /var/log/nginx/error.log
/var/log/php8.2-fpm.log
查看慢日志(性能问题):
/var/log/php8.2-fpm-slow.log
/var/log/mysql/error.log
mysqladmin -u root -p processlist
mysqladmin -u root -p status
查看慢查询:
SHOW VARIABLES LIKE 'slow_query_log';
SHOW VARIABLES LIKE 'long_query_time';
/etc/php/8.2/fpm/pool.d/www.conf
pm.status_path = /php-fpm-status
Nginx 配置:
location /php-fpm-status {
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
include fastcgi_params;
}
访问:
http://IP/php-fpm-status
location /nginx-status {
stub_status;
allow 127.0.0.1;
deny all;
}
访问:
http://IP/nginx-status
监控内容:
安装:
apt install zabbix-server-mysql zabbix-frontend-php zabbix-agent
✅ 优点:功能强、告警完善
❌ 缺点:配置略复杂
✅ 优点:界面漂亮、可扩展
✅ 很适合 LNMP + 云服务器
示例:
#!/bin/bash
if ! systemctl is-active --quiet nginx; then
echo "Nginx down" | mail -s "ALERT" admin@domain.com
fi
配合 cron:
*/5 * * * * /root/check_lnmp.sh
| 场景 | 推荐 |
|---|---|
| 个人服务器 | htop + 日志 + 脚本 |
| 小公司 | Zabbix |
| 高并发网站 | Prometheus + Grafana |
| 云服务器 | 云监控 + 日志 |
你可以告诉我:
我可以直接给你 完整可复制的监控配置方案。