我有一个Debian 10服务器运行Apache2 2.4.38。最近,我替换了所有配置的HTTPS vhost使用的SSL证书文件,并运行了systemctl reload apache2.service,它通过systemd单元文件运行/usr/sbin/apachectl graceful。
根据Apache 2的文档,
USR1或优美信号使父进程通知子进程在其当前请求后退出(如果其子进程没有提供任何服务,则立即退出)。父文件重新读取其配置文件并重新打开其日志文件。当每个子节点死掉时,父级将替换为新一代配置中的一个子级,该子代将立即开始处理新请求。
在繁忙的服务器上,替换子进程的延迟会发生,这是可以理解的。然而,今天我注意到服务器很少仍会使用旧的、预替换的SSL证书进行响应。我去看了一下这些过程:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 13559 0.0 0.2 15640 10356 ? Ss 2022 18:53 /usr/sbin/apache2 -k start
www-data 16834 0.7 0.6 1232452 27780 ? Sl 06:00 3:47 /usr/sbin/apache2 -k start
www-data 17415 0.9 0.6 1231844 26532 ? Sl 10:22 2:32 /usr/sbin/apache2 -k start
www-data 17552 0.7 0.6 1231736 26376 ? Sl 10:53 1:47 /usr/sbin/apache2 -k start
www-data 17612 0.6 0.6 1232000 26840 ? Sl 10:54 1:34 /usr/sbin/apache2 -k start
www-data 17641 0.6 0.5 1231980 22732 ? Sl 10:54 1:36 /usr/sbin/apache2 -k start
www-data 17642 0.8 0.6 1231848 24728 ? Sl 10:54 1:59 /usr/sbin/apache2 -k start
www-data 26704 0.5 0.6 1232216 24748 ? Sl Jan18 89:53 /usr/sbin/apache2 -k start列表中的最后一个进程在START和TIME列上表现得非常突出。我在1月24日运行了reload命令,但是现在,六天后,这个进程还在继续。不过,服务器对请求的响应很好--目前还不清楚这个工作人员是否确实在处理新请求,但其他的则是。
服务器配置非常简单,默认不包括在这里(就目前而言--如果您需要任何特定信息,请询问)。它唯一有趣的特性是它正在运行mod_jk,即各种VirtualHost指令都有JkMount /* workername (在/etc/libasache2-mod-jk/workers.properties中定义了workername )。mod_jk使用ajp13连接到运行Tomcat的两个负载平衡应用程序服务器之一。
这不是我们第一次遇到一个卡住的Apache2工作人员,但我从来没有能够确定其最终结果的原因。这可能与mod_jk和(非常)遗留的Java应用程序有关,可能有一些请求在Java/mod_jk级别引起了罕见的边缘情况错误,并且阻止了工作人员通过USR1信号退出。Java应用程序日志并不在我的控制范围之内;它们非常冗长,包含无意义的信息,经常缺少时间戳,而且对于故障排除来说几乎毫无用处,除非您碰巧在错误发生的那一刻查看了它们。
我将不得不做一个不优雅的重新启动,即使它会导致轻微的生产中断,但我会感兴趣的进一步的方法调试这个问题在未来,以便我们可以让工人总是可靠地执行一个优雅的重新启动时,需要。我们怎样才能更好地分析是什么使一个工人陷入这样的困境呢?
apachectl -V的结果:
Server version: Apache/2.4.38 (Debian)
Server built: 2021-12-21T16:50:43
Server's Module Magic Number: 20120211:84
Server loaded: APR 1.6.5, APR-UTIL 1.6.1
Compiled using: APR 1.6.5, APR-UTIL 1.6.1
Architecture: 64-bit
Server MPM: event
threaded: yes (fixed thread count)
forked: yes (variable process count)
Server compiled with....
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT="/etc/apache2"
-D SUEXEC_BIN="/usr/lib/apache2/suexec"
-D DEFAULT_PIDLOG="/var/run/apache2.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="mime.types"
-D SERVER_CONFIG_FILE="apache2.conf"具有生产子域的apachectl -S被编辑:
VirtualHost configuration:
*:443 is a NameVirtualHost
default server vhost1.domain.example (/etc/apache2/sites-enabled/00_vhost1.domain.example-ssl.conf:2)
port 443 namevhost vhost1.domain.example (/etc/apache2/sites-enabled/00_vhost1.domain.example-ssl.conf:2)
port 443 namevhost vhost2.domain.example (/etc/apache2/sites-enabled/01_vhost2.domain.example-ssl.conf:2)
port 443 namevhost vhost3.domain.example (/etc/apache2/sites-enabled/02_vhost3.domain.example-ssl.conf:2)
port 443 namevhost vhost4.domain.example (/etc/apache2/sites-enabled/03_vhost4.domain.example-ssl.conf:2)
alias alias1.domain.example
*:80 is a NameVirtualHost
default server vhost1.domain.example (/etc/apache2/sites-enabled/00_vhost1.domain.example.conf:1)
port 80 namevhost vhost1.domain.example (/etc/apache2/sites-enabled/00_vhost1.domain.example.conf:1)
port 80 namevhost vhost2.domain.example (/etc/apache2/sites-enabled/01_vhost2.domain.example.conf:1)
alias 172.16.33.63
port 80 namevhost vhost3.domain.example (/etc/apache2/sites-enabled/02_vhost3.domain.example.conf:1)
port 80 namevhost vhost4.domain.example (/etc/apache2/sites-enabled/03_vhost4.domain.example.conf:1)
alias alias1.domain.example
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33发布于 2023-01-31 21:09:51
第三方模块存在一些问题,使得httpd无法优雅地重新启动子进程,甚至导致服务器无法响应。
我对mod_weblogic (mod_wl_24.so)也有类似的行为,还有一些人报告说与mod_security有相似之处。曾试图解决第三方模块中这些假定的错误行为。
例如,2.4.4X对此有几个修复程序。我会尝试升级到至少2.4.49及以上,然后再试一次。检查https://downloads.apache.org/httpd/CHANGES_2.4并查找"mpm_event“。
In 2.4.49
*) mpm_event: Fix children processes possibly not stopped on graceful
restart. PR 63169. [Joel Self <joelself gmail.com>]
*) mpm_event: Fix graceful stop/restart of children processes if connections
are in lingering close for too long. [Yann Ylavic]
In 2.4.47
*) mpm_event: Don't reset connections after lingering close, restoring prior
to 2.4.28 behaviour. [Yann Ylavic]如果您不能立即升级,也有可能使用mod_proxy_ajp获得更好的结果。
因此,简单地说,答案是:如果使用第三方模块,请尝试将版本升级到至少2.4.49。
在此之前,我忘记提到“紧紧抓住”的解决办法,直到您可以升级或更改模块,也就是说,强制httpd永远不会优雅地重新启动任何子进程。多么?
使MaxSpareThreads具有与MaxRequestWorkers相同的值。并且MaxConnectionsPerChild 0允许无限连接,这样httpd就不会试图优雅地关闭它们。
示例:
MaxSpareThreads 500
MaxRequestWorkers 500
MaxConnectionsPerChild 0不要发出优雅的重新启动(某些发行版称之为重新加载),只需重新启动或完全停止/启动即可。
https://serverfault.com/questions/1121502
复制相似问题