cat /proc/sys/net/ipv4/netfilter/ip_conntrack_max (_count/_buckets)
less /proc/net/ip_conntrack
Sysctl and ip_conntrack_max optimization
On a busy webserver, you have to be very careful that you don’t run out of connection tracking buckets.
Check how many you have set as your max:
/sbin/sysctl net.ipv4.ip_conntrack_max
Check how many you’re using:
wc -l /proc/net/ip_conntrack
A good maximum setting for most web servers with at least 2Gb RAM is 65536. Change the setting and lock it in (Redhat variants):
echo "net.ipv4.ip_conntrack_max = 65535" > /etc/sysctl.conf
/sbin/sysctl -w
------------------------------------------------
一、概念
====================
-允许的最大跟踪连接条目:CONNTRACK_MAX(默认值是 2^16=65536 )
-存储跟踪连接条目列表的哈西表的大小:HASHSIZE
-每个哈西表的条目(叫一个bucket),包含了一个链接起来的跟踪连接条目
-哈希表大小HASHSIZE,表现为 条目bucket的多少,在iptables启动时在日志中会显示。
图表形象解释:
例如,系统默认配置下,启动 iptables 时的信息如下:
ip_conntrack version 2.4 (8192 buckets, 65536 max) - 304 bytes per conntrack
二、实战:调大 conntrack_max 参数(2.6内核)
========================================
1)增大 ip_conntrack_max(设置为 2^20,默认值是 2^16=65536)
# vi /etc/sysctl.conf
net.ipv4.ip_conntrack_max = 1048576
2)增大 hashsize (在i386架构上,HASHSIZE = CONNTRACK_MAX / 8)
# vi /etc/modprobe.conf
options ip_conntrack hashsize=131072
然后重启 iptables 服务,在 messages中可以看到参数已生效:
# service iptables restart
# tail /var/log/messages
Feb 27 04:02:02 dispatcher syslogd 1.4.1: restart.
Feb 27 17:45:01 dispatcher auditd[3924]: Audit daemon rotating log files
Mar 1 11:47:13 dispatcher kernel: Removing netfilter NETLINK layer.
Mar 1 11:47:13 dispatcher kernel: ip_tables: (C) 2000-2006 Netfilter Core Team
Mar 1 11:47:13 dispatcher kernel: Netfilter messages via NETLINK v0.30.
Mar 1 11:47:13 dispatcher kernel: ip_conntrack version 2.4 (131072 buckets, 1048576 max) - 228 bytes per conntrack
注:只修改 net.ipv4.ip_conntrack_max = 1048576 ,重启iptables服务,messages信息中 (8192 buckets, 65536 max) 不变。
PS:动态调整
=============
Since 2.6.14, 不但可以动态调整ip_conntrack_max值,还可以动态调整hashsize值(after boot and module load),但不会永久保存,重启iptables服务就又变回8192去了.
Between 2.6.14 and 2.6.19 (included), use:
# echo $HASHSIZE > /sys/module/ip_conntrack/parameters/hashsize
# echo $CONNTRACK_MAX > /proc/sys/net/ipv4/ip_conntrack_max
Since 2.6.20, use:
# echo $HASHSIZE > /sys/module/nf_conntrack/parameters/hashsize
# echo $CONNTRACK_MAX > /proc/sys/net/ipv4/ip_conntrack_max
阅读(687) | 评论(0) | 转发(0) |