如何将Apache配置为仅派生一个子进程/工人? [英] How do I configure Apache to only fork one child process/worker?

查看:120
本文介绍了如何将Apache配置为仅派生一个子进程/工人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望启动apache,以便它派生一个子进程. (我正在分析一个模块.我知道-X标志,)

I wish to launch apache so it forks one child process. (I'm profiling a module. I know about the -X flag,)

根据文档

两个指令对活动子进程的数量设置了硬性限制 以及子进程中的服务器线程数,并且只能是 通过完全停止服务器然后重新启动来进行更改. ServerLimit是活动子进程数的硬限制,并且必须大于或等于MaxClients 指令除以ThreadsPerChild指令. ThreadLimit是一个 服务器线程数的硬限制,并且必须大于 或等于ThreadsPerChild指令.如果非默认值是 这些指令指定的指令,它们应该出现在其他工作程序之前 指令.

Two directives set hard limits on the number of active child processes and the number of server threads in a child process, and can only be changed by fully stopping the server and then starting it again. ServerLimit is a hard limit on the number of active child processes, and must be greater than or equal to the MaxClients directive divided by the ThreadsPerChild directive. ThreadLimit is a hard limit of the number of server threads, and must be greater than or equal to the ThreadsPerChild directive. If non-default values are specified for these directives, they should appear before other worker directives.

我尝试将设置设置为:

<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>

重新启动后,我仍然得到四个进程.

When I restart, I still get four processes.

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标志,我仍然会得到三个进程.

Oddly, if I use the -X flag, I still get three processes.

/usr/sbin/httpd -X -f/etc/httpd/conf/httpd.conf

/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的进程请求.

You should get two process, the first one is owned by root, binds the 80 port, manage child[ren], the second is the one answering the http request.

尝试使用ps auxf,您应该会得到类似的内容:

Try with ps auxf you should get something like:

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等).

Now, browsing the web, it seems that sometimes a second root process is spawned, maybe because of one specific module loaded in Apache that requires that.If you really want to track that you'll have to remove modules, remove advanced things (like SSl certificates, RewriteLock, etc).

您还可以在每个进程上尝试使用lsof -p PID进行差异检查.

You can also try a lsof -p PID on each process the check for differences.

以下是此行为的其他示例:

Here are some other examples of this behavior:

  • https://serverfault.com/questions/310764/why-apache-child-process-runs-as-root
  • Multiple apache root processes
  • https://superuser.com/questions/511841/multiple-apache-root-processes

但是没有人对此有真正的答案.

But nobody has a real answer to that.

还检查当前使用的是哪个mpm(prefork,worker,event?)

Check also which mpm is currently used (prefork, worker, event?)

这篇关于如何将Apache配置为仅派生一个子进程/工人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