Chinaunix首页 | 论坛 | 博客
  • 博客访问: 772498
  • 博文数量: 180
  • 博客积分: 4447
  • 博客等级: 上校
  • 技术积分: 1582
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-03 14:51
文章分类

全部博文(180)

文章存档

2014年(6)

2013年(8)

2011年(125)

2009年(35)

2008年(1)

2007年(5)

分类: LINUX

2011-04-29 11:04:46

  今天由于一台web服务器出现了ip_conntrack表满的情况。已经将/proc/sys/net/ipv4/ip_conntrack_max设置为65536,但是还是满了,按照网上文章知道,通过减小/proc/sys/net/ipv4/netfilter、ip_conntrack_tcp_timeout_established的值,可以让队列释放,但是这个应该是以后的队列才可以的。网上又有文章通过hping2来进行清理,于是我进行了测试:

  1. #!/bin/sh

  2. if [ -z $1 ] ; then
  3. echo "NO INPUT IP"
  4. exit
  5. fi
  6. grep -E "^tcp .{10,25}ESTABLISHED src=$1 " /proc/net/ip_conntrack | while read line; do

  7. S_IP=`echo $line | awk '{print substr($5,5)}'`
  8. S_SOCK=`echo $line | awk '{print substr($7,7)}'`
  9. D_IP=`echo $line | awk '{print substr($6,5)}'`
  10. D_SOCK=`echo $line | awk '{print substr($8,7)}'`
  11. echo "$S_IP:$S_SOCK $D_IP:$D_SOCK"
  12. hping2 $D_IP -R -s $S_SOCK -p $D_SOCK -a $S_IP -k -c 1 > /root/1.log 2>&1 &
  13. done


OS:rhel5.3 x64


首先下载hping2.0.0-rc3.tar.gz
tar zxvf hping2.0.0-rc3.tar.gz
cd cd hping2-rc3/
./configure
make
# make
gcc -c -O2 -Wall  -g  arsglue.c
在包含自 ars.h:18 的文件中,                 从 arsglue.c:5:
byte***.h:22:3: 错误:#error can not find the byte order for this architecture, fix byte***.h
在包含自 arsglue.c:5 的文件中:
ars.h:180:2: 错误:#error "Please, edit Makefile and add -DBYTE_ORDER_(BIG|LITTLE)_ENDIAN"
]ars.h:244:2: 错误:#error "Please, edit Makefile and add -DBYTE_ORDER_(BIG|LITTLE)_ENDIAN"

先放弃,找rpm版的,安装和容易,但是又出问题了,
于是继续 google
http://blog.chinaunix.net/space.php?uid=374372&do=blog&id=89970
说需要修改getlhs.c,于是我是用双网卡做bonding主备的,所以修改为

  1. int get_linkhdr_size(char *ifname)
  2. {

  3.         if ( strstr(ifname, "ppp") ) { /* also works for ippp (ISDN) */
  4.                 linkhdr_size = PPPHDR_SIZE_LINUX;
  5.                 return 0;
  6.         } else if ( strstr(ifname, "eth") ) {
  7.                 linkhdr_size = ETHHDR_SIZE;
  8.                 return 0;
  9.          } else if ( strstr(ifname, "bond") ) {
  10.                 linkhdr_size = ETHHDR_SIZE;
  11.                 return 0;
  12.        } else if (strstr(ifname, "ets")) {
  13.                 linkhdr_size = 0;
  14.                 return 0;
  15.         } else if ( strstr(ifname, "lo") ) {
  16.                 linkhdr_size = LOHDR_SIZE;
  17.                 return 0;
  18.         } else if (strstr(ifname, "atm")) {
  19.                 linkhdr_size = 0;
  20.                 return 0;
  21.         } else if ( strstr(ifname, "wlan") ) {
  22.                 linkhdr_size = WLANHDR_SIZE;
  23.                 return 0;
  24.         }
  25.         else
  26.                 return -1;
  27. }


于是开始google,但是也没有找到有用的结果,经过我分析,应该是gcc 不知道是(BIG|LITTLE)_ENDIAN" 导致的,于是将hping2拷贝到我32位的虚拟机上面去测试,make很正常,于是我确定是gcc 无法识别,打开byte***.h修改
  1. /* Original code from the Linux C library */
  2. /* Copyright (C) 2000,2001 Salvatore Sanfilippo <antirez@invece.org>
  3.  * This code is under the original GNU C library license (GPL) */

  4. /* $Id: byte***.h,v 1.3 2003/07/28 09:00:55 njombart Exp $ */

  5. #ifndef ARS_BYTE***_H
  6. #define ARS_BYTE***_H

  7. #if defined(__i386__) \
  8.         || defined(__x86_64__) \
  9.          || defined(__alpha__) \
  10.         || (defined(__mips__) && (defined(MIPSEL) || defined (__MIPSEL__)))
  11. #define BYTE_ORDER_LITTLE_ENDIAN
  12. #elif defined(__mc68000__) \
  13.         || defined (__sparc__) \
  14.         || defined (__sparc) \
  15.         || defined (__PPC__) \
  16.         || defined (__BIG_ENDIAN__) \
  17.         || (defined(__mips__) && (defined(MIPSEB) || defined (__MIPSEB__)))
  18. #define BYTE_ORDER_BIG_ENDIAN
  19. #else
  20. # error can not find the byte order for this architecture, fix byte***.h
  21. #endif

  22. #endif /* ARS_BYTE***_H */
红色部分增加x86_64的判断。
重新
./configure
make
make strip
make install
一切OK,同时清理ip_conntrack也成功了,但是发现一个问题,并不是一次就能彻底清理的,需要多执行几次脚本,也许是队列里面太多的原因吧。



阅读(5613) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~