Ubuntu 上 LNMP 监控实操指南
一 快速巡检与系统指标
#!/usr/bin/env bash
set -e
echo "=== 服务状态 ==="
systemctl is-active --quiet nginx && echo "Nginx: active" || echo "Nginx: inactive"
systemctl is-active --quiet mysql && echo "MySQL: active" || echo "MySQL: inactive"
systemctl is-active --quiet php-fpm && echo "PHP-FPM: active" || echo "PHP-FPM: inactive"
echo "=== 端口监听 ==="
ss -tulpen | egrep '(:80|:443|:3306)'
echo "=== 近期错误日志 ==="
tail -n50 /var/log/nginx/error.log /var/log/mysql/error.log /var/log/php-fpm/error.log 2>/dev/null | sed 's/^/ /'
以上命令与路径覆盖了 Ubuntu 上 LNMP 的常用巡检与系统级监控要点,适合作为日常排障与值守基线。二 组件级监控要点
location /nginx_status {
stub_status on;
allow 127.0.0.1;
deny all;
}
重载:sudo systemctl reload nginx;访问:http://服务器IP/nginx_status三 可视化与告警方案
四 日志集中与 PHP 性能分析
五 告警阈值与日常巡检清单