对于不同的操作系统,通过调优内核参数,可以有效的提高服务器的性能。
1 | vim /etc/sysctl.conf
|
1 2 3 4 5 6 7 8 9 10 | net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_keepalive_time = 60 net.ipv4.tcp_fin_timeout = 1 net.ipv4.tcp_max_tw_buckets = 5000 net.ipv4.ip_local_port_range = 1024 65500 net.core.somaxconn = 65535 net.ipv4.tcp_max_syn_backlog = 262144 net.core.netdev_max_backlog = 262144 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 |
Linux内核参数 |
参数定义 |
当前值 |
默认值 |
---|---|---|---|
net.ipv4.tcp_tw_reuse |
将TIME-WAIT sockets重新用于新的TCP连接。1表示开启;0表示关闭。 |
1 |
0 |
net.ipv4.tcp_keepalive_time |
TCP发送keepalive探测消息的间隔时间(秒),用于确认TCP连接是否有效。 |
60 |
7200 |
net.ipv4.tcp_fin_timeout |
socket保持在FIN_WAIT_2状态的最大时间。 |
1 |
60 |
net.ipv4.tcp_max_tw_buckets |
减少TIME_WAIT连接数,避免过多TIME_WAIT连接占用网络资源导致新建连接资源紧张,时延增加。 |
5000 |
262144 |
net.ipv4.ip_local_port_range |
增加可用端口范围,避免大量连接占用端口时,新建连接不断寻找可用端口而导致的性能跳水。 |
1024 65500 |
32768 61000 |
net.core.somaxconn |
定义了操作系统中每一个端口最大的监测队列的长度,属于全局的参数。 |
65535 |
128 |
net.ipv4.tcp_max_syn_backlog |
表示SYN队列的长度,加大队列长度可以容纳更多等待连接的网络连接。 |
262144 |
1024 |
net.core.netdev_max_backlog |
当每个网络接口接收数据包的速率比内核处理这些包的速率快时,允许送到队列的数据包的最大数目。 |
262144 |
1000 |
net.core.rmem_max |
操作系统套接字读最大缓冲区。 |
16777216 |
131071 |
net.core.wmem_max |
操作系统套接字写最大缓冲区,增加buffer大小,避免大量新建连接导致buffer溢出,出现无法建立连接情况。 |
16777216 |
131071 |
net.nf_conntrack_max |
最大跟踪连接数。 |
0 |
65536 |
1 2 | net.netfilter.nf_conntrack_max=0 net.nf_conntrack_max=0 |
1 | /sbin/sysctl -p
|