Linux下高并发Socket连接的优化

1、打开文件优化

#对当前shell
ulimit -n 102400
echo "ulimit -n 102400" >> ~/.bashrc

#针对所有用户
sudo vim /etc/security/limits.conf
* soft nofile 102400
* hard nofile 102400

#针对系统
cat /proc/sys/fs/file-max
echo 1024000 > /proc/sys/fs/file-max

2、修改网络内核对TCP的限制

#修改内核网络参数
sudo vim /etc/sysctl.conf
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.ip_conntrack_max = 10240
#生效
sudo sysctl -p

3、两个回收

#修改内核网络参数
sudo vim /etc/sysctl.conf
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
#生效
sudo sysctl -p

Leave a Reply

Your email address will not be published.