温馨提示×

怎么监控debian lnmp

小樊
36
2026-09-04 22:18:47
栏目: 智能运维

Debian + LNMP(Linux + Nginx + MySQL/MariaDB + PHP) 环境下,监控通常分为 系统层、服务层、应用层。下面给你一套从简单到专业的可落地方案。


一、最基础:系统自带命令(适合临时排查)

1. 系统资源

top / htop
free -h
df -h
iostat -x 1

2. 服务状态

systemctl status nginx
systemctl status mysql
systemctl status php8.2-fpm

二、LNMP 各组件专项监控

1. Nginx 监控

开启 status 模块

server {
    location /nginx_status {
        stub_status on;
        allow 127.0.0.1;
        deny all;
    }
}

查看:

curl http://127.0.0.1/nginx_status

关注指标:

  • Active connections
  • Requests per second
  • 4xx / 5xx 错误率

2. MySQL / MariaDB 监控

SHOW STATUS LIKE 'Threads_%';
SHOW PROCESSLIST;
SHOW GLOBAL STATUS;

慢查询:

SHOW VARIABLES LIKE 'slow_query%';

3. PHP-FPM 监控

systemctl status php8.2-fpm

开启 status:

pm.status_path = /status

Nginx 中:

location ~ ^/(status)$ {
    fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}

三、日志监控(非常重要)

Nginx

tail -f /var/log/nginx/access.log
tail -f /var/log/nginx/error.log

MySQL

tail -f /var/log/mysql/error.log

自动分析工具

goaccess access.log

四、轻量级监控方案(推荐)

方案 1:Netdata(最强实时)

bash <(curl -Ss https://my-netdata.io/kickstart.sh)

✅ 自动监控 CPU、内存、Nginx、MySQL、PHP
✅ Web 界面,零配置


方案 2:Prometheus + Grafana(生产级)

组件:

  • node_exporter(系统)
  • nginx-prometheus-exporter
  • mysqld_exporter
  • php-fpm exporter

适合:

  • 多服务器
  • 长期趋势
  • 报警

五、告警方案

简单

  • fail2ban(防爆破)
  • logwatch(每日邮件)

专业

  • Prometheus + Alertmanager
  • Zabbix

六、我该选哪种?

场景 推荐
个人服务器 Netdata
小公司 Netdata + 日志
生产环境 Prometheus + Grafana
多台服务器 Zabbix / Prometheus

如果你愿意,可以告诉我:

  • Debian 版本
  • Nginx / PHP / MySQL 版本
  • 是个人博客还是生产业务

我可以直接帮你 写一套完整监控配置

0