[TAG] Optimizing Apache2 and MySQL install

Suramya Tomar security at suramya.com
Wed Jun 22 05:58:24 MSD 2005


Hi Everyone,

I have another problem and I was hoping that you will be able to help me 
solve this one too. I am hosting my website on a Debian Sarge system on 
a LVS (Linux Virtual Server) with 64 MB RAM and 64MB swap using Apache, 
PHP and MySQL. The problem I have is that every so often the Apache and 
MySQL process start taking 100% of the CPU and RAM and after a few mins 
of which the system runs out of RAM and the kernel starts killing 
processes (MySQL is usually the victim) which means my site goes down 
till I restart that process.

Is there some way I can optimize MySQL and Apache and tell it not to use 
so much RAM/CPU? I tried searching on the web but didn't find anything 
relevant. I am running Apache2, PHP 5, MySQL 4.1.10 on this box.

Apache was compiled with:
--enable-ssl --enable-cgi --with-ssl --enable-module=so

PHP With:

--with-bz2 --enable-ftp --with-gd --enable-exif --with-jpeg-dir 
--with-png-dir --with-ttf --with-freetype-dir 
--with-imap=/usr/local/imap --with-mcrypt --with-mysql=/usr/local/mysql/ 
--with-openssl --with-cpdflib --enable-soap --with-zlib
--with-apxs2=/usr/local/apache2/bin/apxs

and MySQL with:

--with-mysqld-user=mysqld --with-openssl

The website gets about a 1000 - 2000 hits a day and I have 2 blogs(Using 
Serendipity Ver 0.8.1) running on this system. I also run Sendmail on 
the box but is only used locally to send mails from Serendipity and my 
guestbook. I don't allow any external connections to port 25.

The error I see in the /var/log/messages when a process is killed is:

Jun 21 13:44:21 wyrm kernel: __alloc_pages: 0-order allocation failed 
(gfp=0x1d2/0)

Output of free:

wyrm:/home/suramya# free
              total       used       free     shared    buffers     cached
Mem:         60500      59092       1408          0        660      27324
-/+ buffers/cache:      31108      29392
Swap:        65528      28648      36880

Output of top right now:

   PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
740 apache    14   0 13400 9908 2992 R 57.8 16.4   0:28.18 httpd
809 mysql     20   0 11676 2416 2204 R 35.5  4.0   0:01.20 mysqld
459 mysql      9   0 11676 2416 2204 S  1.9  4.0   0:04.74 mysqld
808 root       9   0  1044 1044  852 R  1.3  1.7   0:00.09 top
   4 root       9   0     0    0    0 S  0.3  0.0   0:22.18 kswapd
798 apache     9   0  6928 3660 3056 S  0.3  6.0   0:06.91 httpd
   1 root       9   0   100   72   72 S  0.0  0.1   0:00.21 init
   2 root       9   0     0    0    0 S  0.0  0.0   0:00.00 keventd
  3 root      19  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd_CPU0
  5 root       9   0     0    0    0 S  0.0  0.0   0:00.00 bdflush
  6 root       9   0     0    0    0 S  0.0  0.0   0:00.00 kupdated
  7 root       9   0     0    0    0 S  0.0  0.0   0:00.00 jfsIO
  8 root       9   0     0    0    0 S  0.0  0.0   0:00.00 jfsCommit
  9 root       9   0     0    0    0 S  0.0  0.0   0:00.00 jfsSync
10 root       9   0     0    0    0 S  0.0  0.0   0:00.00 xfsbufd
11 root       9   0     0    0    0 S  0.0  0.0   0:00.00 xfslogd/0

Any suggestions on how to reduce the load and prevent the system from 
dying every few hours?

Thanks,
  Suramya

-- 
----------------------------------------------------------
Some days you're the dog; some days you're the hydrant.
----------------------------------------------------------
Name : Suramya Tomar
Homepage URL: http://www.suramya.com
-------------------------------------------------

************************************************************
Disclaimer:
Any errors in spelling, tact, or fact are transmission errors.
************************************************************





More information about the TAG mailing list