当前位置:   article > 正文

LINUX TCP/IP内核参数调优(适用于拉大流场景,但延迟、抖动会增大)_tcp调优 文件

tcp调优 文件

nano /etc/sysctl.conf

  1. #
  2. # /etc/sysctl.conf - Configuration file for setting system variables
  3. # See /etc/sysctl.d/ for additional system variables.
  4. # See sysctl.conf (5) for information.
  5. #
  6. #kernel.domainname = example.com
  7. # Uncomment the following to stop low-level messages on console
  8. #kernel.printk = 3 4 1 3
  9. ##############################################################3
  10. # Functions previously found in netbase
  11. #
  12. # Uncomment the next two lines to enable Spoof protection (reverse-path filter)
  13. # Turn on Source Address Verification in all interfaces to
  14. # prevent some spoofing attacks
  15. #net.ipv4.conf.default.rp_filter=1
  16. #net.ipv4.conf.all.rp_filter=1
  17. # Uncomment the next line to enable TCP/IP SYN cookies
  18. # See http://lwn.net/Articles/277146/
  19. # Note: This may impact IPv6 TCP sessions too
  20. #net.ipv4.tcp_syncookies=1
  21. # Uncomment the next line to enable packet forwarding for IPv4
  22. #net.ipv4.ip_forward=1
  23. # Uncomment the next line to enable packet forwarding for IPv6
  24. # Enabling this option disables Stateless Address Autoconfiguration
  25. # based on Router Advertisements for this host
  26. #net.ipv6.conf.all.forwarding=1
  27. ###################################################################
  28. # Additional settings - these settings can improve the network
  29. # security of the host and prevent against some network attacks
  30. # including spoofing attacks and man in the middle attacks through
  31. # redirection. Some network environments, however, require that these
  32. # settings are disabled so review and enable them as needed.
  33. #
  34. # Do not accept ICMP redirects (prevent MITM attacks)
  35. #net.ipv4.conf.all.accept_redirects = 0
  36. #net.ipv6.conf.all.accept_redirects = 0
  37. # _or_
  38. # Accept ICMP redirects only for gateways listed in our default
  39. # gateway list (enabled by default)
  40. # net.ipv4.conf.all.secure_redirects = 1
  41. #
  42. # Do not send ICMP redirects (we are not a router)
  43. #net.ipv4.conf.all.send_redirects = 0
  44. #
  45. # Do not accept IP source route packets (we are not a router)
  46. #net.ipv4.conf.all.accept_source_route = 0
  47. #net.ipv6.conf.all.accept_source_route = 0
  48. #
  49. # Log Martian Packets
  50. #net.ipv4.conf.all.log_martians = 1
  51. #
  52. ###################################################################
  53. # Magic system request Key
  54. # 0=disable, 1=enable all, >1 bitmask of sysrq functions
  55. # See https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html
  56. # for what other values do
  57. #kernel.sysrq=438
  58. vm.overcommit_memory=1
  59. net.core.rps_sock_flow_entries=32768 #rfs 设置此文件至同时活跃连接数的最大预期值
  60. #net.ipv4.icmp_echo_ignore_all=1 #禁止ping
  61. #net.ipv4.icmp_echo_ignore_broadcasts=1
  62. fs.file-max=1000000 # 系统级别的能够打开的文件句柄的数量
  63. fs.inotify.max_user_instances=65536
  64. #开启路由转发
  65. net.ipv4.conf.all.route_localnet=1
  66. net.ipv4.ip_forward=1
  67. net.ipv4.conf.all.forwarding=1
  68. net.ipv4.conf.default.forwarding=1
  69. net.ipv6.conf.all.forwarding = 1
  70. net.ipv6.conf.default.forwarding = 1
  71. net.ipv6.conf.lo.forwarding = 1
  72. net.ipv6.conf.all.disable_ipv6 = 0
  73. net.ipv6.conf.default.disable_ipv6 = 0
  74. net.ipv6.conf.lo.disable_ipv6 = 0
  75. net.ipv6.conf.all.accept_ra = 2
  76. net.ipv6.conf.default.accept_ra = 2
  77. net.ipv4.conf.all.accept_redirects=0
  78. net.ipv4.conf.default.accept_redirects=0
  79. net.ipv4.conf.all.secure_redirects=0
  80. net.ipv4.conf.default.secure_redirects=0
  81. net.ipv4.conf.all.send_redirects=0
  82. net.ipv4.conf.default.send_redirects=0
  83. net.ipv4.conf.default.rp_filter=0
  84. net.ipv4.conf.all.rp_filter=0
  85. #ARP回应的级别
  86. #net.ipv4.conf.all.arp_ignore=2
  87. #net.ipv4.conf.default.arp_ignore=2
  88. #net.ipv4.conf.all.arp_announce=2
  89. #net.ipv4.conf.default.arp_announce=2
  90. net.ipv4.neigh.default.gc_stale_time=60 #ARP缓存的存活时间
  91. net.ipv4.tcp_syncookies=1 #开启SYN Cookies。当出现SYN等待队列溢出时,启用cookies来处理
  92. net.ipv4.tcp_retries1=3
  93. net.ipv4.tcp_retries2=8
  94. net.ipv4.tcp_syn_retries=2 #SYN重试次数
  95. net.ipv4.tcp_synack_retries=2 #SYNACK重试次数
  96. net.ipv4.tcp_tw_reuse=1 #开启TIME-WAIT sockets重用
  97. net.ipv4.tcp_fin_timeout=15 #保持在FIN-WAIT-2状态的时间
  98. net.ipv4.tcp_max_tw_buckets=32768 #系统同时保持TIME_WAIT socket的数量
  99. #net.core.busy_poll=50
  100. #net.core.busy_read=50
  101. net.core.dev_weight=4096
  102. net.core.netdev_budget=65536
  103. net.core.netdev_budget_usecs=4096
  104. net.ipv4.tcp_max_syn_backlog=262144 #对于还未获得对方确认的连接请求,可保存在队列中的最大数目
  105. net.core.netdev_max_backlog=32768 #网口接收数据包比内核处理速率快状态队列的数量
  106. net.core.somaxconn=32768 #每个端口最大的监听队列的数量
  107. net.ipv4.tcp_notsent_lowat=131072 #30Mbps以上用这个
  108. #net.ipv4.tcp_notsent_lowat=16384
  109. net.ipv4_timestamps=0 #TCP时间戳的支持
  110. net.ipv4.tcp_keepalive_time=600 #TCP发送keepalive探测消息的间隔时间(秒)
  111. net.ipv4.tcp_keepalive_probes=5 #TCP发送keepalive探测确定连接已经断开的次数
  112. net.ipv4.tcp_keepalive_intvl=15 #探测消息未获得响应时,重发该消息的间隔时间
  113. vm.swappiness=1
  114. net.ipv4.route.gc_timeout=100
  115. net.ipv4.neigh.default.gc_thresh1=1024 #最小保存条数。当邻居表中的条数小于该数值,则 GC 不会做任何清理
  116. net.ipv4.neigh.default.gc_thresh2=4096 #高于该阈值时,GC 会变得更激进,此时存在时间大于 5s 的条目会被清理
  117. net.ipv4.neigh.default.gc_thresh3=8192 #允许的最大临时条目数。当使用的网卡数很多,或直连了很多其它机器时考虑增大该参数。
  118. net.ipv6.neigh.default.gc_thresh1=1024
  119. net.ipv6.neigh.default.gc_thresh2=4096
  120. net.ipv6.neigh.default.gc_thresh3=8192
  121. net.netfilter.nf_conntrack_max=262144
  122. net.nf_conntrack_max=262144
  123. net.netfilter.nf_conntrack_tcp_timeout_established=36000 #ESTABLISHED状态连接的超时时间
  124. # TCP窗口
  125. net.ipv4.tcp_fastopen=3 # 开启TCP快速打开
  126. net.ipv4.tcp_autocorking=0
  127. net.ipv4.tcp_slow_start_after_idle=0 #关闭TCP的连接传输的慢启动
  128. net.ipv4.tcp_no_metrics_save=1
  129. net.ipv4.tcp_ecn=0
  130. net.ipv4.tcp_frto=0
  131. net.ipv4.tcp_mtu_probing=0
  132. net.ipv4.tcp_rfc1337=0
  133. net.ipv4.tcp_sack=1
  134. net.ipv4.tcp_fack=1
  135. net.ipv4.tcp_window_scaling=1
  136. net.ipv4.tcp_adv_win_scale=1
  137. net.ipv4.tcp_moderate_rcvbuf=1
  138. net.core.rmem_max=33554432
  139. net.core.wmem_max=33554432
  140. net.ipv4.tcp_rmem=4096 87380 33554432
  141. net.ipv4.tcp_wmem=4096 16384 33554432
  142. net.ipv4.udp_rmem_min=8192
  143. net.ipv4.udp_wmem_min=8192
  144. net.ipv4.tcp_mem=262144 1048576 4194304
  145. net.ipv4.udp_mem=262144 524288 1048576
  146. # BBR
  147. net.ipv4.tcp_congestion_control=bbr
  148. net.core.default_qdisc=fq

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号