在 CentOS + LAMP(Linux + Apache + MySQL/MariaDB + PHP) 环境下,监控通常从 系统层、服务层、应用层 三个维度来做。下面给你一套实用可落地的方案,从简单到专业。
一、基础监控(命令行,适合临时/日常)
1. 系统资源
top / htop
free -h
df -h
iostat -x 1
安装 htop:
yum install epel-release -y
yum install htop -y
2. Apache 监控
systemctl status httpd
apachectl status
查看连接数:
netstat -an | grep :80 | wc -l
Apache 状态页(推荐开启):
vim /etc/httpd/conf.d/status.conf
SetHandler server-status
Require local
访问:http://localhost/server-status
3. MySQL / MariaDB 监控
systemctl status mariadb
mysqladmin status
mysqladmin processlist
慢查询:
SHOW PROCESSLIST;
SHOW GLOBAL STATUS LIKE 'Slow_queries';
4. PHP 监控
- 查看 PHP 错误日志:
tail -f /var/log/php-fpm/error.log
tail -f /var/log/httpd/error_log
二、日志监控(最重要)
1. 核心日志位置
- Apache:
/var/log/httpd/ - MySQL:
/var/log/mariadb/ - PHP:
/var/log/php-fpm/ - 系统:
/var/log/messages
2. 实时查看
tail -f /var/log/httpd/access_log
tail -f /var/log/httpd/error_log
三、自动化监控(推荐生产环境)
方案 1:Zabbix(企业级,最常用)
✅ 适合 CentOS LAMP 生产环境
监控内容:
- CPU / 内存 / 磁盘
- Apache 状态
- MySQL 状态
- PHP-FPM
- 自定义告警
部署简述:
yum install zabbix-server zabbix-agent httpd php -y
网页配置 + Agent 上报
方案 2:Prometheus + Grafana(现代方案)
✅ 适合容器化 / 云环境
组件:
- node_exporter(系统)
- mysqld_exporter(MySQL)
- apache_exporter(Apache)
- Grafana 可视化
方案 3:轻量级(Netdata)
✅ 一行命令,实时图表
bash <(curl -Ss https://my-netdata.io/kickstart.sh)
访问:http://IP:19999
四、告警机制(必须)
- 邮件:
mailx - 微信 / 钉钉:Zabbix / 脚本
- 短信:第三方 API
五、LAMP 常见监控指标(重点)
| 项目 | 指标 |
|---|---|
| Apache | 并发连接、请求数、5xx |
| MySQL | 连接数、慢查询、QPS |
| PHP | 内存、执行时间、错误 |
| 系统 | CPU、IO、内存、磁盘 |
六、如果你告诉我:
- CentOS 版本(7 / 8 / Stream)
- 是否生产环境
- Apache 还是 Nginx
- 是否允许装监控软件
我可以 直接给你一套可复制的监控部署命令。