program story

아파치를 시작하고 내 컴퓨터를 계속 죽일 때 많은 아파치 프로세스가 생성되는 것을 어떻게 방지 할 수 있습니까?

inputbox 2021. 1. 8. 08:10
반응형

아파치를 시작하고 내 컴퓨터를 계속 죽일 때 많은 아파치 프로세스가 생성되는 것을 어떻게 방지 할 수 있습니까?


한 데비안 컴퓨터에 트래픽이 많은 응용 프로그램이 있고 아파치가 이상하게 작동하기 시작했습니다.

아파치를 시작할 때마다 수많은 아파치 프로세스가 생성되고 앱이 전혀로드되지 않으며 매우 빠르게 전체 시스템이 정지되고 재부팅을 위해 전원을 껐다가 켜야합니다.

아파치를 시작한 직후에 내가 얻는 것은 다음과 같습니다.

top-20:14:44 up 1:16, 2 users, load average : 0.48, 0.10, 0.03
작업 : 총 330 개, 실행 중 5 개, 수면 325 개, 중지 0 개, 좀비 0 개
CPU : 12.0 % us, 21.4 % sy, 0.0 % ni, 65.7 % id, 0.2 % wa, 0.1 % hi, 0.7 % si, 0.0 % st
메모리 : 총 8179920k, 404984k 사용, 7774936k 사용 가능, 60716k 버퍼
스왑 : 총 2097136k, 0k 사용, 2097136k 무료, 43424k 캐시


10251 www-data 150 467m 8100 4016 S 6 0.1 0 : 00.04 apache2
10262 www-data 150 467m 8092 4012 S 6 0.1 0 : 00.05 apache2
10360 www-data 15 0468m 8296 4016 S 6 0.1 0 : 00.05 apache2
10428 www-data 15 0468m 8272 3992 S 6 0.1 0 : 00.05 apache2
10241 www-data 150 467m 8256 4012 S4 0.1 0 : 00.03 apache2
10259 www-data 150 467m 8092 4012 S4 0.1 0 : 00.04 apache2
10274 www-data 150 467m 8056 4012 S4 0.1 0 : 00.03 apache2
10291 www-data 15 0468m 8292 4012 S4 0.1 0 : 00.03 apache2
10293 www-data 15 0468m 8292 4012 S4 0.1 0 : 00.03 apache2
10308 www-data 15 0 468m 8296 4016 S4 0.1 0 : 00.02 apache2
10317 www-data 150468m 8292 4012 S4 0.1 0 : 00.02 apache2
10320 www-data 15 0468m 8292 4012 S4 0.1 0 : 00.04 apache2
10325 www-data 15 0468m 8292 4012 S4 0.1 0 : 00.04 apache2

그리고 더 많은 apache2 프로세스와 함께 ..

1 분도 채 안되어 부하가 0.48에서 2.17로 감소한 것을 아래에서 확인할 수 있습니다. 이 시점에서 아파치를 멈추지 않으면 기계가 죽을 때까지 몇 분 이내에 부하가 계속 증가합니다.

top-20:15:34 up 1:17, 2 명의 사용자,로드 평균 : 2.17, 0.62, 0.21
작업 : 총 1850 개, 실행 5 개, 잠자기 1845 개, 중지 0 개, 좀비 0 개
CPU : 0.3 % us, 2.1 % sy, 0.0 % ni, 96.4 % id, 0.0 % wa, 0.1 % hi, 1.0 % si, 0.0 % st
메모리 : 총 8179920k, 사용 1938524k, 사용 가능한 6241396k, 버퍼 60860k
스왑 : 총 2097136k, 0k 사용, 2097136k 무료, 44196k 캐시

우리는 우리 사이트에 접근 할 수있는 주소를 허용하는 방화벽을 가지고 있습니다.

문제가 무엇인지에 대한 아이디어는 매우 환영합니다.

감사!


아마도 모든 램보다 훨씬 더 많이 사용하도록 Apache를 구성하는 오류를 범했을 것입니다. 이것은 만들기 쉬운 실수입니다.

Prefork Apache와 in-process 애플리케이션 서버 (예 : PHP 또는 mod_perl)를 사용하고 있다고 가정합니다. 이 모델에서는 최대 (MaxClients * 프로세스 당 애플리케이션의 최대 메모리 사용량) 메모리가 사용됩니다. 그다지 많지 않다면 하나, 다른 하나 또는 둘 다를 줄일 때입니다.

일반적으로 이것은 서버에 대처할 충분한 RAM이있는 지점까지 MaxClients를 줄이는 것을 의미합니다.

일반적으로 MaxClients에 사용되는 기본값 (150이 일반적 임)은 Prefork 모델을 사용하는 경우 겸손한 시스템에서 처리중인 무거운 애플리케이션 서버를 실행하는 데 적합하지 않습니다 (대부분의 애플리케이션 서버는 사용을 지원하지 않거나 권장하지 않습니다. 스레드 모델).

