Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Apache2 is eating all my ram&swap [SOLVED]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
zark
n00b
n00b


Joined: 27 Mar 2004
Posts: 74
Location: Belgium

PostPosted: Mon Apr 18, 2005 6:34 pm    Post subject: Apache2 is eating all my ram&swap [SOLVED] Reply with quote

I'm having this recurrent issue with Apache2 on my gentoo server...

It's acting fine, then all of a sudden it starts taking ram and ram, then page memory increases .. until it can't run cgi anymore ...
if i do a /etc/init.d/apache2 stop and then i ps .. i see still LOTS of apache2 processes ... (and if i do a start it won't because port is still binded)

so i have to do a killall apache2 (4-5 times in a row) then i can start the service again ... and the whole thing is fine for another 4 days ..

this happens almost twice a week (mrtg graphs show a pattern)


apache2 config was the default ( talking about that MPM stuff), i changed the settings (turned down) but the problem persists ... seems like it opens threads but don't close them :s


Last edited by zark on Fri May 20, 2005 12:38 pm; edited 1 time in total
Back to top
View user's profile Send private message
SilverOne
Apprentice
Apprentice


Joined: 10 Nov 2003
Posts: 161

PostPosted: Mon Apr 18, 2005 7:04 pm    Post subject: Reply with quote

Perhaps you're the victim of a (D)DOS attack?

Do your MRTG graphs show number of connections to Apache? Is there a significant increase in connections just before the "crash"?
Back to top
View user's profile Send private message
zark
n00b
n00b


Joined: 27 Mar 2004
Posts: 74
Location: Belgium

PostPosted: Mon Apr 18, 2005 7:19 pm    Post subject: Reply with quote

I thought about a DOS attack too ... but i kind of doubt it considering the 'regularity' in which it occurs ...

also the last time it happened (i installed mod_watch last thursday), on saturday, i saw it started happening before our daily traffic increased (our traffic comes 90% from europe, so its always 16h-20h). But why didn't it do that the day before ... the amount of hits are very similar....

i'm really without a clue .... and since this is production server, and we have around 10websites hosted on it ... i'm not really wanting to switch back to 1.3 (though i think about it more and more everyday)

Also.. it's not a SUDDEN thing ... it occurs over 2-3 hours ... then sometimes stabilizes a bit, then drops again ...

we get around : (copypaste from mrtg-modwatch)
Max Hits: 14.3 kH/h
Average Hits: 3809.0 H/h
Current Hits: 8844.0 H/h


so it's not a heavily used server .. ( + it's a 2.8E HT p4 with 1gb ddr )
Back to top
View user's profile Send private message
ai
Apprentice
Apprentice


Joined: 21 Mar 2004
Posts: 227
Location: Poland, Krk

PostPosted: Mon Apr 18, 2005 7:31 pm    Post subject: Reply with quote

hmm looking for the source of this, try to monitor : cgi scripts, php scripts, and your net traffic (not only the average www - this high load can be coused by many errorous connections or smth like that). I believe that studying the logs (/var/log/apache2) might be helpfull. Also i strongly advice u to install & properly configure mod_security as it's a great and handy tool and can provide additional logs.

Looking forward to seeing some suspicious logs, ai [;
_________________
just nothing ;)
Back to top
View user's profile Send private message
zark
n00b
n00b


Joined: 27 Mar 2004
Posts: 74
Location: Belgium

PostPosted: Mon Apr 18, 2005 7:47 pm    Post subject: Reply with quote

ai wrote:
not only the average www - this high load can be coused by many errorous connections or smth like that




but when i kill all the apache2 processes i get all my ram&swap back instantly ....

furthermore, if i look at the pid of the apache2 they have weird number sequences ....


12217 --> 12245
and
30653 --> 30713

check :


Code:
root     30653  0.0  0.5  19612  5272 ?        Ss   Apr17   0:00 /usr/sbin/apache2 -k start -D PHP4
apache   30655  0.0  0.4  18420  4116 ?        S    Apr17   0:00 /usr/sbin/apache2 -k start -D PHP4
apache   30656  0.0 27.2 350848 246248 ?       S    Apr17   0:00 /usr/sbin/apache2 -k start -D PHP4


.....

Code:
apache   30712  0.0 27.2 350848 246248 ?       S    Apr17   0:00 /usr/sbin/apache2 -k start -D PHP4
apache   30713  0.0 27.5 349060 248916 ?       S    Apr17   0:00 /usr/sbin/apache2 -k start -D PHP4
apache   12217  0.0 19.2 262848 174240 ?       S    Apr17   0:00 /usr/sbin/apache2 -k start -D PHP4


....
Code:
apache   12243  0.0 19.2 262848 174240 ?       S    Apr17   0:14 /usr/sbin/apache2 -k start -D PHP4
apache   12244  0.0 19.2 262848 174240 ?       S    Apr17   0:14 /usr/sbin/apache2 -k start -D PHP4
apache   12245  0.0 19.2 262848 174240 ?       S    Apr17   0:00 /usr/sbin/apache2 -k start -D PHP4
Back to top
View user's profile Send private message
zark
n00b
n00b


