linux resolves high concurrent socket maximum connections limit, TCP default 1024 connections

Source: Internet
Author: User

Linux as a server system, when the socket is running high concurrent TCP programs, the connection is usually established to a certain number of cases can no longer establish a connection

I am at work, testing high concurrent TCP program (GPS server-side program), multiple tests, found each connection established to 1000 or so, can no longer establish a TCP connection, the most total Internet search, Linux system default ulimit for 1024 access users can open the maximum number of programs. Typically a port has a maximum connection of 2 to 16 square 65535

    • The first step, modify the/etc/security/limits.conf file, add the following line in the file (* Refer to the System user name), modify the Linux system on the user's number of open files soft limit and hard limit:

    

6553565535

    • In the second step, modify the/etc/pam.d/login file to add the following line to the file:

Session required/lib/security/pam_limits.so

If it is a 64bit system, it should be:
Session required/lib64/security/pam_limits.so

    • In the third step, modify the/etc/sysctl.conf file to add the following line in the file (clear the original contents of the file) (Modify the Network kernel restrictions on TCP connections):
Net.ipv4.ip_local_port_range = 1024x768 65535net.core.rmem_max=16777216net.core.wmem_max=16777216net.ipv4.tcp_rmem= 4096 87380 16777216net.ipv4.tcp_wmem=4096 65536 16777216net.ipv4.tcp_fin_timeout = 10net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_timestamps = 0net.ipv4.tcp_window_scaling = 0net.ipv4.tcp_sack = 0net.core.netdev_max_backlog = 30000net.ipv4.tcp_no_metrics_save=1net.core.somaxconn = 262144net.ipv4.tcp_syncookies = 0net.ipv4.tcp_max_orphans = 262144net.ipv4.tcp_max_syn_backlog = 262144net.ipv4.tcp_synack_retries = 2net.ipv4.tcp_syn_retries = 2

    • Fourth step, execute the following command (to make the above settings effective):

    

/sbin/sysctl-p/etc/sysctl.conf/sbin/sysctl-w net.ipv4.route.flush=1

    • Fifth step, execute the following command (Linux system optimized network must be high to allow the number of open files to support large concurrency, default 1024 is far from enough):

 

echo ULIMIT-HSN 65536 >>/etc/rc.local echo ulimit-hsn 65536 >>/root/.bash_profile ULIMIT-HSN 65536

    • Sixth step, restart the machine.

By modification, TCP can reach 20,000 connections with no problem at all

linux resolves high concurrent socket maximum connections limit, TCP default 1024 connections

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.