在 Debian 上监控 LAMP(Linux + Apache + MySQL/MariaDB + PHP) 环境,通常分为系统层、Web 层、数据库层、应用层四部分。下面给你一套实用可落地的监控方案,从“轻量自查”到“专业监控”逐步进阶。
top / htop
安装 htop(更好用):
apt install htop
df -h
free -h
netstat -tunlp
ss -tunlp
journalctl -xe
tail -f /var/log/syslog
启用 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
tail -f /var/log/apache2/access.log
tail -f /var/log/apache2/error.log
ps aux | grep apache
netstat -an | grep :80 | wc -l
mysqladmin status
mysqladmin extended-status
编辑:
/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
SHOW PROCESSLIST;
SHOW STATUS LIKE 'Threads%';
tail -f /var/log/apache2/error.log
php.ini:
log_errors = On
error_log = /var/log/php_errors.log
systemctl status php8.2-fpm
状态页:
pm.status_path = /status
bash <(curl -Ss https://my-netdata.io/kickstart.sh)
浏览器访问:
http://服务器IP:19999
✅ 实时 CPU / 内存 / Apache / MySQL
组件:
适合:
适合:
可用:
✅ 个人 / 小项目:
htop + Apache status + Netdata
✅ 生产环境:
Prometheus + Grafana + Exporter
如果你愿意,我可以:
直接告诉我你的使用场景即可。