优化Debian Apache内存使用可从以下方面入手:
查看内存使用情况
free -m命令查看系统内存占用。top或htop定位高内存进程。关闭非必要服务和进程
systemctl list-units --types service查看并关闭冗余服务。优化Apache配置
/etc/apache2/apache2.conf,合理设置StartServers、MinSpareServers、MaxRequestWorkers等参数,避免进程过多。
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 150
MaxConnectionsPerChild 1000
</IfModule>
mod_cache和mod_expires缓存静态资源。a2dismod禁用不需要的模块(如rewrite、autoindex)。调整内核参数
/etc/sysctl.conf,优化vm.swappiness(降低交换倾向,如设为10)。net.core.rmem_max和net.core.wmem_max)。使用轻量级方案
event MPM模块(需手动编译)。定期维护
sudo systemctl restart apache2。注意:修改配置前建议备份文件,测试环境优先验证调整效果。