监控Ubuntu LAMP运行状态可从系统资源、服务状态、网络及应用层面入手,以下是具体方法及工具:
top/htop
:实时查看CPU、内存、进程占用情况,htop
界面更友好,需安装。vmstat
:监控虚拟内存、CPU使用率等,安装sysstat
包后使用。iostat
:查看磁盘I/O性能,属于sysstat
工具集。df/du
:检查磁盘空间使用情况,du
可查看指定目录占用。systemctl
命令查看Apache、MySQL等服务状态:systemctl status apache2
、systemctl status mysql
。netstat
或ss
命令检查服务端口(如80、3306)是否正常监听:sudo netstat -tuln | grep -E ':(80|3306)'
。mod_status
模块,访问http://服务器IP/server-status
查看请求状态。sudo tail -f /var/log/mysql/mysql-slow.log
。pm.max_children
等参数以适配服务器资源。psutil
库)定期检测资源使用率,超阈值时发送邮件报警。sudo tail -f /var/log/apache2/error.log
、sudo tail -f /var/log/mysql/error.log
。通过以上方法,可全面掌握Ubuntu LAMP环境的运行状态,及时发现并处理性能瓶颈或故障。