#修改/etc/security/limits.conf文件对用户打开文件数的软限制和硬限制:
soft nofile 65535
hard nofile 65535
#修改/etc/pam.d/login文件,在文件中添加如下行:
session required /lib/security/pam_limits.so #32位系统
session required /lib64/security/pam_limits.so #如果是64bit系统的话,cat /proc/version 查看是不是有X64字样
#修改/etc/sysctl.conf文件,添加如下行(修改网络内核对TCP连接的有关限制):
net.ipv4.ip_local_port_range = 1024 65535
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 = 0
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
/sbin/sysctl -p /etc/sysctl.conf #执行如下命令(使上述设置生效):
/sbin/sysctl -w net.ipv4.route.flush=1 #执行如下命令(使上述设置生效):
echo ulimit -HSn 65536 >> /etc/rc.local
echo ulimit -HSn 65536 >>/root/.bash_profile
ulimit -HSn 65536
reboot #确认可以重启则重启系统
原文