解决服务器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
相关推荐
JuiceFS1 天前
从 MLPerf Storage v2.0 看 AI 训练中的存储性能与扩展能力
运维·后端
chen9451 天前
mysql 3节点mgr集群部署
运维·后端
LH_R1 天前
OneTerm开源堡垒机实战(三):功能扩展与效率提升
运维·后端·安全
dessler1 天前
Hadoop HDFS-高可用集群部署
linux·运维·hdfs
少妇的美梦2 天前
logstash教程
运维
chen9452 天前
k8s集群部署vector日志采集器
运维
chen9452 天前
aws ec2部署harbor,使用s3存储
运维
白帽黑客沐瑶2 天前
【网络安全就业】信息安全专业的就业前景(非常详细)零基础入门到精通,收藏这篇就够了
网络·安全·web安全·计算机·程序员·编程·网络安全就业
christine-rr2 天前
linux常用命令(4)——压缩命令
linux·服务器·redis
東雪蓮☆2 天前
深入理解 LVS-DR 模式与 Keepalived 高可用集群
linux·运维·服务器·lvs