监控 Linux + LNMP(Linux + Nginx + MySQL/MariaDB + PHP) 可以从 系统层、服务层、应用层 三个维度来做。下面给你一套实用、可落地的监控方案,从简单到专业。
查看 CPU、内存、磁盘、网络:
top
htop
free -h
df -h
iostat -x 1
vmstat 1
安装 htop / iotop:
yum install htop iotop -y # CentOS
apt install htop iotop -y # Ubuntu
编辑 nginx 配置:
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
关键指标:
mysqladmin status
mysql -e "SHOW PROCESSLIST;"
mysql -e "SHOW GLOBAL STATUS LIKE 'Threads%';"
SHOW VARIABLES LIKE 'slow_query_log';
SHOW VARIABLES LIKE 'long_query_time';
开启慢日志:
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 1
pm.status_path = /status
Nginx:
location ~ ^/(status)$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
查看:
curl http://127.0.0.1/status
关注:
tail -f /var/log/nginx/error.log
tail -f /var/log/php-fpm/error.log
tail -f /var/log/mysql/error.log
grep "500" /var/log/nginx/access.log | wc -l
监控内容:
优点:
组件:
效果:
netdata
安装:
bash <(curl -Ss https://my-netdata.io/kickstart.sh)
打开:
http://服务器IP:19999
✅ 零配置,秒级监控
| 场景 | 推荐 |
|---|---|
| 个人 / 小站 | netdata |
| 中小企业 | Zabbix |
| 技术团队 | Prometheus + Grafana |
| 云服务器 | 云监控 + 自定义脚本 |
你可以告诉我:
我可以直接给你 完整配置教程。