一、优化最大文件打开数限制,默认1024,建议8192,如果需要还可以更大
1)对所有用户进行优化
#vi /etc/profile
在最后加入
ulimit -SHn 8192
#source /etc/profile
2)对普通用户进行优化
用上述方法也可以修改一般用户的.bash_profile文件
ulimit -n查看参数
注:ulimit –u优化最大进程数,建议在10000以上,如果大于10000则不需要优化,优化方法同上。
二、TCP优化
1)优化网络设备接收队列,默认300(rhel9)或1000(rhel5)建议3000
执行下面命令:
# echo "3000" > /proc/sys/net/core/netdev_max_backlog
#cat /proc/sys/net/core/netdev_max_backlog
3000
2)减少处于FIN-WAIT-2连接状态的时间,使系统可以处理更多的连接。默认值180,建议值30
# echo "30" > /proc/sys/net/ipv4/tcp_fin_timeout
#cat /proc/sys/net/ipv4/tcp_fin_timeout
30
3)减少TCP KeepAlive连接侦测的时间,使系统可以处理更多的连接。默认值7200(2小时),建议值1800(30分钟)
#echo "1800" > /proc/sys/net/ipv4/tcp_keepalive_time
#cat /proc/sys/net/ipv4/tcp_keepalive_time
1800
4)增加TCP SYN队列长度,使系统能处理更多的并发连接。
# echo "8192" > /proc/sys/net/ipv4/tcp_max_syn_backlog
# more /proc/sys/net/ipv4/tcp_max_syn_backlog
8192
三、优化缓冲区
1) 优化系统套接字缓冲区
net.core.rmem_max=16777216(以字节为单位)
net.core.wmem_max=16777216(以字节为单位)
# echo "16777216" > /proc/sys/net/core/rmem_max
# echo "16777216" > /proc/sys/net/core/wmem_max
# more /proc/sys/net/core/rmem_max
16777216
# more /proc/sys/net/core/wmem_max
16777216
2) 优化TCP接收/发送缓冲区
net.ipv4.tcp_rmem=4096 87380 16777216
net.ipv4.tcp_wmem=4096 65536 16777216
# echo "4096 87380 16777216" > /proc/sys/net/ipv4/tcp_rmem
# echo "4096 87380 16777216" > /proc/sys/net/ipv4/tcp_wmem
# more /proc/sys/net/ipv4/tcp_rmem
4096 87380 16777216
# more /proc/sys/net/ipv4/tcp_wmem
4096 87380 16777216
详细配置含义参照:http://www.360doc.com/content/14/0606/16/3300331_384326124.shtml
四、修改tcp timewait释放时间
[root@localhost ~]# vi /etc/sysctl.conf
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 30
net.ipv4.tcp_fin_timeout = 15
[root@localhost ~]# sysctl -a | grep fin
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 30
net.ipv4.tcp_fin_timeout = 15
[root@localhost ~]# sysctl -p
配置文件
[wyx@datacenter1 logs]$ vi /etc/sysctl.conf # Kernel sysctl configuration file for Red Hat Linux # # For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and # sysctl.conf(5) for more details. # # Use '/sbin/sysctl -a' to list all possible parameters. # Controls IP packet forwarding net.ipv4.ip_forward = 0 # Controls source route verification net.ipv4.conf.default.rp_filter = 1 # Do not accept source routing net.ipv4.conf.default.accept_source_route = 0 # Controls the System Request debugging functionality of the kernel kernel.sysrq = 0 # Controls whether core dumps will append the PID to the core filename. # Useful for debugging multi-threaded applications. kernel.core_uses_pid = 1 # Controls the use of TCP syncookies net.ipv4.tcp_syncookies = 1 # Controls the default maxmimum size of a mesage queue kernel.msgmnb = 65536 # Controls the maximum size of a message, in bytes kernel.msgmax = 65536 # Controls the maximum shared segment size, in bytes kernel.shmmax = 68719476736 # Controls the maximum number of shared memory segments, in pages kernel.shmall = 4294967296 net.ipv4.ip_local_port_range = 5000 65000 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 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_max_tw_buckets = 6000