监控 Debian 上的 LNMP(Linux + Nginx + MySQL/MariaDB + PHP) 环境,通常可以从系统资源、服务状态、Web 服务、数据库、日志、告警几个层面来做。下面给你一套实用可落地的方案,从简单到进阶。
top
htop # 推荐,需安装
free -h # 内存
df -h # 磁盘
uptime # 负载
systemctl status nginx
systemctl status mysql
systemctl status php-fpm
批量检查:
for s in nginx mysql php-fpm; do systemctl is-active $s; done
编辑站点配置:
location /nginx_status {
stub_status on;
allow 127.0.0.1;
deny all;
}
访问:
curl http://127.0.0.1/nginx_status
可看到:
mysqladmin status
mysqladmin extended-status
SHOW PROCESSLIST;
SHOW STATUS LIKE 'Threads_connected';
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 1
/etc/php/*/fpm/pool.d/www.conf
pm.status_path = /status
Nginx 中:
location /status {
fastcgi_pass unix:/run/php/php-fpm.sock;
include fastcgi_params;
}
查看:
curl http://127.0.0.1/status
/var/log/nginx/access.log
/var/log/nginx/error.log
/var/log/mysql/error.log
/var/log/php-fpm.log
tail -f /var/log/nginx/error.log
grep -c "error" /var/log/nginx/error.log
bash <(curl -Ss https://my-netdata.io/kickstart.sh)
✅ 实时监控 CPU、内存、Nginx、MySQL、PHP
✅ 网页访问:http://IP:19999
组件:
适合:
df -h | awk '$5+0 > 80 {print $0}'
systemctl enable nginx
systemctl enable mysql
systemctl is-active nginx || echo "nginx down" | mail -s "alert" admin@xx.com
✅ htop
✅ nginx status
✅ php-fpm status
✅ mysqladmin status
✅ Netdata
✅ 日志 tail -f
如果你愿意,我可以:
你现在是学习 / 生产 / 云服务器?