端口重用
由于TCP客户端通讯结束后,主动发起关闭连接,会进入到TIME_WAIT状态。如果不进行回收,端口会占用60秒或更久,而动态端口数量有限(最多60000多个),耗尽后发起连接会报Cannot assign Requested Address。
修改linux机器上的配置:
echo "net.ipv4.tcp_tw_reuse = 1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_timestamp = 1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_tw_recycle = 0" >> /etc/sysctl.conf
echo "net.ipv4.ip_local_port_range = 10000 60999" >> /etc/sysctl.conf
echo "net.ipv4.tcp_max_tw_buckets = 20000" >> /etc/sysctl.conf
systemctl -p