以下是Ubuntu Apache監控服務器狀態的常用方法及配置要點:
sudo systemctl status apache2 或 sudo apachectl status,顯示服務運行狀態及日志。sudo tail -f /var/log/apache2/error.log(錯誤日志)或 access.log(訪問日志)。htop(需安裝)查看CPU/內存占用,top、vmstat等查看系統整體負載。/etc/apache2/apache2.conf,確保包含 LoadModule status_module modules/mod_status.so,并設置 ExtendedStatus On。/etc/apache2/sites-available/000-default.conf)中添加:<Location "/server-status">
SetHandler server-status
Require ip 192.168.1.100 # 替換為允許訪問的IP(如服務器自身或監控服務器)
</Location>
重啟Apache:sudo systemctl restart apache2。http://服務器IP/server-status,可查看服務器負載、請求數等實時數據,添加 ?auto&refresh=5 可自動刷新。sudo apt-get install apachetop。crontab -e設置定期執行并發送郵件通知。mailx,在腳本中調用mailx發送狀態異常告警。注:生產環境中建議結合模塊監控(mod_status)與第三方工具,覆蓋性能、可用性及異常告警需求。