Loading...

Linux 連線數調校.

Temperature: 0 °C

蘇恆永 蘇恆永
author_tools

最近常常遇到連線數太多(因為底層 WebService 太忙了).
web 最後連不上的問題.

後來 用這個指令

netstat -anl | grep 80 | awk '/^tcp/ {t[$NF]++}END{for(state in t){print state, t[state]} }'

檢查發現
LISTEN 2
FIN_WAIT1 4
FIN_WAIT2 113
ESTABLISHED 73
TIME_WAIT 566
SYN_RECV 1

停在 TIME_WAIT 的數目偏大了,

原本 linux 的 somaxconn 只有 1024,
所以等於只剩大約 300多個連線可以給客戶連.

查了好幾篇網路文件.
總算調好參數.
現在 sysctl.conf 裡面
net.core.somaxconn = 4096
net.core.netdev_max_backlog = 5000
net.ipv4.tcp_fin_timeout = 20
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 0
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.ip_local_port_range = 9000 64000


lighttpd.conf 裡面加上
server.max-fds = 2048

一切搞定

ps: 後來發現 net.ipv4.tcp_tw_reuse, net.ipv4.tcp_tw_recycle 如果打開,
在 NAT 後面會發生問題,
所以還是關掉比較好.

參考下列幾篇:
http://vincent.bernat.im/en/blog/2014-tcp-time-wait-state-linux.html
http://www.lognormal.com/blog/2012/09/27/linux-tcpip-tuning/

捷運科技大樓站 Go

https://innstory.com/story-Linux_連線數調校-399
Linux 網管

Next
實用的_netstat_查詢連線指令 

Nearby Attractions

捷運科技大樓站-Nearby Attractions

  • 北投溫泉浴場 Go
  • 原八芝蘭公學校講堂 Go
  • 新富市場 Go
  • 圓山別莊 Go
  • 臺北公會堂 Go
  • 艋舺助順將軍廟(晉德宮) Go

About the Author

蘇恆永

重新pickup本能中

Visitor message

Leave some footprints to prove that you visited me

  • eyJpdiI6IlptUmhhMmx1Wld3N2FXNXFZV3BrYWc9PSIsInZhbHVlIjoiQ1d1akZrMTBzb2xuK25vT09wd1lqZz09In0

    Chung 2015-04-28 04:36:22 0

    man,我依稀記得我也遇過類似的問題..

Recommended reading

Author's other related stories

CentOS 5 更新 openssh 7.1p2 及 openssl 1.0.1s

CentOS 5 更新 op...

最近被 highlight openssh 必須更新至 .p. CentOS5 真是有夠古老的, 一...

Python Pragmatic Unicode

Python Pragmat...

記錄一下 Python Pragmatic Unicode ...

免費電子書下載

免費電子書下載

太晚看到了, 每天都有免費程式設計相關的電子書可以下載 ht...

Recommended reading

Other stories happened at this address

vmware 的 vm 網卡如何改成固定 mac

vmware 的 vm 網卡...

http://wahlnetwork.com////rej...

實用的 netstat 查詢連線指令

實用的 netstat 查詢...

以下是一些實用的 netstat 語法,可以檢查主機的連線數量: netstat na 顯示主機上所...

ankhsvn 使用非標準 ssh port, 及設定免密碼登入

ankhsvn 使用非標準 ...

ankhsvn https://ankhsvn.open.c...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format