首页 男生 其他 跟老男孩学Linux运维:Web集群实战

3.4.12 Linux服务器内核参数优化

  您可以在百度里搜索“跟老男孩学Linux运维:Web集群实战 艾草文学(www.321553.xyz)”查找最新章节!

  

  3.4.12 Linux服务器内核参数优化

  所谓Linux服务器内核参数优化,主要是指在Linux系统中针对业务服务应用而进行的系统内核参数调整,优化并无一定的标准。下面以生产环境下Linux常见的内核优化为例进行讲解,仅供大家参考。

  优化方法是执行vi/etc/sysctl.conf命令到文件结尾,然后拷贝如下内容并保存。

  net.ipv4.tcp_fin_timeout = 2 net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_syncookies = 1net.ipv4.tcp_keepalive_time = 600 net.ipv4.ip_local_port_range =4000 65000 net.ipv4.tcp_max_syn_backlog = 16384net.ipv4.tcp_max_tw_buckets = 36000 net.ipv4.route.gc_timeout = 100net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_synack_retries = 1net.core.somaxconn = 16384 net.core.netdev_max_backlog = 16384net.ipv4.tcp_max_orphans = 16384#以下参数是对iptables防火墙的优化,防火墙不开会提示,可以忽略不理 net.nf_conntrack_max =25000000 net.netfilter.nf_conntrack_max = 25000000net.netfilter.nf_conntrack_tcp_timeout_established = 180net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120

  将上面的内核参数值加入/etc/sysctl.conf文件中,然后执行如下命令使之生效:

  [root@www ~]# sysctl -p net.ipv4.ip_forward = 0net.ipv4.conf.default.rp_filter = 1net.ipv4.conf.default.accept_source_route = 0 kernel.sysrq = 0kernel.core_uses_pid = 1 net.ipv4.tcp_syncookies = 1 error:"net.bridge.bridge-nf-call-ip6tables" is an unknown key error:"net.bridge.bridge-nf-call-iptables" is an unknown key error:"net.bridge.bridge-nf-call-arptables" is an unknown keykernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax =68719476736 kernel.shmall = 4294967296 net.ipv4.tcp_fin_timeout = 2net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_keepalive_time = 600net.ipv4.ip_local_port_range = 4000 65000net.ipv4.tcp_max_syn_backlog = 16384 net.ipv4.tcp_max_tw_buckets =36000 net.ipv4.route.gc_timeout = 100 net.ipv4.tcp_syn_retries = 1net.ipv4.tcp_synack_retries = 1 net.core.somaxconn = 16384net.core.netdev_max_backlog = 16384 net.ipv4.tcp_max_orphans =16384 net.nf_conntrack_max = 25000000net.netfilter.nf_conntrack_max = 25000000 error:"net.netfilter.nf_conntrack_tcp_timeout_established" is an unknownkey error: "net.netfilter.nf_conntrack_tcp_timeout_time_wait" is anunknown key error:"net.netfilter.nf_conntrack_tcp_timeout_close_wait" is an unknownkey error: "net.netfilter.nf_conntrack_tcp_timeout_fin_wait" is anunknown key

  如果是在CentOS6环境中,必须开启ip6tables服务才不会出现上面所示的报错,其实报错也可以暂时不理,这是针对防火墙的优化,而此时防火墙并没有开启,将来开启了就没问题了。

  sysctl.conf内核文件中的参数含义见表3-6。

  表3-6 sysctl.conf内核文件中常用参数含义

  网络状态说明及优化命令和优化细节参考资料请看:

  http://yangrong.blog.51cto.com/6945369/1321594 ←老男孩教育的优秀学生博文http://oldboy.blog.51cto.com/2561410/1336488 跟老男孩学Linux运维:Web集群实战

目录
设置
手机
书架
书页
评论