1. 程式人生 > >服務端Too many open files解決方案

服務端Too many open files解決方案

一個負載比較重的discuz論壇伺服器,1小時線上一萬多,有時訪問時無法顯示。


我用另一臺同網段的機器作測試,大概20次中會有1、2次超時


wget http://bbs.xxx.com
--17:06:08--  http://bbs.xxx.com/
正在解析主機 bbs.xxx.com... 221.13.18.b
Connecting to bbs.xxx.com|221.13.18.b|:80... 失敗:連線超時。
重試中。
在bbs上用tcpdump監控


正常時可以接收到
......
17:27:55.746530 IP 221.13.18.a.39495 > 221.13.18.b.http: . ack 193785 win 353
17:27:55.746923 IP 221.13.18.a.39495 > 221.13.18.b.http: . ack 196705 win 353
17:27:55.747276 IP 221.13.18.a.39495 > 221.13.18.b.http: F 128:128(0) ack 197467 win 353
17:27:55.747284 IP 221.13.18.b.http > 221.130.185.a.39495: . ack 129 win 12

如果wget失敗就監控不到資訊,問下怎麼回事?
檢察了net.ipv4.tcp_max_syn_backlog 應該足夠了


系統資訊
======================================
centos 5.2 64bit
nginx+php+mysql

nginx 4個程序
php 96個程序


Linux bora 2.6.18-128.el5 #1 SMP Wed Jan 21 10:41:14 EST 2009 x86_64 x86_64 x86_64 GNU/Linux


sysctl核心
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768
net.ipv4.tcp_max_tw_buckets = 5000
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 196608 262144 393216
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 120
net.ipv4.ip_local_port_range = 1024  65535
net.ipv4.tcp_syncookies = 1


優化檔案控制代碼
vi /etc/security/limits.conf
* soft nofile 51200 
* hard nofile 51200


vi /etc/rc.local
ulimit -SHn 51200 


===================
Active connections: 2419 
server accepts handled requests
73668795 73668795 232420556 
Reading: 11 Writing: 28 Waiting: 2380 



bbs線上會員 - 總計 13433 人線上

top - 13:29:01 up 33 days, 22:53,  2 users,  load average: 1.22, 1.60, 
Tasks: 265 total,   1 running, 264 sleeping,   0 stopped,   0 zombie 
Cpu(s):  9.3%us,  1.4%sy,  0.0%ni, 88.2%id,  0.5%wa,  0.0%hi,  0.6%si, 
Mem:   8168412k total,  6691148k used,  1477264k free,   917728k buffe 
Swap:  4096532k total,      228k used,  4096304k free,  3841696k cache


netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
TIME_WAIT 4845
SYN_SENT 1
FIN_WAIT1 185
ESTABLISHED 2698
FIN_WAIT2 381
SYN_RECV 162
CLOSING 5
LAST_ACK 137


netstat -n |wc -l
8441


cat /proc/sys/net/ipv4/netfilter/ip_conntrack_max
65536


cat /proc/sys/fs/file-nr
4590    0       765985