Version 2 (modified by jazz, 14 years ago) (diff) |
---|
2011-04-13
Apache Performance Tuning
- 花了兩天時間,總算找出造成 trac 網站大量記憶體需求的特徵:刻意發起造成 CLOSE_WAIT 的攻擊行為。
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 15652 www-data 20 0 783m 763m 4624 R 97.0 75.4 17:31.07 apache2 20059 www-data 20 0 52836 31m 4732 S 2.7 3.2 0:06.86 apache2 jazz@trac-pool:~$ sudo netstat -nap | grep 15652 tcp6 1 0 140.110.X.X:80 220.181.93.1:55903 CLOSE_WAIT 15652/apache2
- 手動砍掉 15652 這個 process 之後,同樣這個 IP,後來又產生了一次 CLOSE_WAIT 現象,不禁懷疑這是一種網站攻擊方式。
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 23708 www-data 20 0 414m 396m 4544 R 99.7 39.2 2:44.46 apache2 23025 www-data 20 0 74940 55m 4752 S 0.0 5.5 0:27.58 apache2 tcp6 0 0 140.110.X.X:80 220.181.93.1:64932 TIME_WAIT - tcp6 0 0 140.110.X.X:80 220.181.93.1:47074 TIME_WAIT - tcp6 0 0 140.110.X.X:80 220.181.93.1:50047 TIME_WAIT - tcp6 0 0 140.110.X.X:80 220.181.93.1:43913 TIME_WAIT -
- <解決方法> 降低 net.ipv4.tcp_keepalive_time 的數值,預設是 7200 秒(兩小時),真的太長了!!
echo "decrease TCP socket TIME_WAIT time" sysctl -w net.ipv4.tcp_fin_timeout=10 sysctl -w net.ipv4.tcp_tw_reuse=1 sysctl -w net.ipv4.tcp_tw_recycle=1 echo "decrease TCP socket CLOSE_WAIT time" sysctl -w net.ipv4.tcp_keepalive_time=30 sysctl -w net.ipv4.tcp_keepalive_probes=2 sysctl -w net.ipv4.tcp_keepalive_intvl=2
- <參考> 大量 CLOSE_WAIT 的影響
大量的 CLOSE_WAIT 連接,直接佔滿 TCP 連線佇列, 導致 Apache 失去回應,且 CPU 使用量與記憶體使用量快速提高!!
- <參考> CLOSE_WAIT 生成的原因
Attachments (1)
- 11-04-14_memory-week.png (41.2 KB) - added by jazz 14 years ago.
Download all attachments as: .zip