当前位置:   article > 正文

centos 连接数查看及TIME_OUT 过多处理

centos 连接数查看及TIME_OUT 过多处理

查看连接数及状态统计

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

编辑 /etc/sysctl.conf

shell: sysctl -p 生效
  1. # sysctl settings are defined through files in
  2. # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
  3. #
  4. # Vendors settings live in /usr/lib/sysctl.d/.
  5. # To override a whole file, create a new file with the same in
  6. # /etc/sysctl.d/ and put new settings there. To override
  7. # only specific settings, add a file with a lexically later
  8. # name in /etc/sysctl.d/ and put new settings there.
  9. #
  10. # For more information, see sysctl.conf(5) and sysctl.d(5).
  11. #禁用ipv6
  12. net.ipv6.conf.all.disable_ipv6 = 1
  13. net.ipv6.conf.default.disable_ipv6 = 1
  14. net.ipv6.conf.lo.disable_ipv6 = 1
  15. net.ipv6.conf.eth0.disable_ipv6 = 1
  16. net.ipv6.conf.pan0.disable_ipv6 = 1
  17. #使用swap资源
  18. vm.swappiness = 10
  19. net.ipv4.neigh.default.gc_stale_time=120
  20. # see details in https://help.aliyun.com/knowledge_detail/39428.html
  21. net.ipv4.conf.all.rp_filter=0
  22. net.ipv4.conf.default.rp_filter=0
  23. net.ipv4.conf.eth0.rp_filter = 0
  24. net.ipv4.conf.default.arp_announce = 2
  25. net.ipv4.conf.lo.arp_announce=2
  26. net.ipv4.conf.all.arp_announce=2
  27. # see details in https://help.aliyun.com/knowledge_detail/41334.html
  28. #net.ipv4.tcp_max_tw_buckets = 5000
  29. net.ipv4.tcp_syncookies = 1
  30. #net.ipv4.tcp_max_syn_backlog = 1024
  31. net.ipv4.tcp_synack_retries = 2
  32. #最大连接数
  33. fs.file-max=65535
  34. #处理TIME_OUT连接过多
  35. net.ipv4.tcp_max_tw_buckets = 10000
  36. net.ipv4.tcp_tw_reuse = 1
  37. net.ipv4.tcp_tw_recycle = 1
  38. net.ipv4.tcp_fin_timeout = 10
  39. net.ipv4.tcp_keepalive_time = 60
  40. net.ipv4.ip_local_port_range = 11000 65000
  41. net.ipv4.tcp_keepalive_time = 120
  42. net.ipv4.tcp_keepalive_intvl = 15
  43. net.ipv4.tcp_keepalive_probes = 5
  44. #记录的那些尚未收到客户端确认信息的连接请求的最大值。对于有128M内存的系统而言,缺省值是1024,小内存的系统则是128
  45. net.ipv4.tcp_max_syn_backlog = 262144
  46. #web应用中listen函数的backlog默认会给我们内核参数的net.core.somaxconn限制到128,而nginx定义的NGX_LISTEN_BACKLOG默认为511,所以有必要调整这个值。
  47. net.core.somaxconn = 65535
  48. #系统中最多有多少个TCP套接字不被关联到任何一个用户文件句柄上。如果超过这个数字,孤儿连接将即刻被复位并打印出警告信息。
  49. #这个限制仅仅是为了防止简单的DoS攻击,不能过分依靠它或者人为地减小这个值,更应该增加这个值(如果增加了内存之后)。
  50. net.ipv4.tcp_max_orphans = 262144
  51. #时间戳可以避免序列号的卷绕。一个1Gbps的链路肯定会遇到以前用过的序列号。时间戳能够让内核接受这种“异常”的数据包。这里需要将其关掉。
  52. net.ipv4.tcp_timestamps = 0
  53. #内核放弃连接之前发送SYN+ACK包的数量
  54. net.ipv4.tcp_synack_retries = 1
  55. #在内核放弃建立连接之前发送SYN包的数量
  56. net.ipv4.tcp_syn_retries = 1

 

查看tcp前10的连接数IP , 本地IP除外

netstat -na|grep ESTABLISHED|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -rn|head -10|grep -v -E '192.168|127.0'

查看连接数IP,按连接数排序

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

监控网络带宽

iftop

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/158571
推荐阅读
相关标签
  

闽ICP备14008679号