温馨提示×

怎么监控debian lamp

小樊
38
2026-10-07 17:03:15
栏目: 智能运维

在 Debian 上监控 LAMP(Linux + Apache + MySQL/MariaDB + PHP) 环境,通常分为系统层、Web 层、数据库层、应用层四部分。下面给你一套实用可落地的监控方案,从“轻量自查”到“专业监控”逐步进阶。


一、基础系统监控(必须)

1. 实时查看

top / htop

安装 htop(更好用):

apt install htop

2. 磁盘 / 内存 / 网络

df -h
free -h
netstat -tunlp
ss -tunlp

3. 系统日志

journalctl -xe
tail -f /var/log/syslog

二、Apache 监控

1. Apache 状态页(推荐)

启用 status 模块:

a2enmod status

编辑:

/etc/apache2/mods-enabled/status.conf

示例:

<Location /server-status>
    SetHandler server-status
    Require ip 127.0.0.1
</Location>

访问:

http://localhost/server-status

2. Apache 日志

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

3. 进程数 & 连接数

ps aux | grep apache
netstat -an | grep :80 | wc -l

三、MySQL / MariaDB 监控

1. 内置状态

mysqladmin status
mysqladmin extended-status

2. 慢查询

编辑:

/etc/mysql/mariadb.conf.d/50-server.cnf

开启:

slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 1

3. 连接数

SHOW PROCESSLIST;
SHOW STATUS LIKE 'Threads%';

四、PHP 监控

1. PHP 错误日志

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

php.ini:

log_errors = On
error_log = /var/log/php_errors.log

2. PHP-FPM(如使用)

systemctl status php8.2-fpm

状态页:

pm.status_path = /status

五、自动化监控方案(推荐)

方案 1:Netdata(最简单)

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

浏览器访问:

http://服务器IP:19999

✅ 实时 CPU / 内存 / Apache / MySQL


方案 2:Prometheus + Grafana(专业)

组件:

  • node_exporter(系统)
  • apache_exporter
  • mysqld_exporter

适合:

  • 多服务器
  • 长期监控
  • 告警

方案 3:Zabbix(企业级)

适合:

  • 公司环境
  • 自动告警(邮件/微信)

六、告警(非常重要)

  • 磁盘 > 80%
  • Apache 5xx 错误
  • MySQL 连接数过高
  • PHP 致命错误

可用:

  • cron + mail
  • Prometheus Alertmanager
  • Zabbix

七、总结推荐组合

✅ 个人 / 小项目:
htop + Apache status + Netdata

✅ 生产环境:
Prometheus + Grafana + Exporter


如果你愿意,我可以:

  • 帮你只监控 Apache + MySQL
  • 给你一键监控脚本
  • 按你的 Debian 版本 / LAMP 版本定制配置

直接告诉我你的使用场景即可。

0 踩