监控 Linux + LNMP(Linux + Nginx + MySQL/MariaDB + PHP) 可以从系统层、服务层、应用层三个维度来做。下面给你一套实用方案,从轻量到专业逐步递进。
top / htop
free -h
df -h
iostat -x 1
Nginx 状态模块(推荐开启)
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 | grep -E "Queries|Threads|Slow"
慢查询:
SHOW PROCESSLIST;
SHOW GLOBAL STATUS LIKE 'Slow_queries';
location /php_status {
fastcgi_pass unix:/run/php/php-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /status;
}
查看:
curl http://127.0.0.1/php_status
tail -f /var/log/nginx/access.log
tail -f /var/log/nginx/error.log
关注:
tail -f /var/log/mysql/slow.log
tail -f /var/log/php-fpm.log
监控项:
优点:
组件:
优点:
bash <(curl -Ss https://my-netdata.io/kickstart.sh)
告警指标示例:
✅ Nginx 是否 502/504
✅ PHP-FPM 进程是否够用
✅ MySQL 连接数是否打满
✅ 磁盘 IO 是否瓶颈
✅ 是否有慢查询
✅ 是否有异常 IP 攻击
如果你愿意,我可以:
你目前是 学习 / 单机 / 生产服务器?