CentOS优化

前端之家收集整理的这篇文章主要介绍了CentOS优化前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. 网络线程优化:
  2. 在/etc/sysctl.conf里面加入如下内容
  1. #关闭ipv6
  2. net.ipv6.conf.all.disable_ipv6 = 1
  3. net.ipv6.conf.default.disable_ipv6 = 1
  4. # 避免放大攻击
  5. net.ipv4.icmp_echo_ignore_broadcasts = 1
  6. # 开启恶意icmp错误消息保护
  7. net.ipv4.icmp_ignore_bogus_error_responses = 1
  8. #关闭路由转发
  9. net.ipv4.ip_forward = 0
  10. net.ipv4.conf.all.send_redirects = 0
  11. net.ipv4.conf.default.send_redirects = 0
  12. #开启反向路径过滤
  13. net.ipv4.conf.all.rp_filter = 1
  14. net.ipv4.conf.default.rp_filter = 1
  15. #处理无源路由的包
  16. net.ipv4.conf.all.accept_source_route = 0
  17. net.ipv4.conf.default.accept_source_route = 0
  18. #关闭sysrq功能
  19. kernel.sysrq = 0
  20. #core文件名中添加pid作为扩展名
  21. kernel.core_uses_pid = 1
  22. # 开启SYN洪水攻击保护
  23. net.ipv4.tcp_syncookies = 1
  24. #修改消息队列长度
  25. kernel.msgmnb = 65536
  26. kernel.msgmax = 65536
  27. #设置最大内存共享段大小bytes
  28. kernel.shmmax = 68719476736
  29. kernel.shmall = 4294967296
  30. #timewait的数量,默认180000
  31. net.ipv4.tcp_max_tw_buckets = 6000
  32. net.ipv4.tcp_sack = 1
  33. net.ipv4.tcp_window_scaling = 1
  34. net.ipv4.tcp_rmem = 4096 87380 4194304
  35. net.ipv4.tcp_wmem = 4096 16384 4194304
  36. net.core.wmem_default = 8388608
  37. net.core.rmem_default = 8388608
  38. net.core.rmem_max = 16777216
  39. net.core.wmem_max = 16777216
  40. #每个网络接口接收数据包的速率比内核处理这些包的速率快时,允许送到队列的数据包的最大数目
  41. net.core.netdev_max_backlog = 262144
  42. #限制仅仅是为了防止简单的DoS 攻击
  43. net.ipv4.tcp_max_orphans = 3276800
  44. #未收到客户端确认信息的连接请求的最大值
  45. net.ipv4.tcp_max_syn_backlog = 262144
  46. net.ipv4.tcp_timestamps = 0
  47. #内核放弃建立连接之前发送SYNACK 包的数量
  48. net.ipv4.tcp_synack_retries = 1
  49. #内核放弃建立连接之前发送SYN 包的数量
  50. net.ipv4.tcp_syn_retries = 1
  51. #启用timewait 快速回收
  52. net.ipv4.tcp_tw_recycle = 1
  53. #开启重用。允许将TIME-WAIT sockets 重新用于新的TCP 连接
  54. net.ipv4.tcp_tw_reuse = 1
  55. net.ipv4.tcp_mem = 94500000 915000000 927000000
  56. net.ipv4.tcp_fin_timeout = 1
  57. #当keepalive 起用的时候,TCP 发送keepalive 消息的频度。缺省是2 小时
  58. net.ipv4.tcp_keepalive_time = 30
  59. #允许系统打开的端口范围
  60. net.ipv4.ip_local_port_range = 1024 65000
  61. #修改防火墙表大小,默认65536
  62. #net.netfilter.nf_conntrack_max=655350
  63. #net.netfilter.nf_conntrack_tcp_timeout_established=1200
  64. # 确保无人能修改路由表
  65. net.ipv4.conf.all.accept_redirects = 0
  66. net.ipv4.conf.default.accept_redirects = 0
  67. net.ipv4.conf.all.secure_redirects = 0
  68. net.ipv4.conf.default.secure_redirects = 0
  1. 执行/sbin/sysctl -p立即生效:如果出现error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key错误提示,按照以下方法处理:
  1. modprobe bridge
  2. lsmod|grep bridge
  3.  
  4. 再次执行/sbin/sysctl -p
  1. 系统连接数的优化,linux 默认 open files max user processes 1024
  2. 通过ulimit -n查看限制:
  1. [root@soft ~]# ulimit -n
  2. 1024
  3. [root@soft ~]# ulimit -a
  4. core file size (blocks,-c) 0
  5. data seg size (kbytes,-d) unlimited
  6. scheduling priority (-e) 0
  7. file size (blocks,-f) unlimited
  8. pending signals (-i) 63880
  9. max locked memory (kbytes,-l) 64
  10. max memory size (kbytes,-m) unlimited
  11. open files (-n) 1024
  12. pipe size (512 bytes,-p) 8
  13. POSIX message queues (bytes,-q) 819200
  14. real-time priority (-r) 0
  15. stack size (kbytes,-s) 8192
  16. cpu time (seconds,-t) unlimited
  17. max user processes (-u) 63880
  18. virtual memory (kbytes,-v) unlimited
  19. file locks (-x) unlimited
  1. 在/etc/security/limits.conf后面添加
  1. * soft nofile 65535
  2. * hard nofile 65535
  3. * soft nproc 65535
  4. * hard nproc 65535

参考:
http://smilejay.com/2016/06/centos-7-systemd-conf-limits/?utm_source=tuicool&utm_medium=referral

猜你在找的CentOS相关文章