그러나 MaxClients를 줄이면 응용 프로그램을 사용할 수 없게됩니다. 특히 킵 얼라이브가 켜져 있고 킵 얼라이브 시간 초과가 너무 긴 경우 더욱 그렇습니다. 연결을 유지하는 프로세스 (서버 상태의 K 상태)는 여전히 많은 RAM을 사용하며 문제가 될 수 있습니다. 연결 유지 제한 시간을 최소화하거나 모두 끄십시오.

(mod_status에서 제공하는) 서버 상태를 주시해야합니다.

물론 결과를 이해하는 경우에만 이러한 변경을 수행해야합니다. 두 번 생각하고 구성을 한 번 변경하십시오. 유사한 사양의 비 프로덕션 머신에서 시뮬레이션 된로드로 변경 사항을 테스트 할 수있는 능력이 있다면 그렇게하십시오.


ps -aux 사용 | grep apache를 사용하여 apache가 실행중인 프로세스 수를 확인합니다. 각 프로세스에서 사용하는 메모리 추정치를 제공하는 "RSS"열을 찾으십시오. 또는 "top"을 사용할 수 있습니다. 여기서 Shift + f를 누른 다음 % MEM 열을 선택하여 메모리 사용량별로 프로세스를 정렬 할 수 있습니다.

프로세스 수는 apache.conf 파일의 "MaxClients"지시문에 의해 결정됩니다. 이 그림을 보는 방법은 이 페이지에 설명되어 있습니다 .

  1. 루트로 서버에 SSH를 사용합니다.
  2. 런 탑.
  3. Shift + m을 누릅니다.
  4. httpd에서 사용하는 가장 높은 RES 메모리에 유의하십시오.
  5. 상단을 종료하려면 Q를 누르십시오.
  6. 실행 : service httpd stop (데비안에서, sudo service apache2 stop)
  7. httpd가 중지되면 다음을 실행합니다. free -m
  8. "사용됨"아래에 나열된 메모리를 확인합니다.
  9. Find the guaranteed memory for your VPS plan. Support can tell you how much you have guaranteed if you cannot find it.
  10. Subtract the memory USED from the memory that your plan is GUARANTEED. This will give you your base FREE MEMORY POOL.
  11. Multiply the value of your FREE MEMORY POOL by 0.8 to find your average AVAILABLE APACHE POOL (this will allow you a 20% memory reserve for burst periods).
  12. Divide your AVAILABLE APACHE POOL by the highest RES memory used by httpd. This will give you the MaxClients value that should be set for your system. (Round it to the nearest integer less than this value if it has a fraction component.)

The right value for "MaxClients" will ensure the right memory allocation for your apache server. That's how I solved it.

In Debian, apache conf file is at /etc/apache2/apache2.conf


Have you changed your configuration file recently? If yes, I trust you keep the old version for diffing?

If not, search for the "StartServers", "MaxSpareServers" and "MinSpareServers" directives. Generally you want to leave these at defaults, but it's possible that they were intentionally set high (bad idea) or accidentally set that way due to a bad config edit.

If this doesn't help, it's time to look outside Apache, for some process that's opening connections at a fast rate (could be that there's a testing process that's run amok).

First step is the access log. Second step is to run netstat, to see where the connections might be coming from. And if it's running on the same system, you can look in /proc/*/fd to find the two ends of the connection.


This question is ancient, but I feel compelled to add an answer here because all of the existing answers are overlooking a key piece of information from the OP: After the load has begun to rise for a few minutes, top reports that there are still ample CPU & memory resources available. There is usually one culprit remaining, and that's I/O.

Check if there is a full partition with df -h. If not, see if your application is thrashing the disk using vmstat 1 10 or iostat 1 10 (these are provided by the 'sysstat' package on Debian/Ubuntu). If you still don't see an issue there, perhaps you have device level I/O errors or network trouble for network-mounted storage. Check the system and daemon log files.


As has been said (assuming Prefork Apache) - MaxClients = max processes at once.

If you find you are getting hammered with real traffic (and not a mis-configured StartServers/Min/MaxSpareServers), there are some other things you can do:

  1. Set up a separate, lightweight apache process (or lighttpd) for your static content. That way all the small, static stuff doesn't "pollute" your heavy-weight app process. This can be on the same server, or a different one. Doesn't matter.
  2. Put a reverse proxy like Squid in front of your Apache process. The reverse proxy will quickly suck down the content from Apache and store it in memory and then parcel it back out to the client. This way AOL users on 14.4kb modems don't hog one of your valuable Apache slots. As a bonus, such a setup can be configured to cache some of your content to reduce the load on your Apache processes.

Your 'top' output shows that you have plenty of free memory, so I don't think that MaxClients is an issue (unless there is some problem with Apache allocating more than 2GB of memory?) Your error log should show errors if it is having problems creating more children.

Most likely, your Apache processes really are using a lot of resources. If you are running PHP apps, try installing eAccelerator which does a good job of optimizing and caching PHP code. Other things might include heavy MySQL queries, a slow DNS resolver, etc. Beyond that, it gets more into understanding what programs are being hit and what they are doing.

ReferenceURL : https://stackoverflow.com/questions/501205/how-can-i-prevent-tons-of-apache-processes-spawning-when-i-start-apache-and-proc

반응형