わたろぐ

仕事、読書、ガジェット、グルメ、写真、旅行など雑多な備忘

apacheの設定

レンタルサーバにて運営しているこのブログ。 時々応答しなくなったり、すごい時間がかかるようになることがある。 気になったらapacheの再起動をしてたんだけど、設定を見直した。

調べてみると、プロセスがメモリを食い続けていることが原因で応答が遅くなるケースがあるとか。 早速自分のサーバでもチェックしてみた。 [bash] $ ps aux | grep httpd root 887 0.0 0.1 65448 844 pts/0 R+ 22:42 0:00 grep httpd apache 9335 0.0 1.1 395752 6140 ? S May22 0:01 /usr/sbin/httpd apache 9343 0.0 5.0 403980 26512 ? S May20 0:05 /usr/sbin/httpd apache 9345 0.0 6.4 398860 33896 ? S May20 0:04 /usr/sbin/httpd apache 9347 0.0 5.7 397852 30260 ? S May20 0:05 /usr/sbin/httpd apache 9349 0.0 3.7 398860 19904 ? S May20 0:05 /usr/sbin/httpd apache 9350 0.0 3.9 401948 20872 ? S May20 0:05 /usr/sbin/httpd apache 12695 0.0 3.0 397852 16064 ? S May20 0:05 /usr/sbin/httpd apache 12698 0.0 6.9 398876 36256 ? S May20 0:06 /usr/sbin/httpd apache 15303 0.0 7.4 405004 38920 ? S May20 0:05 /usr/sbin/httpd apache 18743 0.0 1.4 394728 7500 ? S May23 0:01 /usr/sbin/httpd apache 18745 0.0 0.9 399884 5152 ? S May23 0:01 /usr/sbin/httpd apache 18746 0.0 1.2 397852 6576 ? S May23 0:01 /usr/sbin/httpd apache 18747 0.0 4.5 397832 23708 ? S May23 0:01 /usr/sbin/httpd apache 18750 0.0 4.9 399944 26200 ? S May23 0:01 /usr/sbin/httpd apache 18752 0.0 7.0 396784 37124 ? S May23 0:01 /usr/sbin/httpd apache 18754 0.0 1.6 396792 8540 ? S May23 0:02 /usr/sbin/httpd apache 18755 0.0 6.8 398876 35828 ? S May23 0:01 /usr/sbin/httpd apache 18756 0.0 1.0 396872 5364 ? S May23 0:01 /usr/sbin/httpd apache 18757 0.0 0.8 393712 4644 ? S May23 0:01 /usr/sbin/httpd apache 18758 0.0 6.5 398860 34460 ? S May23 0:00 /usr/sbin/httpd root 30188 0.0 0.6 355816 3288 ? Ss May19 0:00 /usr/sbin/httpd [/bash]

めちゃくちゃプロセスが起動してる。 試しに再起動。これも時間がかかった。しかもなんかメッセージ出てるし。 [bash]

/etc/rc.d/init.d/httpd restart

httpd を停止中: [ OK ] httpd を起動中: httpd: Could not reliably determine the server's fully qualified domain name, using 163.43.164.119 for ServerName [ OK ] [/bash]

ここでもう一度プロセスをチェックしてみる。 [bash] [root@rad-xen-vweb7 ~]# ps aux | grep httpd root 987 0.3 2.8 355064 14768 ? Ss 22:48 0:00 /usr/sbin/httpd apache 989 0.0 1.3 356088 7264 ? S 22:48 0:00 /usr/sbin/httpd apache 990 0.0 1.3 356088 7264 ? S 22:48 0:00 /usr/sbin/httpd apache 991 0.0 1.3 356088 7264 ? S 22:48 0:00 /usr/sbin/httpd apache 992 0.0 1.3 356088 7264 ? S 22:48 0:00 /usr/sbin/httpd apache 993 0.0 1.3 356088 7264 ? S 22:48 0:00 /usr/sbin/httpd apache 994 0.0 1.3 356088 7264 ? S 22:48 0:00 /usr/sbin/httpd apache 995 0.0 1.3 356088 7264 ? S 22:48 0:00 /usr/sbin/httpd apache 996 0.0 1.3 356088 7264 ? S 22:48 0:00 /usr/sbin/httpd [/bash] おお、かなり使用量減ってる。

ってことで、設定を見直すことにした。 httpd.confを修正すればいいみたい。 で、暫定の設定がこれ。 [bash]

prefork MPM

StartServers: number of server processes to start

MinSpareServers: minimum number of server processes which are kept spare

MaxSpareServers: maximum number of server processes which are kept spare

ServerLimit: maximum value for MaxClients for the lifetime of the server

MaxClients: maximum number of server processes allowed to start

MaxRequestsPerChild: maximum number of requests a server process serves

StartServers 6 MinSpareServers 6 MaxSpareServers 6 ServerLimit 100 MaxClients 100 MaxRequestsPerChild 1024 [/bash] これでしばらく様子を見てみます。

ちなみに設定、再起動後のプロセスはこうなってました。 [bash]

ps aux | grep httpd

root 1160 0.4 2.7 355064 14680 ? Ss 23:05 0:00 /usr/sbin/httpd apache 1161 0.0 1.3 355064 7204 ? S 23:05 0:00 /usr/sbin/httpd apache 1162 0.0 1.3 355064 7204 ? S 23:05 0:00 /usr/sbin/httpd apache 1163 0.0 1.3 355064 7204 ? S 23:05 0:00 /usr/sbin/httpd apache 1165 0.0 1.3 355064 7204 ? S 23:05 0:00 /usr/sbin/httpd apache 1166 0.0 1.3 355064 7204 ? S 23:05 0:00 /usr/sbin/httpd apache 1167 0.0 1.3 355064 7204 ? S 23:05 0:00 /usr/sbin/httpd root 1169 0.0 0.1 65448 840 pts/0 R+ 23:06 0:00 grep httpd [/bash] ちゃんと起動時のプロセスが6個になってる。