zoukankan      html  css  js  c++  java
  • linux 下Time_wait过多问题解决

    linux 下Time_wait过多问题解决

     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,表示关闭。
    net.ipv4.tcp_fin_timeout修改系統默认的TIMEOUT时间

    关键命令:

    1、netstat -n | awk '/^tcp/ {++state[$NF]} END {for(key in state) print key," ",state[key]}'

    2. netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

    注:这边文章的说法貌似时错误的. sysctl -p命令并不能使得内核立即生效.可以查看帮助知道

    yingc@yingc:~/work/gitcode/v1.9-dev.tmp$ sudo /sbin/sysctl --hel
    
    Usage:
     sysctl [options] [variable[=value] ...]
    
    Options:
      -a, --all            display all variables
      -A                   alias of -a
      -X                   alias of -a
          --deprecated     include deprecated parameters to listing
      -b, --binary         print value without new line
      -e, --ignore         ignore unknown variables errors
      -N, --names          print variable names without values
      -n, --values         print only values of a variables
      -p, --load[=<file>]  read values from file
      -f                   alias of -p
          --system         read values from all system directories
      -r, --pattern <expression>
                           select setting that match expression
      -q, --quiet          do not echo variable set
      -w, --write          enable writing a value to variable
      -o                   does nothing
      -x                   does nothing
      -d                   alias of -h
    
     -h, --help     display this help and exit
     -V, --version  output version information and exit
    

    关于 netstat 下 time-wait 状态链接 过多的 测试

    这篇文章通过修改内核中的#define TCP_TIMEWAIT_LEN (10*HZ)是可以尽快将处于TIME_WAIT状态的socket回收,

    但是会有问题. 详见UNIX网络编程卷一 P37=> 需要2MSL

  • 相关阅读:
    day02-数据库操作
    day01-MySQL介绍
    3-socketserver
    1-多线程与多进程
    keyword模块
    math模块
    查看进程pid与ppid
    开启进程的两种方式
    进程理论
    进程
  • 原文地址:https://www.cnblogs.com/jingzhishen/p/4885661.html
Copyright © 2011-2022 走看看