apache服务自动停止

1.问题: apache 服务自动停止
     2.原因:
      (1)过程: apache 处理用户请求时,apache 会产生子进程,当apache处理完用户请求之后,子进程将会被父进程终止,这时候子进程佔用的内存就会释放,如果再有访问请求,父进程会重新产生子进程进行处理。但是如果在apache配置文件中将apache 独立子进程能处理的请求数量设置为无穷时,如果子进程佔用了200~300M内存,占用的内存不会释放。导致内存溢出
因此,apache告诉服务器这个进程你要给停了,但是服务器又杀不掉子进程,进入了一个死循环,最后系统资源被耗光,apache进程挂掉,然后网站就无法访问了。
    
     (2)造成这种结果的原因是网页程序问题,也是服务器设置的问题。因为php某一些脚本存在内存泄露的代码段。而服务器设置的 :apache处理这些代码段的进程的处理请求数被设置为无穷0 。也就是说这些进程只有在apache重启或者服务器重启的情况下才会被kill,否则将一直运行下去,直到耗尽系统的最后一点资源(主要是内存),然后挂掉服务。
   3. 解决:
      在apache 配置文件 :  /usr/local/apache/conf/extra/httpd-mpm.conf 
      找到apache 独立子进程能处理的请求数量:“MaxRequestsPerChild”  参数:不能设置为0,最好设置为一个相对不大的数字,比如“50”    防止httpd进程有意外的内存泄露
      保存并退出,利用service httpd restart 重启apache服务,使配置生效。避免下次再次发生
以下是apache:  错误的   error.log
[Tue Oct 31 01:23:36 2017] [warn] child process 33831 still did not exit, sending a SIGTERM                    意思:子进程的33831仍然没有退出,发送一个SIGTERM
[Tue Oct 31 01:23:36 2017] [warn] child process 33832 still did not exit, sending a SIGTERM
[Tue Oct 31 01:23:38 2017] [error] child process 33828 still did not exit, sending a SIGKILL
[Tue Oct 31 01:23:38 2017] [error] child process 33829 still did not exit, sending a SIGKILL
[Tue Oct 31 01:23:38 2017] [error] child process 33830 still did not exit, sending a SIGKILL
[Tue Oct 31 01:23:38 2017] [error] child process 33831 still did not exit, sending a SIGKILL
[Tue Oct 31 01:23:38 2017] [error] child process 33832 still did not exit, sending a SIGKILL
[Tue Oct 31 01:23:39 2017] [error] could not make child process 33830 exit, attempting to continue anyway
[Tue Oct 31 01:23:39 2017] [error] could not make child process 33831 exit, attempting to continue anyway
[Tue Oct 31 01:23:39 2017] [error] could not make child process 33832 exit, attempting to continue anyway
[Tue Oct 31 01:23:39 2017] [notice] caught SIGTERM, shutting down
[Tue Oct 31 12:12:52 2017] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Tue Oct 31 12:12:52 2017] [notice] suEXEC mechanism enabled (wrapper: /usr/local/apache/bin/suexec)
[Tue Oct 31 12:12:52 2017] [notice] Digest: generating secret for digest authentication ...
[Tue Oct 31 12:12:52 2017] [notice] Digest: done
[Tue Oct 31 12:12:53 2017] [notice] Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/1.0.1 DAV/2 PHP/5.5.36 configured -- resuming normal operations
点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注