Apache 因 OOM 而死亡

Apache 因 OOM 而死亡

我在 Ubuntu 22 上运行 apache2。我的 Apache2 经常因 OOM 而终止。我尝试获取日志,它显示了类似以下内容

> root@localhost:~# dmesg -e | grep -i kill [Mar15 03:00] shopping_cart
> invoked oom-killer:
> gfp_mask=0x1100dca(GFP_HIGHUSER_MOVABLE|__GFP_ZERO), order=0,
> oom_score_adj=0 [  +0.000004]  oom_kill_process.cold+0xb/0x10 [ 
> +0.000001] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/system.slice/apache2.service,task=shopping_cart,pid=1676,uid=33
> [  +0.000012] Out of memory: Killed process 1676 (shopping_cart)
> total-vm:2398524kB, anon-rss:1834584kB, file-rss:0kB, shmem-rss:0kB,
> UID:33 pgtables:4044kB oom_score_adj:0 [  +4.614029] changelog.k2
> invoked oom-killer:
> gfp_mask=0x1100dca(GFP_HIGHUSER_MOVABLE|__GFP_ZERO), order=0,
> oom_score_adj=0 [  +0.000003]  oom_kill_process.cold+0xb/0x10 [ 
> +0.000002] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/system.slice/apache2.service,task=changelog.k2,pid=6244,uid=33 [  +0.000016] Out of memory: Killed process 6244 (changelog.k2)
> total-vm:2398524kB, anon-rss:1856988kB, file-rss:0kB, shmem-rss:0kB,
> UID:33 pgtables:4048kB oom_score_adj:0

我对以上日志不太明白。

当我检查 apache2 被杀死时的状态时,我得到了这样的信息

root@localhost:~# sudo systemctl status apache2
× apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: failed (Result: oom-kill) since Wed 2023-03-15 03:00:07 UTC; 9min ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 620 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
    Process: 1746 ExecStop=/usr/sbin/apachectl graceful-stop (code=exited, status=0/SUCCESS)
   Main PID: 736 (code=exited, status=0/SUCCESS)
        CPU: 5min 4.064s

如果我重新启动 apache2,它会开始正常工作,但几分钟后,它再次被杀死

我已经尝试过 apache2buddy,它显示了类似这样的内容

--------------------------------------------------------------------------------
### GENERAL FINDINGS & RECOMMENDATIONS ###
--------------------------------------------------------------------------------
Apache2buddy.pl report for server: localhost (45.33.10.196):

Settings considered for this report:
[ !! ] *** LOW UPTIME ***.
[ @@ ] The following recommendations may be misleading - apache has been restarted within the last 24 hours.

        Your server's physical RAM:                                   3923 MB
        Remaining Memory after other services considered:             3923 MB
        Apache's MaxRequestWorkers directive:                         115      <--------- Current Setting
        Apache MPM Model:                                             prefork
        Largest Apache process (by memory):                           40 MB
[ !! ]  Your MaxRequestWorkers setting is too high.
        Your recommended MaxRequestWorkers setting (based on available memory) is between 87 and 97. <-- Acceptable Range (90-100% of Remaining RAM)
        Max potential memory usage:                                   4646 MB
        Percentage of TOTAL RAM allocated to Apache:                  118.43  %
        Percentage of REMAINING RAM allocated to Apache:              118.43  %
--------------------------------------------------------------------------------

我只改变了mode_prefork像这样

<IfModule mpm_prefork_module>
        StartServers              2
        MinSpareServers           5
        MaxSpareServers          10
        MaxRequestWorkers        115
        MaxConnectionsPerChild   0
</IfModule>

我认为这是内存不足导致的,但我不知道 apache 的哪个进程占用了太多内存,以及如何解决它。我试过了htop 和 free但它没有给我任何线索。

如果有人能帮助我解决这个难题,请告诉我。

谢谢!

相关内容