优化Ubuntu Apache内存使用可从以下方面入手:
mod_ssl、mod_php),仅保留核心模块。MaxClients:根据服务器内存和单个进程占用量设置,避免过多进程占用内存。MaxRequestsPerChild:设置合理值(如1000-5000),防止内存泄漏。KeepAlive:低并发场景设为Off,高并发设为On并调整KeepAliveTimeout(建议5-15秒)和MaxKeepAliveRequests(如100)。StartServers、MinSpareServers、MaxSpareServers:根据负载调整,避免空闲进程过多。mod_expires缓存静态资源,减少重复请求。mod_deflate压缩传输数据,降低带宽占用。prefork切换至event或worker模式,减少内存消耗。vm.swappiness设为较低值(如10),减少交换空间使用。sudo sync && echo 3 > /proc/sys/vm/drop_caches。top、htop监控内存使用,定位异常进程。systemctl reload apache2重载配置。参考来源: