您的位置:首页 > 其它

pf_ring安装 使用 修改缓冲区

2017-01-18 13:56 381 查看

前言

本文详细描述Linux下PF_RING的编译和安装过程。

PF_RING版本:6.0.2(当前最新版本)

官方网址:http://www.ntop.org/products/pf_ring/

下载网址:http://sourceforge.net/projects/ntop/files/PF_RING/

Linux系统:Redhat 6.3(x86_64)

GCC版本:GCC 4.4.6

下载PF_RING

1)确认是否安装PF_RING

如果你已经安装pf_ring,你可能需要执行:rmmodpf_ring

如果你不确定你是否安装pf_ring,执行:modinfopf_ring

2)从下载网址下载最新版本的PF_RING:

PF_RING-6.0.2.tar.gz  2014-09-24   21.9MB

上传到安装Redhat 6.3的服务器的/opt目录下。

以root用户登录到服务器:

       #cd /opt

       #tar zxf PF_RING-6.0.2.tar.gz

       #cd PF_RING-6.0.2

编译和安装PF_RING

1)编译pf_ring内核文件

进入内核模块目录:

cd /opt/PF_RING-6.0.2/kernel

编译pf_ring内核模块:

make &&make install

在RHEL 6.3中PF_RING内核模块安装的目录:

/lib/modules/2.6.32-279.el6.x86_64/kernel/net/pf_ring

加载pf_ring内核模块:

modprobe pf_ringtransparent_mode=1

或者

insmod<PF_RINGPATH>/kernel/pf_ring.ko [transparent_mode=0|1|2] [min_num_slots=x][enable_tx_capture=1|0][enable_ip_defrag=1|0]  [quick_mode=1|0]

检查是否加载pf_ring内核模块:

lsmod | greppf_ring

查看加载信息:

cat/proc/net/pf_ring/info

删除pf_ring内核模块:

rmmd pf_ring

2)编译pf_ring开发库

进入到/opt/PF_RING-6.0.2/userland/lib目录下编译pf_ring库:

       #cd /opt/PF_RING-6.0.2/userland/lib

       #./configure --prefix=/opt/pfring

报错:checkingif libnuma is present... no

Please install libnuma-dev in order to usePF_RING

解决:需要安装libnuma-dev库,可以从光盘或者ISO镜像中查找numactl*.rpm包使用rpm -ivh命令进行安装。

       #make && make intall

注:编译完成的pf_ring库和头文件可以在/opt/pfring中找到。

注:缺少lib/pf_ring.h头文件可以在/usr/include/linux/pf_ring.h中找到,或则/opt/PF_RING-6.0.2/kernel/linux目录下找到。

3)编译支持PF_RING的libpcap库

       #cd /opt/PF_RING-6.0.2/userland/libpcap

       #./configure --prefix=/opt/pfring/

       #make && make install

 注:修改源码,将pf_ring的内核ring缓冲区设为10M,默认是2M

       源代码:userland/libpcap-1.1.1-ring/pcap-linux.c

       函数:int activate_mmap(pcap_t*handle);

       代码片段:

  3310         if (handle->opt.buffer_size == 0) {

  3311                 /* by defaultrequest 2M for the ring buffer */

  3312                handle->opt.buffer_size = 2*1024*1024;

  3313         } 

注:编译完成的libpcap库和头文件可以在/opt/pfring中找到。

 4)编译pf_ring示例代码

       #cd /opt/PF_RING-6.0.2/userland/examples

       #make

       #./alldevs

1. lan (PF_RING)

2. usbmon1 (USB bus number 1)

3. any (Pseudo-device that captures on allinterfaces)

4. lo (No description available)

       该目录下还有一些实用的PF_RING工具:pfcount、pfsend等。

 5)编译和安装PF_RING支持的驱动

       *使用ethtool工具查看网卡的型号,例如:ethtool -i eth0

       #lspci | grep Ethernet

       *进入到驱动目录,注意这里使用非零拷贝的驱动:

cd /opt/PF_RING-6.0.2/drivers/PF_RING_aware/non-ZC-drivers/intel

       *编译PF_RING支持的网卡:

       #cd e1000/e1000-8.0.35/src

       #make && make install

       在Redhat 6.3下网卡驱动安装的位置:

       /lib/modules/2.6.32-279.el6.x86_64/kernel/drivers/net/e1000/e1000.ko

       *卸载和安装PF_RING驱动:

