解决服务器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
相关推荐
编码浪子2 小时前
趣味学RUST基础篇(异步)
服务器·rust·负载均衡
九河云3 小时前
华为云 GaussDB:金融级高可用数据库,为核心业务保驾护航
网络·数据库·科技·金融·华为云·gaussdb
独行soc3 小时前
2025年渗透测试面试题总结-66(题目+回答)
java·网络·python·安全·web安全·adb·渗透测试
码农101号4 小时前
运维安全05 - iptables规则保存与恢复
运维·网络·安全
Empty_7774 小时前
SELinux安全上下文
linux·服务器·安全
bug攻城狮5 小时前
解决Ubuntu中apt-get -y安装时弹出交互提示的问题
linux·运维·ubuntu
夜阑珊夭夭5 小时前
linux自定义网卡名字
linux·运维
佛天华6 小时前
centos 时间校准
linux·运维·centos
sukalot6 小时前
window显示驱动开发—视频呈现网络的术语
网络