解决服务器nf_contrack导致丢包问题

问题描述

近日线下测试环境的一个cloudstack计算节点上的虚拟机出现频繁的丢包情况,经过排查日志发现这个计算节点的报文被丢弃,日志信息如下:

txt 复制代码
Oct 25 10:50:31 hycan-tsp-test-0011 kernel: nf_conntrack: table full, dropping packet
Oct 25 10:50:32 hycan-tsp-test-0011 kernel: nf_conntrack: table full, dropping packet
Oct 25 10:50:33 hycan-tsp-test-0011 kernel: nf_conntrack: table full, dropping packet
Oct 25 10:50:36 hycan-tsp-test-0011 kernel: nf_conntrack: table full, dropping packet
Oct 25 10:50:36 hycan-tsp-test-0011 kernel: nf_conntrack: table full, dropping packet
Oct 25 10:50:37 hycan-tsp-test-0011 kernel: nf_conntrack: table full, dropping packet
Oct 25 10:50:37 hycan-tsp-test-0011 kernel: nf_conntrack: table full, dropping packet
Oct 25 10:50:37 hycan-tsp-test-0011 kernel: nf_conntrack: table full, dropping packet
Oct 25 10:50:38 hycan-tsp-test-0011 kernel: nf_conntrack: table full, dropping packet
Oct 25 10:50:38 hycan-tsp-test-0011 kernel: nf_conntrack: table full, dropping packet
Oct 25 10:50:38 hycan-tsp-test-0011 kernel: nf_conntrack: table full, dropping packet
Oct 25 10:50:39 hycan-tsp-test-0011 kernel: nf_conntrack: table full, dropping packet
Oct 25 10:50:39 hycan-tsp-test-0011 kernel: nf_conntrack: table full, dropping packet
Oct 25 10:50:39 hycan-tsp-test-0011 kernel: nf_conntrack: table full, dropping packet

查询这个错误是因为连接数过高引起的,可以调整nf_conntrack内核参数进行解决。

查看优化相关参数

既然找到了原因,那么我们可以查看并且优化相关参数,默认的net.netfilter.nf_conntrack_max是65536。

bash 复制代码
sysctl net.netfilter.nf_conntrack_max
net.netfilter.nf_conntrack_max = 131072

那么这个值设置多少合理呢?我在网上找到一个计算公式,以512G内存64位系统为例,计算格式如下:

python 复制代码
net.netfilter.nf_conntrack_max = 512*1024*1024*1024/16384/2 = 16777216

优化内核参数。

bash 复制代码
echo net.netfilter.nf_conntrack_max = 16777216 >> /etc/sysctl.conf
sysctl -p

nf_conntrack还有些相关的参数可以进行优化,这些参数我们在之前已经做过优化了,如下:

bash 复制代码
net.netfilter.nf_conntrack_tcp_timeout_established = 1800
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
相关推荐
郝学胜-神的一滴7 小时前
Effective STL 条款09:慎重选择删除元素的方法
开发语言·网络·数据结构·c++·算法·stl
FlightYe9 小时前
linux系统编程(二十一):C 语言常见坑
android·linux·运维·服务器·c语言·音视频
by2099910 小时前
Linux 文件描述符与重定向
linux·服务器
橙橙笔记11 小时前
Linux基础与命令的学习
linux·运维·服务器·shell
无奈笑天下11 小时前
银河麒麟桌面操作系统【命令行配置文件与图片搜索功能】操作方法
linux·运维·服务器
飞花漫卷,情随岁迁12 小时前
网络数据包转发与内核机制:小白概念科普
linux·运维·网络·数据库·mysql·oracle·智能路由器
.道阻且长.13 小时前
Linux基础IO:理解文件以及回顾C文件接口
linux·运维·服务器·c语言·开发语言·职场和发展
laozhang70013 小时前
自己动手写一个 WebSocket 调试工具:告别广告与限制
网络·websocket·网络协议
丘山录14 小时前
本地部署 DGX Spark,200G 网卡挂在 4 条通道上
服务器·人工智能·spark·持续部署