卸载驱动:# rmmod e1000

安装驱动:# modprobe e1000

查看驱动:# ethtol -i eth0

       注意:当通信网卡也使用该驱动程序时,请务必现场操作,如果使用ssh远程卸载驱动会造成网络不能连接。

注:建议采集使用的网卡和通信使用的网卡分别使用不同的驱动。

       注:设置网卡名称和MAC地址,请编译下面的文件:

/etc/udev/rules.d/70-persistent-net.rules

       编译和安装PF_RING的命令整理如下(无需作为root用户执行):

# 编译内核

cd /opt/PF_RING-6.0.2/kernel

make && sudo make install

# 编译PF_RING库

cd ../userland/lib

./configure –prefix=/usr/local/pfring&& make && sudo make install

# 编译libpcap库

cd ../libpcap-1.1.1-ring

./configure –prefix=/usr/local/pfring&& make && sudo make install

# 编译TCPDUMP

cd ../tcpdump-4.1.1

./configure –prefix=/usr/local/pfring&& make && sudo make install

# 更新动态库

sudo ldconfig

# 加载模块

sudo modprobe pf_ring

# 提升到root权限,执行

modinfo pf_ring && cat/proc/net/pf_ring/info

# 增加ixgbe模块的节流率

rmmod ixgbe

modprobe ixgbe InterruptThrottl
bcf5
eRate=4000

# 为了符合高速网络的需要,我们需要增加ring槽位的数量

rmmod pf_ring

modprobe pf_ring transparent_mode=1 min_num_slots=65534 enable_tx_capture=0

使用PF_RING

       如果使用支持PF_RING的libpcap的话,记得在应用程序的头文件中加入#define HAVE_PF_RING定义或CXXFLAGS中加入-DHAVE_PF_RING。

       如果直接使用PF_RINGAPI编写代码不需要加入上面的定义。

       PF_RINGAPI使用请阅读doc目录下的UserGuide.pdf文件,或者阅读userland目录下examples中的pfcount代码。

       ….

编译PF_RING问题

问题1:./runlex.sh: line 83: flex: command not found;

    ./runlex.sh: line 118: flex: command not found

   回答: sudo yuminstall flex

 

问题2:make[2]: yacc: Command not found         

 answer:sudo yum install bison

 

问题3:cannot find -lnuma

answer:sudo yum install numactl-devel

对于Redhat 6.3版本需要从网上下载:numactl-devel-2.0.7-3.el6.x86_64.rpm

 

问题4:grammar.c:(.text+0x44e): undefined reference to `pcap_lex'

  answer: 删除掉老的libpcap 1.0.0之前的版本。

       #rpm -aq | grep libpcap  如果存在则删除它

       #yum remove libpcap

 

问题5:insmod: error inserting 'pf_ring.ko': -1 Unknown symbol in module

解决:没有卸载当前的网卡驱动,导致新的驱动加载不了,因此需要先卸载网卡驱动后再重新进行加载。

 

问题6: --nodefs: unknown option

解决:rpm --nodeps -e libpcap

配置PF_RING

1.加载ixgbe驱动,我们发现设置InterruptThrottleRate为4000是最优的。

modprobe ixgbe InterruptThrottleRate=4000

2.加载PF_RING驱动,使用透传模式2,并且设置合理的缓冲区大小。

modprobe pf_ring.ko transparent_mode=2min_num_slots=16384

3.优化以太网设备,关闭影响吞吐量的选项。使用合适的接口替代eth3。

ethtool -C eth3 rx-usecs 1000

ethtool -C eth3 adaptive-rx off

ethtool -K eth3 tso off

ethtool -K eth3 gro off

ethtool -K eth3 lro off

ethtool -K eth3 gso off

ethtool -K eth3 rx off

ethtool -K eth3 tx off

ethtool -K eth3 sg off

 4.设置CPU的亲和力

为了让Snort达到5Gbps吞吐量,我们需要更好的硬件(24核CPU Intel X567),使用PF_RING NAPI或DNA进行加速,选择使用Silicom网卡。

禁用TX捕获:insmodpf_ring.ko enable_tx_capture=0
增加ring slots数量,使用透传模式1:insmod pf_ring.ko enable_tx_capture=0transparent_mode=1 min_num_slots=16384
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: