一、系统参数调优
打开文件 /etc/sysctl.conf
############ # 一般服务器调整 # ############ #最大连接数 net.core.somaxconn = 32768 #内存分配策略 1表示内核允许分配所有的物理内存,而不管当前的内存状态如何 vm.overcommit_memory = 1 #修改消息队列长度 kernel.msgmnb = 65535 kernel.msgmax = 65535 #所能接受SYN同步包的最大客户端数量,即半连接上限 net.ipv4.tcp_max_syn_backlog = 65535 #允许系统打开的端口范围 net.ipv4.ip_local_port_range = 10240 61440 #当keepalive 起用的时候,TCP 发送keepalive 消息的频度。缺省是2小时,单位秒 net.ipv4.tcp_keepalive_time = 1800 #关闭ipv6 net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 ############################################ # 无状态服务器调整 , 可能会使连接丢失 , 比如网页session # # 不适合需要登录的服务器场景 , 但是适合高并发服务器,比如纯redis服务器 # ############################################ #启用timewait 快速回收 , 服务器不要开启 net.ipv4.tcp_tw_recycle = 1 #开启重用 , 允许将TIME-WAIT sockets 重新用于新的TCP 连接 , 服务器不要开启 net.ipv4.tcp_tw_reuse = 1 #CLOSE_WAIT超时时间 net.ipv4.tcp_fin_timeout = 5 #当keepalive 起用的时候,TCP 发送keepalive 消息的频度。缺省是2 小时,单位秒 , 指的是60秒检查一次tcp是否存活 net.ipv4.tcp_keepalive_time = 60 ###########参数复制版############ net.core.somaxconn = 32768 vm.overcommit_memory = 1 kernel.msgmnb = 65535 kernel.msgmax = 65535 net.ipv4.ip_local_port_range = 10240 61440 net.ipv4.tcp_keepalive_time = 60 net.ipv4.tcp_tw_recycle = 0 net.ipv4.tcp_tw_reuse = 0 net.ipv4.tcp_fin_timeout = 5 net.ipv4.tcp_max_syn_backlog = 65535 net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 ##############################
二、使配置生效(不需要重启)
#执行以下命令使配置生效 sysctl -p
#其他参考的例子 net.ipv4.tcp_syncookies = 1 net.ipv4.ip_local_port_range = 32768 61000 net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_timestamps = 1 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_tw_recycle = 0 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_max_tw_buckets = 6000 net.ipv4.tcp_max_orphans = 3276800 net.ipv4.tcp_max_syn_backlog = 262144 net.ipv4.tcp_keepalive_intvl = 30 net.ipv4.tcp_keepalive_probes = 3 net.ipv4.tcp_keepalive_time = 1800 net.ipv4.tcp_keepalive_probes = 5 net.ipv4.tcp_keepalive_intvl = 15 net.core.netdev_max_backlog = 262144 net.core.somaxconn = 65535 vm.overcommit_memory = 1 net.core.rmem_default = 8388608 net.core.wmem_default = 8388608 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 net.ipv4.tcp_mem = 94500000 915000000 927000000 net.ipv4.tcp_rmem = 4096 87380 16777216 net.ipv4.tcp_wmem = 4096 16384 16777216 #net.netfilter.nf_conntrack_max=655350 #net.netfilter.nf_conntrack_tcp_timeout_established=1200 net.ipv4.icmp_echo_ignore_broadcasts = 1 net.ipv4.icmp_ignore_bogus_error_responses = 1 kernel.sysrq = 0 kernel.core_uses_pid = 1 kernel.msgmnb = 65536 kernel.msgmax = 65536