In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge about "how to achieve the configuration of the maximum number of high concurrent socket connections under Linux". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
[Appeal Scene]
Linux operating system, whether writing client programs or server programs, when processing high concurrent TCP connections, the maximum number of concurrent connections is limited by the number of files that the system can open simultaneously for a single user process (because the system creates a socket handle for each TCP connection, and each socket handle is also a file handle).
This document is mainly on the file number concurrent limit to do modification.
[Configuration method]
1. Modify the limit on the number of files that can be opened by the user process, as shown in the figure:
Description:
ulimit -n: View the limit on the number of files the current system allows the current user process to open.
Default is 1024: indicates that each process of the current user is allowed to open up to 1024 files simultaneously.
Of these 1024 files, standard input, standard output, standard error, server listening socket, etc. that are open by each process have to be removed, leaving only the number of files available for client socket connections.
1024-10=1014 or so, that is, Linux-based programs allow up to 1014 concurrent TCP connections at the same time.
(1) Modify the Linux system to open soft and hard restrictions for users, as shown in the figure:
vim /etc/security/limits.conf
Add root soft nofile 1921
root hard nofile 1921
Note: root represents the limit on the number of files opened by root user. You can use "*" to represent all users soft and hard to specify the soft limit or hard limit to be modified. 1921 Specify the new limit for modification, which is the maximum number of open files (soft limit must be less than or equal to hard limit)
(2) Modify the/etc/pam.d/login file, as shown in the figure:
Add: session required/lib/security/pam_limits.so
Note: Linux should call the pam_limits.so module after the user logs in to set the maximum number of resources that the system can use for the user (including the maximum number of files that the user can open).
The pam_limits.so module reads these limits from the/etc/security/limits.conf file
(3) Check linux system-level maximum number of open files limit cat /proc/sys/fs/file-max, as shown in the figure:
Note: This means that the linux system allows up to 96854 files to be opened at the same time (including the sum of the number of files opened by all users). It is a hard limit at the linux system level. The number of files opened by all users must not exceed this value. Generally, this value is not modified. If you want to modify it, the command is vim /etc/rc.local.
(4) Add: echo value> /proc/sys/fs/file-max, modify and restart the system, and execute ulimit -n after restarting to check, as shown in the figure:
(5) If the value checked by executing ulimit -n after restart is still less than the maximum value after modification above, it may be that the number of files that users can open at the same time has been limited by using ulimit -n command in user login script/etc/profile. ulimit -n can only be found in/etc/profile to limit the maximum number of files that users can open at the same time. You can delete or modify the value. Restart the system.
(6) The above operation can solve the system limit on the number of open files handled by high-concurrency TCP connections.
Sometimes, even though the system limit on the number of simultaneous open files is lifted, there is still a phenomenon that when the number of concurrent TCP connections increases to a certain number, new TCP connections can no longer be created.
2. Linux network kernel has restrictions on the range of local port numbers. For example, the current system kernel limits the range of local port numbers to 1024-32768. When there are a large number of TCP client connections at the same time, since each TCP client has to occupy a unique local port number, if the range of TCP port numbers is insufficient, it will prompt: can't assign requested address. This is because the default local port number range set during kernel compilation is too small.
Modify: /etc/sysctl.conf
Add: net.ipv4.ip_local_port_range = 1024 65535 (max value should be less than or equal to 65535)
Execution: sysctl -p, if no error is reported, the setting is successful, and the displayed content includes the content in the figure:
The above is a single process can open up to 63000 TCP client connections at the same time.
"Linux how to achieve high concurrency socket maximum number of connections configuration" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.