您的位置:首页 > 其它

sysctl.conf的优化

2010-11-18 18:44 155 查看
内核参数sysctl.conf的优化
安装的Centos5.5_x86_64原来的sysctl.conf如下
#cat /etc/sysctl.conf |grep -v '^$' |grep -v '#'
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 4294967295
kernel.shmall = 268435456
在最后面添加如下参数
fs.file-max = 6553600
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 1024 65536
net.core.rmem_default = 16777216
net.core.rmem_max=16777216
net.core.wmem_default = 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 = 15
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_tw_recycle = 1
net.core.netdev_max_backlog = 30000
net.ipv4.tcp_no_metrics_save=1
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 8000
net.ipv4.tcp_max_syn_backlog = 8000
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2

运行sysctl -p,使配置生效
这里的"fs.file-max = 6553600"其实是由"fs.file-max = 512 * PROCESSES"得到的,我们指定PROCESSES的值为12800,即为"fs.file-max =512 *12800"。
kernel.shmmax:表示单个共享内存段的最大值,以字节为单位,此值一般为物理内存的一半,不过大一点也没关系,这里设定的为4GB,即"4294967295/1024/1024/1024=4G"
kernel.shmmni:表示单个共享内存段的最小值,一般为4kB,即4096bit
kernel.shmall:表示可用共享内存的总量,单位是页,在32位系统上一页等于4kB,也就是4096字节
fs.file-max:表示文件句柄的最大数量。文件句柄表示在Linux系统中可以打开的文件数量。
ip_local_port_range:表示端口的范围,为指定的内容。
kernel.sem:表示设置的信号量,这4个参数内容大小固定。
net.core.rmem_default:表示接收套接字缓冲区大小的缺省值(以字节为单位)。
net.core.rmem_max :表示接收套接字缓冲区大小的最大值(以字节为单位)
net.core.wmem_default:表示发送套接字缓冲区大小的缺省值(以字节为单位)。
net.core.wmem_max:表示发送套接字缓冲区大小的最大值(以字节为单位)。
net.ipv4.tcp_fin_timeout: 减少处于FIN-WAIT-2连接状态的时间,使系统可以处理更多的连接
net.ipv4.tcp_keepalive_time当keepalive打开的情况下,TCP发送keepalive消息的频率。
net.ipv4.tcp_tw_recycle加速TIME-WAIT sockets回收
net.core.netdev_max_backlog每个网络接口接收数据包的速率比内核处理这些包的速率快时,允许送到队列的数据包的最大数目
net.ipv4.tcp_no_metrics_save
net.core.somaxconn系统同时发起连接的tcp连接
net.ipv4.tcp_max_orphans系统所能处理不属于所有进程的TCP sockets最大数量
net.ipv4.tcp_max_syn_backlog对于那些依然还未获得客户端确认的连接请求?需要保存在队列中最大数目(默认1024),增加此参数能够比较有效的缓解小规模的SYN Flood攻击
net.ipv4.tcp_synack_retries tcp第二次握手中,决定内核在放弃连接之前所送出的 SYN+ACK 数目(默认值是5)减小此参数可以防御DDOS攻击
net.ipv4.tcp_syn_retries 对于一个新建tcp连接,内核要发送多少个 SYN 连接请求才决定放弃(默认值是5)减小此参数可以防御DDOS攻击

#取消 ICMP 接受 Redirect
net.ipv4.conf.lo.accept_redirects=0
net.ipv4.conf.all.accept_redirects=0
net.ipv4.conf.eth0.accept_redirects=0
net.ipv4.conf.default.accept_redirects=0
net.ipv4.conf.lo.accept_source_route=0
net.ipv4.conf.all.accept_source_route=0
net.ipv4.conf.eth0.accept_source_route=0
net.ipv4.conf.default.accept_source_route=0
net.ipv4.conf.lo.accept_redirects=0
net.ipv4.conf.all.accept_redirects=0
net.ipv4.conf.eth0.accept_redirects=0
net.ipv4.conf.default.accept_redirects=0
net.ipv4.conf.lo.secure_redirects=0
net.ipv4.conf.all.secure_redirects=0
net.ipv4.conf.eth0.secure_redirects=0
net.ipv4.conf.default.secure_redirects=0
net.ipv4.conf.lo.send_redirects=0
net.ipv4.conf.all.send_redirects=0
net.ipv4.conf.eth0.send_redirects=0
net.ipv4.conf.default.send_redirects=0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: