技术头条 - 一个快速在微博传播文章的方式     搜索本站
您现在的位置首页 --> 系统运维 --> Linux内核参数调整

Linux内核参数调整

浏览:690次  出处信息

ulimit设置

ulimit -n 要调整为100000甚至更大。 命令行下执行 ulimit -n 100000即可修改。如果不能修改,需要设置 /etc/security/limits.conf,加入

* soft nofile 262140

* hard nofile 262140

root soft nofile 262140

root hard nofile 262140

* soft core unlimited

* hard core unlimited

root soft core unlimited

root hard core unlimited


内核设置

net.unix.max_dgram_qlen = 100


swoole使用unix socket dgram来做进程间通信,如果请求量很大,需要调整此参数。系统默认为10,可以设置为100或者更大。
或者增加worker进程的数量,减少单个worker进程分配的请求量。

net.core.wmem_max


修改此参数增加socket缓存区的内存大小

net.ipv4.tcp_mem  =   379008       505344  758016

net.ipv4.tcp_wmem = 4096        16384   4194304

net.ipv4.tcp_rmem = 4096          87380   4194304

net.core.wmem_default = 8388608

net.core.rmem_default = 8388608

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216


net.ipv4.tcp_tw_reuse


是否socket reuse,此函数的作用是Server重启时可以快速重新使用监听的端口。如果没有设置此参数,会导致server重启时发生端口未及时释放而启动失败

net.ipv4.tcp_tw_recycle


使用socket快速回收,短连接Server需要开启此参数

消息队列设置


当使用消息队列作为进程间通信方式时,需要调整此内核参数

  • kernel.msgmnb = 4203520,消息队列的最大字节数

  • kernel.msgmni = 64,最多允许创建多少个消息队列

  • kernel.msgmax = 8192,消息队列单条数据最大的长度

FreeBSD/MacOS

  • sysctl -w net.local.dgram.maxdgram=8192

  • sysctl -w net.local.dgram.recvspace=200000 修改Unix Socket的buffer区尺寸

开启CoreDump


设置内核参数

kernel.core_pattern = /data/core_files/core-%e-%p-%t


通过ulimit -c命令查看当前coredump文件的限制

ulimit -c


如果为0,需要修改/etc/security/limits.conf,进行limit设置。

开启core-dump后,一旦程序发生异常,会将进程导出到文件。对于调查程序问题有很大的帮助

其他重要配置

  • net.ipv4.tcp_syncookies=1

  • net.ipv4.tcp_max_syn_backlog=81920

  • net.ipv4.tcp_synack_retries=3

  • net.ipv4.tcp_syn_retries=3

  • net.ipv4.tcp_fin_timeout = 30

  • net.ipv4.tcp_keepalive_time = 300

  • net.ipv4.tcp_tw_reuse = 1

  • net.ipv4.tcp_tw_recycle = 1

  • net.ipv4.ip_local_port_range = 20000 65000

  • net.ipv4.tcp_max_tw_buckets = 200000

  • net.ipv4.route.max_size = 5242880

查看配置是否生效


如:修改net.unix.max_dgram_qlen = 100后,通过

cat /proc/sys/net/unix/max_dgram_qlen


如果修改成功,这里是新设置的值。

来源:http://wiki.swoole.com/wiki/page/p-server/sysctl.html

建议继续学习:

  1. linux内核研究笔记(一)内存管理 – page介绍    (阅读:7988)
  2. PHP内核介绍及扩展开发指南―Extensions 的编写    (阅读:4446)
  3. 我的内核配置文件    (阅读:3491)
  4. Linux内核协议栈对于timewait状态的处理    (阅读:3450)
  5. PHP内核介绍及扩展开发指南―高级主题    (阅读:3380)
  6. PHP内核介绍及扩展开发指南―基础知识    (阅读:3175)
  7. 在 Dell PowerEdge 1950 上安装 Linux 2.6.32-rc8 内核的问题与解决    (阅读:2894)
  8. 在Ubuntu上使用SystemTap    (阅读:2885)
  9. Linux内核模块开发(笔记)    (阅读:2865)
  10. 内核编译升级失败了以后的处理方案    (阅读:2833)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
© 2009 - 2024 by blogread.cn 微博:@IT技术博客大学习

京ICP备15002552号-1