我希望启动 apache,以便它分叉一个子进程。 (我正在分析一个模块。我知道 -X 标志,)
根据文档
两个指令对活动子进程的数量设置了硬性限制
以及子进程中的服务器线程数,并且只能是
通过完全停止服务器然后再次启动来更改。ServerLimit 是对活动子进程数量的硬限制,并且必须大于或等于 MaxClients
指令除以 ThreadsPerChild 指令。线程限制是一个
服务器线程数的硬限制,并且必须大于
或等于 ThreadsPerChild 指令。如果非默认值是
为这些指令指定,它们应该出现在其他工作人员之前
指令。
我尝试将我的设置设置为:
<IfModule prefork.c>
StartServers 1
MinSpareServers 1
MaxSpareServers 1
ServerLimit 1
MaxClients 1
MaxRequestsPerChild 4000
</IfModule>
<IfModule worker.c>
StartServers 1
MaxClients 25
MinSpareThreads 25
MaxSpareThreads 25
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
当我重新启动时,我仍然得到四个进程。
root 17173 1 0 11:44 ? 00:00:00 /usr/sbin/httpd -k start
root 17205 17173 0 11:46 ? 00:00:00 /usr/sbin/httpd -k start
apache 17206 17173 0 11:46 ? 00:00:00 /usr/sbin/httpd -k start
apache 17207 17173 0 11:46 ? 00:00:00 /usr/sbin/httpd -k start
我究竟做错了什么?
奇怪的是,如果我使用 -X 标志,我仍然会得到三个进程。
/usr/sbin/httpd -X -f /etc/httpd/conf/httpd.conf
apache 17224 4097 1 11:51 pts/1 00:00:00 /usr/sbin/httpd -X -f /etc/httpd/conf/httpd.conf
root 17226 17224 0 11:51 pts/1 00:00:00 /usr/sbin/httpd -X -f /etc/httpd/conf/httpd.conf
apache 17227 17224 0 11:51 pts/1 00:00:00 /usr/sbin/httpd -X -f /etc/httpd/conf/httpd.conf
你应该得到两个进程,第一个是 root 拥有的,绑定 80 端口,管理 child[ren],第二个是应答 http 请求的进程。
尝试用ps auxf
你应该得到类似的东西:
ps auxf | grep httpd | grep -v 'grep'
root 16955 0.0 0.2 275440 17996 ? Ss 13:50 0:00 /usr/sbin/httpd -X -f /etc/httpd/conf/httpd.conf
www-data 16987 0.0 0.1 275472 7620 ? S 13:50 0:00 \_ /usr/sbin/httpd -X -f /etc/httpd/conf/httpd.conf
现在,浏览网页,似乎有时会生成第二个根进程,可能是因为 Apache 中加载的一个特定模块需要它。如果您真的想跟踪它,则必须删除模块,删除高级的东西(例如SSL 证书、RewriteLock 等)。
您还可以尝试lsof -p PID
在每个过程中检查差异。
以下是此行为的一些其他示例:
- https://serverfault.com/questions/310764/why-apache-child-process-runs-as-root https://serverfault.com/questions/310764/why-apache-child-process-runs-as-root
- 多个 apache 根进程 https://stackoverflow.com/questions/13631459/multiple-apache-root-processes
- https://superuser.com/questions/511841/multiple-apache-root-processes https://superuser.com/questions/511841/multiple-apache-root-processes
但没有人对此有真正的答案。
还检查当前使用哪个 mpm(prefork、worker、event?)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)