Joined: 27 Mar 2004
Posts: 74
Location: Belgium

PostPosted: Mon Apr 18, 2005 8:07 pm    Post subject: Reply with quote

i check with glsa -l


and found these

200403-04 [U] Multiple security vulnerabilities in Apache 2 ( net-www/apache )
200411-18 [U] Apache 2.0: Denial of Service by memory consumption ( net-www/apache )



if it says U .. means i should apply them ?
Back to top
View user's profile Send private message
ai
Apprentice
Apprentice


Joined: 21 Mar 2004
Posts: 227
Location: Poland, Krk

PostPosted: Mon Apr 18, 2005 9:12 pm    Post subject: Reply with quote

zark wrote:
ai wrote:
not only the average www - this high load can be coused by many errorous connections or smth like that




but when i kill all the apache2 processes i get all my ram&swap back instantly ....

oh of course, that's quite logical that when u kill the deamon which has to handle with many errorous connections it does not need swap memmory anymore. (acctually he is forced to not use it).
zark wrote:

furthermore, if i look at the pid of the apache2 they have weird number sequences ....


12217 --> 12245
and
30653 --> 30713

check :


Code:
root     30653  0.0  0.5  19612  5272 ?        Ss   Apr17   0:00 /usr/sbin/apache2 -k start -D PHP4
apache   30655  0.0  0.4  18420  4116 ?        S    Apr17   0:00 /usr/sbin/apache2 -k start -D PHP4
apache   30656  0.0 27.2 350848 246248 ?       S    Apr17   0:00 /usr/sbin/apache2 -k start -D PHP4


.....

Code:
apache   30712  0.0 27.2 350848 246248 ?       S    Apr17   0:00 /usr/sbin/apache2 -k start -D PHP4
apache   30713  0.0 27.5 349060 248916 ?       S    Apr17   0:00 /usr/sbin/apache2 -k start -D PHP4
apache   12217  0.0 19.2 262848 174240 ?       S    Apr17   0:00 /usr/sbin/apache2 -k start -D PHP4


....
Code:
apache   12243  0.0 19.2 262848 174240 ?       S    Apr17   0:14 /usr/sbin/apache2 -k start -D PHP4
apache   12244  0.0 19.2 262848 174240 ?       S    Apr17   0:14 /usr/sbin/apache2 -k start -D PHP4
apache   12245  0.0 19.2 262848 174240 ?       S    Apr17   0:00 /usr/sbin/apache2 -k start -D PHP4


i have a problem in understanding what u mean, but i believe that the pid number depends on how much other processes will be started, while starting another apached process.

zark wrote:
i check with glsa -l


and found these

200403-04 [U] Multiple security vulnerabilities in Apache 2 ( net-www/apache )
200411-18 [U] Apache 2.0: Denial of Service by memory consumption ( net-www/apache )



if it says U .. means i should apply them ?


? is your apache2 up to date for sure ? becouse this are vuln from 2004.
_________________
just nothing ;)
Back to top
View user's profile Send private message
zark
n00b
n00b


Joined: 27 Mar 2004
Posts: 74
Location: Belgium

PostPosted: Wed Apr 20, 2005 7:52 am    Post subject: Reply with quote

mmh, i just realised that apache2 is actually using WORKER MPM ... i thought the default was prefork and that worker was experimental ....

i reduced the 256 MaxClients to 25 and memory usage seems under control.



[ebuild R ] net-www/apache-2.0.52-r1 +berkdb -debug -doc +gdbm +ipv6 -ldap +ssl -static +threads 0 kB
Back to top
View user's profile Send private message
zark
n00b
n00b


Joined: 27 Mar 2004
Posts: 74
Location: Belgium

PostPosted: Fri Apr 22, 2005 10:06 am    Post subject: Reply with quote

okay .. that didn't solve the problem ...

it ate thru 200mb of swap in 10minutes.



problem is that all my logs are vhost dependant ... so finding anything suspicious around the time of attack is kinda hard ....

i'll check out that mod_security thing
Back to top
View user's profile Send private message
Quinten
n00b
n00b


Joined: 06 Jan 2003
Posts: 6

PostPosted: Tue Apr 26, 2005 6:50 am    Post subject: Reply with quote

I have exactly the same problem. System runs fine for a day or two and then grinds to a halt. Top shows me that apache2 uses all available swapspace and memory, and a stop and start frees it all up... until the next time.
Back to top
View user's profile Send private message
zark
n00b
n00b


Joined: 27 Mar 2004
Posts: 74
Location: Belgium

PostPosted: Fri May 20, 2005 12:38 pm    Post subject: Reply with quote

okay ...


i found the solution ... i recompiled apache,


USE "-threads" emerge apache


and that compiled it without the threads options, and it's been running smoothly for over a week now !
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum