解决服务器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
相关推荐
yt9483243 分钟前
Docker-基础(数据卷、自定义镜像、Compose)
运维·docker·容器
{{uname}}3 小时前
利用WebSocket实现实时通知
网络·spring boot·websocket·网络协议
水银嘻嘻3 小时前
web 自动化之 KDT 关键字驱动详解
运维·自动化
Vone_663 小时前
node.js 邮箱验证服务器搭建
运维·服务器·node.js
丢丢丢丢丢丢~4 小时前
apache2的默认html修改
linux·运维·服务器
wusam4 小时前
Linux系统管理与编程20:Apache
linux·运维·服务器·apache·shell编程
我不想当小卡拉米4 小时前
【Linux】操作系统入门:冯诺依曼体系结构
linux·开发语言·网络·c++
思科小白白4 小时前
【无标题】
网络·智能路由器
ChironW4 小时前
Ubuntu 24.04 LTS系统上配置国内时间同步
linux·运维·服务器·ubuntu
TPBoreas4 小时前
排查服务器内存空间预警思路
运维·服务器