Performance tuning of Linux makes your server more powerful! Increase TCP connection limit

Time:2020-8-14

In Linux system, there is a maximum limit on the number of TCP connections, that is, the maximum number of file descriptions that can be opened by a process
ulimit -n

The article is updated every week. Your “three companies” are my greatest affirmation. WeChat can search the public for the first time to read the official account of “backend Technology School” (usually one to two updates earlier than blogs).

TCP connection limit

The server with high load can reasonably plan the user resources and system resources by modifying the ulimit parameter.

User level

Modify the maximum number of connections

  • Modification of system parameters

ulimit -SHn 65535

-H hard limit is actual limit, and – s soft limit is warning limit
If you run the ulimit command without adding sh, the two parameters change together

  • Modification of PAM module configuration
  1. session required /lib/security/pam_limits.so
  2. Modify / etc / security/ limits.conf Here’s an example

    * soft nofile 65536
    * hard nofile 65536
    *On behalf of all users, you can also specify a user such as root

Confirm whether the modification is effective

After modification, although the command view is the modified value, the TCP number of process connections is still the system default 1024, resulting in access denial

View the actual maximum number of connections for the process

Cat / proc / process PID / limits
Max open files is the actual value of the current process

System level

View the total system open file limit

cat /proc/sys/fs/file-max

To modify it, you can rc.local plus

Echo what you want > / proc / sys / FS / file Max


more

You can search the official account of WeChat for “back end technology school” to reply to “information”. Articles are updated every week, see you next time!