Reserve the ports to avoid the occupation ip_local_reserved_ports

Problem Description: business encounter this situation, when to restart the service, there is occupied port 1986 can not start, and so on have to release the port after the successful launch. Analysis: 1986 port is a client on the server selected at random source port to occupy out. solution: Use net.ipv4.ip_local_port_range parameters, planning a section of the port section reserved for port services, this approach can solve the current problem, but there is a problem, reduce the use of ports, when the server needs to consume a large amount of port numbers, then , such as anti-generation servers, there is a bottleneck. The best practice is to add to all separated by commas ip_local_reserved_ports in the service listening port, when the TCP / IP protocol stack, randomly selected from ip_local_port_range source port, the port will be excluded ip_local_reserved_ports defined, and therefore will not appear on the port is occupied service failed to start. ip_local_reserved_ports explained as follows: ip_local_reserved_ports - list of comma separated ranges Specify the ports which are reserved for known third-party applications These ports will not be used by automatic port assignments (eg when calling connect () or bind () with port number 0). . Explicit port allocation behavior is unchanged. The format used for both input and output is a comma separated list of ranges (eg "1,2-4,10-10" for ports 1, 2, 3, 4 and 10). Writing to the file will clear all previously reserved ports and update the current list with the one given in the input.
# vim /etc/sysctl.conf
net.ipv4.ip_local_reserved_ports = 1986, 11211-11220
# sysctl -p
[warning] Note: The kernel version is greater than 2.6.18-164, or do not support this argument. [/ warning] reproduced please specify from time to live operation and maintenance : http://www.ttlsa.com/html/3409.html

Reproduced in: https: //my.oschina.net/766/blog/211495

Guess you like

Origin blog.csdn.net/weixin_33978044/article/details/91493116