`

apache time_wait

 
阅读更多
# netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
LAST_ACK 1
SYN_RECV 164
CLOSE_WAIT 3
ESTABLISHED 655
FIN_WAIT1 15
FIN_WAIT2 81
SYN_SENT 3
TIME_WAIT 14274
系统很多TIME_WAIT状态的连接,不能及时回收。访问量大的时候时常出现连接超时。
解决办法是调整内核参数,加快TIME_WAIT状态连接的回收和启用重用。
修改内核代码
vi /etc/sysctl.conf
net.ipv4.tcp_tw_reuse = 1 #表示开启重用。允许将TIME-WAIT sockets重新用于新的TCP连接,默认为0,表示关闭;
net.ipv4.tcp_tw_recycle = 1 #表示开启TCP连接中TIME-WAIT sockets的快速回收,默认为0,表示关闭。
sysctl -p
vi /etc/sysctl.conf
net.ipv4.tcp_tw_reuse = 1 #表示开启重用。允许将TIME-WAIT sockets重新用于新的TCP连接,默认为0,表示关闭;
net.ipv4.tcp_tw_recycle = 1 #表示开启TCP连接中TIME-WAIT sockets的快速回收,默认为0,表示关闭。
sysctl -p
更多参数调整看以前的博客Linux web服务器常用内核参数注解
调整后TIME_WAIT状态连接立即减少:
# netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’
LAST_ACK 9
SYN_RECV 171
CLOSE_WAIT 2
ESTABLISHED 767
FIN_WAIT1 27
FIN_WAIT2 13
TIME_WAIT 3675
# netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’
LAST_ACK 9
SYN_RECV 275
CLOSE_WAIT 3
ESTABLISHED 1111
FIN_WAIT1 42
FIN_WAIT2 154
TIME_WAIT 1804
在安装linux后的内核优化根据下面的选项,在优化Linux内核中要注意你修改的每一个参数,以保证万无一失.
kernel.shmall = 268435456
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 5000 65000
net.ipv4.tcp_mem = 786432 1048576 1572864
net.core.wmem_max = 873200
net.core.rmem_max = 873200
net.ipv4.tcp_wmem = 8192 436600 873200
net.ipv4.tcp_rmem = 32768 436600 873200
net.core.somaxconn = 256
net.core.netdev_max_backlog = 1000
net.ipv4.tcp_max_syn_backlog = 2048
net.ipv4.tcp_retries2 = 5
net.ipv4.tcp_keepalive_time = 500
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.conf.lo.arp_ignore = 0
net.ipv4.conf.lo.arp_announce = 0
net.ipv4.conf.all.arp_ignore = 0
net.ipv4.conf.all.arp_announce = 0
各选项的解释:
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 = 30
#表示如果套接字由本端要求关闭,这个参数决定了它保持在FIN-WAIT-2状态的时间。
net.ipv4.tcp_keepalive_time = 1200
#表示当keepalive起用的时候,TCP发送keepalive消息的频度。缺省是2小时,改为20分钟。
net.ipv4.ip_local_port_range = 1024    65000
#表示用于向外连接的端口范围。缺省情况下很小:32768到61000,改为1024到65000。
net.ipv4.tcp_max_tw_buckets = 5000
#表示系统同时保持TIME_WAIT套接字的最大数量,如果超过这个数字,
#TIME_WAIT套接字将立刻被清除并打印警告信息。默认为180000,改为5000。
#对于Apache、Nginx等服务器,上几行的参数可以很好地减少TIME_WAIT套接字数量,

#但是对于Squid,效果却不大。此项参数可以控制TIME_WAIT套接字的最大数量,避免Squid服务器被大量的TIME_WAIT套接字拖死。
分享到:
评论

相关推荐

    apache time_wait连接数太多问题解决方法

    主要介绍了apache time_wait连接数太多问题解决方法,本文使用调整内核参数来解决,需要的朋友可以参考下

    CentOS解决服务器存在大量time_wait的问题

    近期服务器出现大量time_wait的TCP连接造成服务器连接数过多而最终导致tomcat假死状态。连接服务器查看连接数的时候提示如下。 [root@test apache-tomcat-7.0.53]# netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a...

    单机负载均衡与群集的测试用例

    本测试用例基于Spring开发。已经打为war包。测试的时候请放在tomcat的webapps目录内。启动tomcat后会自动部署。访问的时在浏览器输入...页面会显示网站当前部署的物理目录以及当前的SessionID。

    apache benchmark ab.exe

    wait for each response Default is 30 seconds -b windowsize Size of TCP send/receive buffer, in bytes -B address Address to bind to when making outgoing connections -p postfile File containing ...

    linux下动态网站维护基本命令小结

    TCP连接数,TIME_WAIT 等 (2).服务运行情况 用户能否访问 代码如下: tail -f 查看apache访问日志与错误日志 查看系统日志/var/log/messages 查看服务器与Mysql数据库的连接情况 3.故障处理 (1).PHP类动态网站 服务...

    blog:fupengfei058的博客

    目录语言PHP的socket相关函数整理C语言malloc函数原理php中mt_...WAIT状态存在的原因TCP序列号回绕与解决TCP-fastopen(TFO)tcp粘包问题http2.0入门服务器&数据库fastcgi与php-fpm的关系Nginx为什么比Apache Httpd高效

    httpd2.2.12.tar

    desired changes in the stable versions must wait for inclusion into the next release cycle. When deciding to promote a development tree to being stable, a determination should be made whether the ...

    ( ap6181_sina33m_sc3817r验证通过_20170710_1608没有外层目录.7z

    <integer name="def_screen_off_timeout">1800000 <bool name="def_lockscreen_disabled">true 7、请严重注意,全志在这里埋坑了!(坑爹无敌!) Android里面调入配置文件:nvram.txt,里面里面调入:nvram_...

    InciDashboard_e3b:InciDashboard_e3b

    start " ZooKeeper " /D " .\bin\windows\ " " zookeeper-server-start.bat " " ..\..\config\zookeeper.properties "REM Wait 10 seconds:timeout 10REM Start Apache Kafka server:start " Kafka " /D " .\bin\...

    php.ini-development

    Enable the PHP scripting language engine under Apache. ; http://php.net/engine engine = On ; This directive determines whether or not PHP will recognize code between ; <? and ?> tags as ...

    操作系统(内存管理)

    文将对 Linux™ 程序员可以使用的内存管理技术进行概述,虽然关注的重点是 C 语言,但同样也适用于其他语言。文中将为您提供如何管理内存的细节,然后将进一步展示如何手工管理内存,如何使用引用计数或者内存池来半...

    内存管理内存管理内存管理

    内存管理内幕 dragonimp's blog coder.developer.[designer].ArchitecturE.manager.^_^... posts - 29, comments - 121, trackbacks - 27 My Links Home Contact ...文中将为您提供如何管理内存的细节,然后...

    testActiveMQ.rar

    // Wait while asynchronous messages come in. doneLatch.await(waitMillis); } catch (CMSException& e) { // Indicate we are ready for messages. latch.countDown(); e.printStackTrace(); } } // ...

    新版Android开发教程.rar

    o Apache Ant 1.6.5 or later for Linux and Mac, 1.7 or later for Windows o Not Not Not Not compatible with Gnu Compiler for Java (gcj) Note: Note: Note: Note: If JDK is already installed on your ...

    一个进程池的服务器程序

    #include <time.h> #include #include #include #include #include #include #include #include #include #include <sys/wait.h> #include #include #include #include #define PRECHILD 5 #define ...

    JMeter操作手册大全.docx

    1.1.RT -Response time 请求响应时间 从客户端发出请求到得到响应的整个时间 一般包括网络响应时间+server的响应时间。 用户接受准则: 例如2-5-10原则,即按照正常用户体验,如果用户能够在2秒内得到响应,会...

    计算机网络第六版答案

    Because the router has the entire packet at time t1, it can begin to transmit the packet to the receiving host at time t1. At time t2 = t1 + L/R2, the router completes transmission and the entire ...

    外文翻译 stus MVC

    If you where slick, you would place the configuration information into a file and load the file at run time. Function pointer arrays were the good old days of structured programming in C. Life is ...

    MySQL 5.6 Reference Manual

    1.11. Apache License Version 2.0, January 2004 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxvii 1.12...

Global site tag (gtag.js) - Google Analytics