http://finance.qq.com/simulatestock/index.htm
#Avoid a smurf attack
net.ipv4.icmp_echo_ignore_broadcasts = 1
#Turn on protection for bad icmp error messages
net.ipv4.icmp_ignore_bogus_error_responses = 1
#Turn on syncookies for SYN flood attack protection
net.ipv4.tcp_syncookies = 1
#Turn on and log spoofed,source routed,and redirect packets
net.ipv4.conf.all.log_martians = 1
net.ipv4.conf.default.log_martians = 1
#No source routed packets here
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
#Turn on reverse path filtering
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
#Make sure no one can alter the routing tables
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
#Don't act as a router
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
#Turn on execshild
kernel.exec-shield = 1
kernel.randomize_va_space = 1
#Tuen IPv6
net.ipv6.conf.default.router_solicitions = 0
net.ipv6.conf.default.accept_ra_rtr_pref = 0
net.ipv6.conf.default.accept_ra_pinfo = 0
net.ipv6.conf.default.accept_ra_defrtr = 0
net.ipv6.conf.default.autoconf = 0
net.ipv6.conf.default.dad_transmits = 0
net.ipv6.conf.default.max_addresses = 1
#Optimization for port usefor LBs
#Increase system file descriptor limit
fs.file-max = 65535
#Allow for more PIDs(to reduce rollover problems);may break some programs 32768;
kernel.pid_max = 65535
#Increase system IP port limits
net.ipv4.ip_local_port_range = 2000 65000
#Increase TCP max buffer size setable using setsockopt()
net.ipv4.tcp_rmem = 4096 87380 8388608
net.ipv4.tcp_wmem = 4096 87380 8388608
#Increase Linux auto tuning TCP buffer limits
#min,default,and max number of bytes to use
#set max to at least 4MB,or higher if you use very high BDP paths
#Tcp Windows etc
net.core.rmem_max = 8388608
net.core.wmem_max = 8388608
net.core.netdev_max_backlog = 5000
net.ipv4.tcp_window_scaling = 1
生产环境内核参数
net.ipv4.tcp_fin_timeout = 2
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_keepalive_time = 600
net.ipv4.ip_local_port_range = 4000 65000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_max_tw_buckets = 36000
net.ipv4.route.gc_timeout = 100
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.core.netdev_max_backlog = 16384
net.ipv4.tcp_max_orphans = 16384
#以下参数是对iptables防火墙的优化,防火墙不开会提示,可以忽略不理。
net.ipv4.ip_conntrack_max = 25000000
net.ipv4.netfilter.ip_conntrack_max = 25000000
net.ipv4.netfilter.ip_contrack_tcp_timeout_established=180
net.ipv4.netfilter.ip_contrack_tcp_timeout_time_wait=120
net.ipv4.netfilter.ip_contrack_tcp_timeout_close_wait=60
net.ipv4.netfilter.ip_contrack_tcp_timeout_fin_wait=120
#将上面的内核参数加入/etc/sysctl.conf文件中,然后执行如下命令使之生效:sysctl -p
nginx服务器内核参数解释说明
net.ipv4.tcp_fin_timeout = 2
#表示如果套接字由本端要求关闭,这个参数决定了它保持在FIN-WAIT-2状态的时间,默认值是60秒。该参数对应系统路径为/proc/sys/net/ipv4/tcp_fin_timeout 60
net.ipv4.tcp_tw_reuse = 1
#表示开启重用。允许将TIME-WAIT- sockets重新用于新的TCP连接,默认值为0表示关闭。该参数对应系统路径为 /proc/sys/net/ipv4/tcp_tw_reuse 0
net.ipv4.tcp_tw_recycle = 1
#表示开启TCP连接中TIME-WAIT sockets的快速回收。该参数对应系统路径为/proc/sys/net/ipv4/tcp_tw_recycle默认为0,表示关闭
提示:reuse和recycle两个参数为了防止生产环境下web,squid等time_wait过设置的。
net.ipv4.tcp_syncookies = 1
#表示开启SYN Cookies功能。当出现SYN等待队列溢出时,启用cookies来处理,可防范少量SYN***,centos5系列默认值为1,表示开启,因此这个参数也可以不添加,该参数对应系统路径为:/proc/sys/net/ipv4/tcp_syncookies默认为1
net.ipv4.tcp_keepalive_time = 600
#表示当keepalive起用的时候,TCP发送keepalive消息的频度。缺省是2小时,为10分钟。该参数对应系统路径为: /proc/sys/net/ipv4/tcp_keepalive_time默认为7200和
net.ipv4.ip_local_port_range = 4000 65000
#选项用来设定允许系统打开的端口范围。即用于向外连接的端口范围。
该参数对应系统路径为:/proc/sys/net/ipv4/ip_local_port_range 42768 61000
net.ipv4.tcp_max_syn_backlog = 8192
#表示SYN队列的长度,默认为1024,加大队列长度为8192,可以容纳更多等待连接的网络连接数。选项为服务器端用于记录那些尚未收到客户端确认信息的连接请求的最大值。
该参数对应系统路径为:/proc/sys/net/ipv4/tcp_max_syn_backlog
net.ipv4.tcp_max_tw_buckets = 30000
#表示系统同时保持TIME_WAIT套接字的最大数量,如果超过这个数字TIME_WAIT套接字将立刻被清除并打印警告信息。默认为180000,对于Apache、Nginx等服务器来说可以调整低一点:如:改为5000-30000,不同的服务器也可以给大疑点,比如lvs,squid。
以上几行的参数可以很好的减少TIME_WAIT套接字数量,但是对于squid,效果缺不大。
此项参数可以控制TIME_WAIT套接字的最大数量,避免squid服务器被大量TIME_WAIT套接字托死。该参数对应系统路径为:/proc/sys/net/ipv4/tcp_max_tw_bucke
net.ipv4.tcp_synack_retries
#参数的值决定了内核放弃连接之前发送SYN+ACK包的数量
该参数对应系统路径为:/proc/sys/net/ipv4/tcp_synack_retries默认值为5。
net.ipv4.tcp_syn_retries
#表示在内核放弃连接之前发送SYN包的娄量。该参数对应系统路径为/proc/sys/net/ipv4/tcp_syn_retries 5
net.ipv4.tcp_max_orphans
#选项用于设定系统中最多有多少个TCP套接字不被关联到任何一个用户文件句上。如果超过这个数字,孤立连接将立即被抚慰并打印出警告信息。这个限制只是为了停止简单的Dos***。不能过分依靠这个限制甚至人为减小这个值,更多的情况的增加这个值。该参数对应系统路径为:/proc/sys/net/ipv4/tcp_max_orphans 65536
net.core.somaxconn
#选项默认值是128,这个参数用于调节系统同时发起的tcp连接数,在高并发的请求中,默认的值可能会导致链接超时或者重传,因此,需要结合并发请求数来调节此值
该参数对应系统路径为:/proc/sys/net/core/somaxconn 128
net.core.netdev_max_backlog
#选项表示当每个网络接口接收数据包的速率比内核处理这些包的速率快时,允许传送到队列的数据包的最大数目。
该参数对应系统路径为:/proc/sys/net/core/netdev_max_backlog 默认值1000