apache2:mpmconfiguration

经过几个像“CRITICAL – 负载平均:135.12,92.20,49.09”和OOM杀手的nagios消息,我用不同的设置一次又一次地检查了configuration,但没有成功。

唯一的解决办法,似乎有助于Ubuntu的盒子,这是更清洁的cronjob:

[ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2>/dev/null \; -delete

阅读oom-killer信息,告诉我有关apache2是不好的(父母)过程。 这个虚拟服务器上只有很less的stream量,几乎没有任何高峰。

lscpu

架构:x86_64

CPU操作模式:32位,64位

字节顺序:Little Endian

CPU(s):1

免费-m

Mem:2003 835 1168 0 18 381

– / + buffers / cache:435 1568

交换:1019 129 890

apache2.conf mpm

 <IfModule mpm_prefork_module> StartServers 2 MinSpareServers 2 MaxSpareServers 10 MaxClients 150 MaxRequestsPerChild 10000 </IfModule> <IfModule mpm_worker_module> StartServers 2 MinSpareThreads 25 MaxSpareThreads 75 KeepAliveTimeout 15 ThreadLimit 64 ThreadsPerChild 25 MaxClients 100 MaxRequestsPerChild 10000 </IfModule> <IfModule mpm_event_module> StartServers 2 MinSpareThreads 25 MaxSpareThreads 75 ThreadLimit 64 ThreadsPerChild 25 MaxClients 100 MaxRequestsPerChild 10000 </IfModule> 

是不是有像apache的mysql_tuner.sh或类似的vps有用的例子?

谢谢

你正在分配内存 – OOM意味着“内存不足” – 高负载平均值将是机器交换的结果。

您不需要调整脚本来知道使用什么合适的设置。 启动Apache,然后查看单个线程的RAM使用情况。 通常,对于PHP应用程序,预计大约30MB。 然后,你可以开始计算出你可以运行多less个线程。

你可能会发现你在应用程序级(PHP最大内存或MySQL)分配内存,而不是Apache线程本身的数量; 只是这是应用程序的边缘使用。

目前来说,要保守一点,然后努力工作。 因此,降低设置为这样的事情:

 StartServers 1 MinSpareServers 1 MaxSpareServers 10 MaxClients 15 MaxRequestsPerChild 1500 

然后降低你所有的MySQL内存设置,或者至less减less连接的数量(约15)。 并降低所有的PHP最大。 内存设置。

内存使用脚本

这是我为内存使用而编写的一个小脚本,但请记住,它不会正确考虑共享库等。

只需创build一个新文件,

例如。 /root/memory_usage.sh

然后运行应用程序名称,

例如。 /root/memory_usage.sh apache2 /root/memory_usage.sh mysqld

 #!/bin/bash grandtotal=0 if [ $# -lt 1 ];then echo "$0: invalid option" echo "You are missing required arguments" echo "1 Application name or 'all', 2 2nd application name (optional)" exit 0 fi if [[ "$1" == "all" ]]; then tot=0;for i in `ps -e -orss=`;do tot=$(( $tot + $i )); done; echo "Total " $(( $tot /4096 )) "MB" exit fi for app in $@; do echo -n $app ps u -p $(pidof $app) | awk 'NR > 1 {nm += $5} END {print " Total: " nm/1024 " MB"}' apptotal=`ps -e -orss=,args= | grep "$app" | awk 'NR > 0 {nm += $1} END {print nm}'` echo "$app Total: " $(( $apptotal / 4096 )) "MB" grandtotal=$(( $apptotal + $grandtotal )) done if [ $# -gt 1 ];then echo "Grand total: " $(( $grandtotal / 4096 )) "MB" fi