linux修改TCP连接数

我的系统为:centos 6.4 64位,现在与大爱分享一下修改TCP连接数(centos实测) !

  一、 文件数限制修改

(1) vi /etc/security/limits.conf

在末尾追加

* soft nofile 10240

* hard nofile 10240

(2) vi /etc/pam.d/login

在末尾追加

session required /lib/security/pam_limits.so

      (3)

        net.nf_conntrack_max=6553600

将参数65536改为6553600

       vim /proc/sys/net/nf_conntrack_max

  二、 网络端口限制修改

vi /etc/sysctl.conf

      

net.ipv4.ip_conntrack_max = 10240
net.ipv4.ip_local_port_range = 1024 6553

内核参数sysctl.conf的优化
/etc/sysctl.conf 是用来控制linux网络的配置文件,对于依赖网络的程序(如web服务器和cache服务器)非常重要

           

net.ipv4.ip_local_port_range = 1024 65536
net.ipv4.ip_conntrack_max = 10240
net.core.rmem_max=16777216
net.core.wmem_max=16777216
net.ipv4.tcp_rmem=4096 87380 16777216
net.ipv4.tcp_wmem=4096 65536 16777216
net.ipv4.tcp_fin_timeout = 10
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_window_scaling = 0
net.ipv4.tcp_sack = 0
net.core.netdev_max_backlog = 30000
net.ipv4.tcp_no_metrics_save=1
net.core.somaxconn = 262144
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_max_tw_buckets = 5000
     

       三、调整文件数:
       echo ulimit -HSn 65536 >> /etc/rc.local
       echo ulimit -HSn 65536 >>/root/.bash_profile

相关推荐