High-concurrency Linux kernel Network Parameter Tuning

Source: Internet
Author: User
Adjust Linux (ubuntu8.0.4) kernel parameters to meet high-concurrency access and solve a large number of time_wait and SYN Attacks:
1 sudo VI/etc/sysctl. conf
Edit and add at the bottom:
Net. ipv4.tcp _ fin_timeout = 30
Net. ipv4.tcp _ keepalive_time = 1200
Net. Route 4.route. gc_timeout = 100
Net. ipv4.ip _ local_port_range = 1024 65000
Net. ipv4.tcp _ tw_reuse = 1
Net. ipv4.tcp _ tw_recycle = 1
Net. ipv4.tcp _ syn_retries = 1
Net. ipv4.tcp _ synack_retries = 1
Net. ipv4.tcp _ max_syn_backlog = 262144
Net. Core. netdev_max_backlog = 262144
Net. Core. somaxconn = 262144
Net. ipv4.tcp _ mem = 94500000 915000000 927000000
Save and exit
2 sudo/sbin/sysctl-P
Take effect immediately (in practice, if it cannot take effect immediately, restart the host to take effect)

Use the following command to monitor connections in different States:
1 netstat-N | awk '/^ TCP/{++ s [$ NF]} end {for (a in S) print a, s [a]}' 
2 CAT/proc/NET/sockstat 
3. check whether any exception log exists: dmesg 
4. view the number of current IP addresses and the number of connections per IP Address: 
Netstat-an | grep 80 | awk '{print $5}' | awk 'begin {FS = ": "} NF = 2 {print $1} NF = 5 {print $4} '| sort | uniq-c | sort-n

Default Value Recovery:
Net. ipv4.tcp _ fin_timeout = 60
Net. ipv4.tcp _ keepalive_time = 7200
Net. Route 4.route. gc_timeout = 300
Net. ipv4.ip _ local_port_range = 32768 61000
Net. ipv4.tcp _ tw_reuse = 0
Net. ipv4.tcp _ tw_recycle = 0
Net. ipv4.tcp _ syn_retries = 5
Net. ipv4.tcp _ synack_retries = 5
Net. ipv4.tcp _ max_syn_backlog = 1024
Net. Core. netdev_max_backlog = 1000
Net. Core. somaxconn = 128
Net. ipv4.tcp _ mem = 853440 1137920 1706880

In the actual production environment, if the number of connections for a single machine reaches, nginx works normally.

Server optimization recommendationsArticle: Http://blog.sina.com.cn/s/blog_466c66400100bi2n.html ~ Type = v5_one & label = rela_prevarticle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.