In Linux, the maximum number of TCP connections is limited by Kernel and Ulimit. 1. File limit Modification 1. user-level view Linux system user maximum open file limit: # ulimit-n1024 (1) vi/etc/security/limits. confapachesoftnofile10240apachehardnofile10240 where apache specifies the limit on the number of files opened by the user to be modified. Available '*
In Linux, the maximum number of TCP connections is limited by Kernel and Ulimit.
I. Modify the limit on the number of files
1. user level
View the maximum file opening limit for Linux users:
# Ulimit-n
1024
(1) vi/etc/security/limits. conf
Apache soft nofile 10240
Apache hard nofile 10240
Apache specifies the user's limit on the number of files to be modified.
'*' Can be used to modify the limits of all users. soft or hard indicates whether to modify the soft limit or hard limit. 10240 indicates the new limit value to be modified, that is, the maximum number of opened files (note that the soft limit value must be smaller than or equal to the hard limit ).
(2) vi/etc/pam. d/login
Session required/lib/security/pam_limits.so
This tells Linux that after the user completes system logon, you should call the pam_limits.so module to set the maximum number of resources that the system can use (including the maximum number of files that the user can open ).
The pam_limits.so module reads the configuration from the/etc/security/limits. conf file to set these limits.
2. Linux system level
View the Linux system's hard limit on the number of files opened at the same time:
# Sysctl-a | grep file-max
Fs. file-max = 50542
This indicates that this Linux system allows a maximum of 50542 files to be opened simultaneously (that is, including the total number of files opened by all users), which is a Linux system-level hard limitation, the number of opened files for all users cannot exceed this value.
Generally, this system-level hard limit is the optimal maximum number of files that can be opened at the same time based on the system hardware resources when the Linux system is started.
(1) vi/etc/sysctl. conf
Fs. file-max = 505420
Effective immediately:
# Sysctl-p
Ii. Modify network port restrictions
View the maximum number of TCP connections tracked in Linux:
# Sysctl-a | grep ipv4.ip _ conntrack_max
Net. ipv4.ip _ conntrack_max = 16376
This indicates that the system will limit the maximum number of TCP connections tracked by 16376 by default.
View the Linux port range:
# Sysctl-a | grep ipv4.ip _ local_port_range
Net. ipv4.ip _ local_port_range = 32768 61000
Note:
Each TCP client connection occupies a unique local port number (this port number is in the range of the local port number of the system). If the existing TCP client connection has occupied all the local port numbers. A new TCP connection cannot be created.
(1) vi/etc/sysctl. conf
Net. ipv4.ip _ local_port_range = 1024 65000
Net. ipv4.ip _ conntrack_max = 20480
If the preceding port range is used, a single process can establish a maximum of 60000 TCP client connections at the same time.
If the preceding parameters are used, a single process can establish a maximum of 20000 TCP client connections at the same time.
Note:
Set the number of files simultaneously opened by apache users to 10240;
Set the number of files that can be opened at the same time in Linux to 505420 (must be greater than the limit on the number of files simultaneously opened by users );
Set the maximum number of TCP connections tracked in Linux to 20480 (however, it is recommended to set it to 10240; because the number of simultaneously opened files for apache users is already limited to 10240; and smaller values can save memory );
Set the port range of the linux system to 1024 ~ 65000 (more than 60000 connections are supported, which is not recommended to be modified; more than 20000 connections are supported by default );
Based on the above four points, the number of TCP connections is limited to 10140.
These 10240 files also need to remove the standard input, standard output, standard errors, server listening socket, unix domain socket for inter-process communication, and other files that each process must open.
Therefore, you only need to adjust the ulimit parameter when adjusting the number of TCP connections.
The number of files opened by system hardware at the same time does not become a bottleneck (the system automatically calculates based on hardware performance ).
Red Hat Enterprise Linux 7 Users download http://www.linuxidc.com/Linux/2014-06/102998.htm now
RHEL 6.3 installation tutorial graphic details http://www.linuxidc.com/Linux/2014-05/101845.htm
Red Hat Linux 7.0 installation illustrationHttp://www.linuxidc.com/Linux/2014-06/103190.htm
For more information about RedHat, see RedHat topic page http://www.linuxidc.com/topicnews.aspx? Tid = 10
This article permanently updates the link address: Http://www.linuxidc.com/Linux/2014-07/104153.htm