我在 Ubuntu Server 22.04 上使用 Apache2 2.4.56。我安装了 PHP FPM 8.1,应该使用通过模块启用的 MPM Worker:
a2query -m
setenvif (enabled by maintainer script)
dir (enabled by maintainer script)
actions (enabled by unknown)
rewrite (enabled by unknown)
proxy_fcgi (enabled by site administrator)
autoindex (enabled by maintainer script)
authz_user (enabled by maintainer script)
slotmem_shm (enabled by unknown)
auth_basic (enabled by maintainer script)
authz_core (enabled by maintainer script)
authn_file (enabled by maintainer script)
proxy_balancer (enabled by unknown)
authz_groupfile (enabled by unknown)
access_compat (enabled by maintainer script)
proxy_html (enabled by unknown)
negotiation (enabled by maintainer script)
proxy_ajp (enabled by unknown)
cgi (enabled by unknown)
proxy_http (enabled by unknown)
authn_core (enabled by maintainer script)
xml2enc (enabled by unknown)
fcgid (enabled by maintainer script)
include (enabled by site administrator)
proxy_wstunnel (enabled by site administrator)
ssl (enabled by unknown)
env (enabled by maintainer script)
proxy (enabled by unknown)
http2 (enabled by site administrator)
filter (enabled by maintainer script)
reqtimeout (enabled by maintainer script)
proxy_connect (enabled by unknown)
socache_shmcb (enabled by unknown)
status (enabled by maintainer script)
mpm_worker (enabled by site administrator)
deflate (enabled by maintainer script)
authz_host (enabled by maintainer script)
headers (enabled by unknown)
mime (enabled by maintainer script)
alias (enabled by maintainer script)
一切都运行良好,但我做了一些 nextcloud 应用程序更新,并且开始在日志中收到此信息,然后我的系统将变得无法访问:
[Thu Mar 23 15:16:45.304069 2023] [core:notice] [pid 1188749:tid 139956863047552] AH00094: Command line: '/usr/sbin/apache2'
[Thu Mar 23 15:18:01.382967 2023] [mpm_worker:error] [pid 1188749:tid 139956863047552] AH00287: server is within MinSpareThreads of MaxRequestWorkers, consider raising the MaxRequestWorkers setting
[Thu Mar 23 15:18:22.408722 2023] [mpm_worker:error] [pid 1188749:tid 139956863047552] AH00286: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting
[Thu Mar 23 15:20:32.327642 2023] [mpm_worker:notice] [pid 1188749:tid 139956863047552] AH00296: caught SIGWINCH, shutting down gracefully
[Thu Mar 23 15:20:35.688071 2023] [core:warn] [pid 1188749:tid 139956863047552] AH00045: child process 1188751 still did not exit, sending a SIGTERM
我手动修改了 /etc/apache2/apache2.conf,将 ServerLimit 和 MaxRequestWorkers 设置为 256(这似乎比默认值 16 高很多),但这没有帮助,而且这种情况仍然发生。
我有点无法诊断这个问题?有没有办法解决产生这么多工作进程的问题?或者有没有办法证明设置没有被加载?(例如,我已将其从“ifmodule”块中删除,以确保它不会被忽略)。任何建议都是有用的,我谷歌搜索的大部分内容只是说“增加 MaxRequestWorkers 并设置 ServerLimit 以匹配”,但这没有帮助。
答案1
您不需要指定所有的 mpm 参数,但是您不能在线程 mpm(如 worker 或 event)中将 ServerLimit 设置为等于 MaxRequestWorkers,因为 ServerLimit 指的是子进程,而 MaxRequestWorkers 指的是最大 Worker 线程数。
也就是说,如果您有 5 台服务器,并且每个子服务器的线程数为 100,则总共可以有 500 个请求工作者。
将此视为针对平均到高流量的合理默认设置(取决于服务器的功能):
StartServers 1
ServerLimit 5
MinSpareThreads 100
MaxSpareThreads 300
ThreadsPerChild 100
ThreadLimit 100
MaxRequestWorkers 500
MaxConnectionsPerChild 100000000
PS:如果我是你,我真的会开始卸载不必要的模块,你展示的列表听起来像是你不会使用的默认模块的夸张列表。此外,在 2.4 中不要使用 2.2 指令,mod_access_compat 现在不应使用。
PS2:您显示的错误不是 Apache 崩溃,而是正常关闭 IIRC。
答案2
我读了更多内容,发现 mpm_event 可能比 mpm_worker 更适合我的用例。我曾尝试禁用 nextcloud(我认为这是问题所在),但问题仍然存在,因此我根据此处的建议,使用以下设置转换为 mpm_eventhttps://stackoverflow.com/a/64937518/1739616:
<IfModule mpm_event_module>
StartServers 4
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestWorkers 800
ServerLimit 32
MaxConnectionsPerChild 10000
</IfModule>
这有效;计算是“ServerLimit x ThreadsPerChild = MaxRequestWorkers”