原文
中文版
大意如下
有两点我们要注意.
-conntrack最大数量.叫做conntrack_max
-存储这些conntrack的hash表的大小,叫做hashsize
当conntrack入口数大于conntrack_max时,在hash表中每一个conntrack list中的存储的入口将不可控.(conntrack_mark/hashsize 为每个list所能存储的入口的数量)
hash表存在于固定的的不可swap的内存中. conntrack_mark决定占用多少这些不可swap的内存.
缺省的hashsize
--------------------------------
conntrack_max=hashsize*8
i386中 hashsize=conntrack_max/8=ramsize(in bytes)/131072=ramsize(in MegaBytes)*8.
所以32位pc,512M内存可以存512*1024^2/128/1024=512*8=4096(连接池list)
但是正确的算法是:
hashsize=conntrack_max/8=ramsize(in bytes)/131072/(x/32)
x表示使用的指针类型是(32位还是64的)
----------------------------\
读取conntrack_max值
cat /proc/sys/net/ipv4/ip_conntrack_max
读取hashsize值
cat /proc/sys/net/ipv4/netfilter/ip_conntrack_buckets
------------------------------
你可修改这两个值以适应高负载的netfilter的应用
系统默认为conntrack_max:hashsize是8:1,你可以设成1:1以提高性能.
-------------------------
设置conntrack_max
echo $CONNTRACK_MAX > /proc/sys/net/ipv4/ip_conntrack_max
设置hashsize
如果(netfilter conntrack静态编译在内核中),2.4中可以在编译时设置,2.6可以在启动中(boot时)加入ip_conntrack.hashsize=$hashsize
如果为modules,则可以使用 modprobe ip_conntrack hashsize=$hashsize
--------------------------
conntrack使用的内存计算
size_of_mem_used_by_conntrack (in bytes) =
CONNTRACK_MAX * sizeof(struct ip_conntrack) +
HASHSIZE * sizeof(struct list_head)
其中sizeof(struct ip_conntrack)大概在192-352字节之间.
sizeof(struct list_head) = 2 * size_of_a_pointer(i386中为4字节)
一个例子512m内存,使用384m来用于conntrack则
384*1024*1024/(352+8)(使用它是保守计算) =~1143901 (此为conntrack:hashszie为1:1,352为sizeof(ip_conntrack),8为sizeof(list_head).
由于hash最好设为2的乘方的数,所以为1048576(2^20).
---------------------
附相关设置及命令:
ip_conntrack timeout 原值432000秒(5天)
可改为10小时,echo "600" > /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_timeout_established
ip_conntrack buffer使用情况
grep conn /proc/slabinfo
例ip_conntrack 188069 229570 336 11 1 : tunables 54 27 8 : slabdata 20870
相关修改:
echo "1024 65000" > /proc/sys/net/ipv4/ip_local_port_range
echo "100 1200 128 512 15 5000 500 1884 2">/proc/sys/vm/bdflush
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo "1" > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo "1048576" > /proc/sys/net/ipv4/netfilter/ip_conntrack_max
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "268435456" >/proc/sys/kernel/shmall
echo "536870912" >/proc/sys/kernel/shmmax
echo "600" > /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_timeout_established
echo "1024" > /proc/sys/net/ipv4/neigh/default/gc_thresh1
echo "2048" > /proc/sys/net/ipv4/neigh/default/gc_thresh2
echo "4096" > /proc/sys/net/ipv4/neigh/default/gc_thresh3
echo "52428800" > /proc/sys/net/ipv4/route/max_size
echo "1" > /proc/sys/net/ipv4/conf/all/proxy_arp
echo "1" > /proc/sys/net/ipv4/tcp_window_scaling
如果系统日志出现下面信息:
Nov 19 22:18:10 Server kernel: printk: 3 messages suppressed.
Nov 19 22:26:50 Server kernel: printk: 10 messages suppressed.
Nov 19 23:41:25 Server kernel: printk: 3 messages suppressed.
Nov 19 23:41:31 Server kernel: printk: 14 messages suppressed.
Nov 19 23:41:36 Server kernel: printk: 11 messages suppressed.
Nov 19 23:41:40 Server kernel: printk: 7 messages suppressed.
Nov 19 23:41:45 Server kernel: printk: 8 messages suppressed.
Nov 19 23:41:51 Server kernel: printk: 9 messages suppressed.
Nov 19 23:41:55 Server kernel: printk: 3 messages suppressed.
Nov 19 23:42:01 Server kernel: printk: 4 messages suppressed.
Nov 19 23:42:11 Server kernel: printk: 2 messages suppressed.
Nov 19 23:42:20 Server kernel: printk: 2 messages suppressed.
Nov 19 23:42:28 Server kernel: printk: 1 messages suppressed.
Nov 20 02:06:48 Server last message repeated 6 times
Nov 20 02:12:50 Server kernel: printk: 8 messages suppressed.
Nov 20 02:13:12 Server kernel: printk: 2 messages suppressed.
Nov 20 02:13:23 Server kernel: printk: 2 messages suppressed.
Nov 20 02:13:30 Server kernel: printk: 1 messages suppressed.
Nov 20 02:13:40 Server kernel: printk: 1 messages suppressed.
Nov 20 02:24:04 Server kernel: printk: 14 messages suppressed.
Nov 20 02:24:09 Server kernel: printk: 24 messages suppressed.
Nov 20 02:24:14 Server kernel: printk: 24 messages suppressed.
Nov 20 02:24:19 Server kernel: printk: 23 messages suppressed.
Nov 20 02:24:24 Server kernel: printk: 24 messages suppressed.
Nov 20 02:24:29 Server kernel: printk: 24 messages suppressed.
Nov 20 02:24:34 Server kernel: printk: 20 messages suppressed.
Nov 20 02:24:39 Server kernel: printk: 24 messages suppressed.
Nov 20 02:24:44 Server kernel: printk: 23 messages suppressed.
Nov 20 02:24:49 Server kernel: printk: 24 messages suppressed.
Nov 20 02:31:53 Server kernel: printk: 23 messages suppressed.
Nov 20 08:54:55 Server sshd(pam_unix)[4593]: session opened for user root by root(uid=0)
修改:
/proc/sys/net/ipv4/neigh/default/gc_thresh1
/proc/sys/net/ipv4/neigh/default/gc_thresh2
/proc/sys/net/ipv4/neigh/default/gc_thresh3
的值
阅读(1531) | 评论(0) | 转发(0) |