先上代码
<IfModule mpm_prefork_module>
StartServers 10
MinSpareServers 10
MaxSpareServers 15
ServerLimit 2000
MaxClients 1000
MaxRequestsPerChild 10000
</IfModule>
我们部署项目一直是使用apache,最近两周以来两台服务器出现过好几次apache假死的情况。原本打算把mpm由prefork换成worker,但在第一台服务器上切换时出现了一点小错误,另外根据网上说prefork是目前最稳定的方式。所以先不打算换,而只优化一下prefork配置。
首先使用下行命令查看当前apache的运行模式
root@iZbp17avth9xef2vqlve84Z:/home/zhanghong# apachectl -V | grep -i mpm
Server MPM: prefork
root@iZbp17avth9xef2vqlve84Z:/home/zhanghong#
查看Apache可用MPM模式
root@iZbp17avth9xef2vqlve84Z:/home/zhanghong# ls /etc/apache2/mods-available/mpm*
/etc/apache2/mods-available/mpm_event.conf /etc/apache2/mods-available/mpm_prefork.conf /etc/apache2/mods-available/mpm_worker.conf
/etc/apache2/mods-available/mpm_event.load /etc/apache2/mods-available/mpm_prefork.load /etc/apache2/mods-available/mpm_worker.load
查看现在使用的MPM模式
root@iZbp17avth9xef2vqlve84Z:/home/zhanghong# ls -l /etc/apache2/mods-enabled/mpm*
lrwxrwxrwx 1 root root 34 Jul 14 17:19 /etc/apache2/mods-enabled/mpm_prefork.conf -> ../mods-available/mpm_prefork.conf
lrwxrwxrwx 1 root root 34 Jul 14 17:19 /etc/apache2/mods-enabled/mpm_prefork.load -> ../mods-available/mpm_prefork.load
把/etc/apache2/mods-enabled/mpm_prefork.conf文件改成开始讲的配置代码,然后重启apache。
参考
https://askubuntu.com/questions/524770/apache-enable-worker-mpm
http://blog.csdn.net/lestat1225/article/details/12872907
apache切换prefork到worker
http://blog.sina.com.cn/s/blog_4da051a60102vilw.html