监控 Linux 下的 LNMP(Linux + Nginx + MySQL/MariaDB + PHP) 环境,通常分为 系统层、服务层、应用层、日志层 四个维度。下面我按“用什么监控 + 怎么监控 + 常用命令/工具”给你一个实用方案。
top / htop
free -h
df -h
iostat -x 1
iftop
bash <(curl -Ss https://my-netdata.io/kickstart.sh)
访问:http://IP:19999
server {
listen 80;
server_name localhost;
location /nginx_status {
stub_status on;
allow 127.0.0.1;
deny all;
}
}
查看:
curl http://127.0.0.1/nginx_status
指标说明:
tail -f /var/log/nginx/access.log
awk '{print $1}' access.log | sort | uniq -c | sort -nr | head
mysqladmin status
mysqladmin extended-status
SHOW VARIABLES LIKE 'slow_query%';
SHOW PROCESSLIST;
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
goaccess /var/log/nginx/access.log -o report.html
✅ 小项目
Netdata + GoAccess
✅ 中型网站
Prometheus + Grafana + Exporter
✅ 大型 / 生产环境
Zabbix / PMM / ELK
如果你愿意,我可以:
你现在是 学习 / 生产 / 排查问题?