[文章作者:张宴 本文版本:v1.0 最后修改:2007.07.24 转载请注明出处:http://blog.zyan.cc]

  新增的一组Apache服务器上线以来,我用netstat -an命令发现服务器中有大量状态为TIME-WAIT的TCP连接,于是用/sbin/sysctl -a查看了一下Linux的各项内核参数,并翻阅有关资料,决定修改其中的两项参数,以达到减少TCP连接中TIME-WAIT sockets的目的。

  vi /etc/sysctl.conf
  编辑/etc/sysctl.conf文件,增加三行:
引用
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1

  说明:
  net.ipv4.tcp_syncookies = 1 表示开启SYN Cookies。当出现SYN等待队列溢出时,启用cookies来处理,可防范少量SYN攻击,默认为0,表示关闭;
  net.ipv4.tcp_tw_reuse = 1 表示开启重用。允许将TIME-WAIT sockets重新用于新的TCP连接,默认为0,表示关闭;
  net.ipv4.tcp_tw_recycle = 1 表示开启TCP连接中TIME-WAIT sockets的快速回收,默认为0,表示关闭。

  再执行以下命令,让修改结果立即生效:
  /sbin/sysctl -p

  用以下语句看了一下服务器的TCP状态:
  netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
  返回结果如下:
  ESTABLISHED 1423
  FIN_WAIT1 1
  FIN_WAIT2 262
  SYN_SENT 1
  TIME_WAIT 962

  效果:处于TIME_WAIT状态的sockets从原来的10000多减少到1000左右。处于SYN_RECV等待处理状态的sockets为0,原来的为50~300。

  附:TCP状态变迁图,见我的另一篇文章《查看Apache并发请求数及其TCP连接状态

Tags: ,



技术大类 » Web服务器 | 评论(57) | 引用(0) | 阅读(100779)
GAWE
2013-3-5 13:49
买轴承就到:www.jkzhoucheng.cn
磨延城 Email Homepage
2013-10-21 20:55
磨途歌学习了
django Email Homepage
2013-11-30 19:26
Uggs Sale the ideal idea Coach Outlet Online  enough time to search for many of reduction Ugg boot. Like big portions? If you began ready your apartment, Coach Outlet  it's always best to consider the most effective way direct to the stage it could be to utilise your inventory throughout Coach Factory Outlet  concern, or maybe you basically won't destination stuff not enough.we're anti- whitening tray because Coach Outlet Online  i will be enjoy just get germ dog breeders
apple
2014-1-24 16:46
zanzanzanzanzan
shz Email
2022-8-14 16:36
New site is solid. A debt of gratitude is in order for the colossal exertion.  Lead generation
shz Email
2022-8-14 16:39
This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.  Lead generation
shz Email
2022-8-14 16:42
Actually I read it yesterday but I had some thoughts about it and today I wanted to read it again because it is very well written.  Lead generation
shz Email
2022-8-14 16:45
Took me time to understand all of the comments, but I seriously enjoyed the write-up. It proved being really helpful to me and Im positive to all of the commenters right here! Its constantly nice when you can not only be informed, but also entertained! I am certain you had enjoyable writing this write-up.  Lead generation
shz Email
2022-8-14 16:47
It is extremely nice to see the greatest details presented in an easy and understanding manner.  Lead generation
shz Email
2022-8-14 16:50
I like viewing web sites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you!  Lead generation
shz Email
2022-8-14 16:58
Thanks for the nice blog. It was very useful for me. I'm happy I found this blog. Thank you for sharing with us,I too always learn something new from your post.  Lead generation
shz Email
2022-8-14 17:01
We are really grateful for your blog post. You will find a lot of approaches after visiting your post. Great work  Lead generation
shz Email
2022-8-14 17:04
Super site! I am Loving it!! Will return once more, Im taking your food additionally, Thanks.  Lead generation
shz Email
2022-8-14 17:06
I would also motivate just about every person to save this web page for any favorite assistance to assist posted the appearance.  Lead generation
먹튀신고 Email Homepage
2023-9-21 13:04
Great website, I like it. Well done. Nice website. Love it. This is really good. Please continue to publish good articles and let me learn more. Thank you먹튀신고
Lucky cola
2024-2-7 13:48
Unleash your inner gamer and dominate the virtual realm.  Lucky cola
分页: 3/3 第一页 上页 1 2 3 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]