我刚刚安装了带有 Apache 的 CentOS 9,发现apachectl stop
需要很长时间才能完成(总是需要 1 分 30 秒)。
我真的不知道要看哪里,我没有看到停止时任何 CPU 绑定进程,并apachectl configtest
给了我一个“语法 OK”。
当我这样做时,watch "ps ax | grep httpd"
我看到一些过程很快就结束了,而 4 个过程却持续了很长时间。
在停止/启动之后,它又会再次加速。
更新
当我得到给我的kill
PID时systemctl status httpd
,它会停止得更快。
更新
我设置了mod_status
,它工作正常。但是,一旦运行apachectl stop
,状态页面就会停止工作。
更新
apachectl -M
没用,但httpd -M
确实有用。结果如下。
[user@host ~]$ httpd -M
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
access_compat_module (shared)
actions_module (shared)
alias_module (shared)
allowmethods_module (shared)
auth_basic_module (shared)
auth_digest_module (shared)
authn_anon_module (shared)
authn_core_module (shared)
authn_dbd_module (shared)
authn_dbm_module (shared)
authn_file_module (shared)
authn_socache_module (shared)
authz_core_module (shared)
authz_dbd_module (shared)
authz_dbm_module (shared)
authz_groupfile_module (shared)
authz_host_module (shared)
authz_owner_module (shared)
authz_user_module (shared)
autoindex_module (shared)
cache_module (shared)
cache_disk_module (shared)
cache_socache_module (shared)
data_module (shared)
dbd_module (shared)
deflate_module (shared)
dir_module (shared)
dumpio_module (shared)
echo_module (shared)
env_module (shared)
expires_module (shared)
ext_filter_module (shared)
filter_module (shared)
headers_module (shared)
include_module (shared)
info_module (shared)
log_config_module (shared)
logio_module (shared)
macro_module (shared)
mime_magic_module (shared)
mime_module (shared)
negotiation_module (shared)
remoteip_module (shared)
reqtimeout_module (shared)
request_module (shared)
rewrite_module (shared)
setenvif_module (shared)
slotmem_plain_module (shared)
slotmem_shm_module (shared)
socache_dbm_module (shared)
socache_memcache_module (shared)
socache_redis_module (shared)
socache_shmcb_module (shared)
status_module (shared)
substitute_module (shared)
suexec_module (shared)
unique_id_module (shared)
unixd_module (shared)
userdir_module (shared)
version_module (shared)
vhost_alias_module (shared)
watchdog_module (shared)
brotli_module (shared)
dav_module (shared)
dav_fs_module (shared)
dav_lock_module (shared)
lua_module (shared)
mpm_event_module (shared)
proxy_module (shared)
lbmethod_bybusyness_module (shared)
lbmethod_byrequests_module (shared)
lbmethod_bytraffic_module (shared)
lbmethod_heartbeat_module (shared)
proxy_ajp_module (shared)
proxy_balancer_module (shared)
proxy_connect_module (shared)
proxy_express_module (shared)
proxy_fcgi_module (shared)
proxy_fdpass_module (shared)
proxy_ftp_module (shared)
proxy_http_module (shared)
proxy_hcheck_module (shared)
proxy_scgi_module (shared)
proxy_uwsgi_module (shared)
proxy_wstunnel_module (shared)
ssl_module (shared)
systemd_module (shared)
cgid_module (shared)
fcgid_module (shared)
http2_module (shared)
proxy_http2_module (shared)
wsgi_module (shared)
答案1
(这开始是一条评论,但后来变得太大了)
是的,正如@vidarlo 所说,一些连接并没有被断开。
配置服务器状态 - 这将向您显示停止后仍在运行的内容。
检查 KeepAliveTimeout - 大多数情况下,默认的 5 秒太高了。
还要在日志中添加一些性能指标。如果您对服务质量很在意,那么您应该知道哪些事情耗费了很长时间(并修复任何未运行 websockets 的事情)。
假设您有强制更快关机的正当理由,那么请使用以下脚本替换关机机制:
- 添加 iptables 规则阻止与 httpd 的新连接
- 等待时间限制到期,定期检查连接数(FIN_WAIT2 中的连接数除外)
- 如果计时器到期,则 kill -TERM httpd 主进程(通常是 root 拥有的进程)
- 如果连接数为零,则终止 -WINCH 主进程(或正常停止)