你好,游客 登录 注册 搜索
背景:
阅读新闻

PF_RING 6.0.2在Redhat 6.3 x86_64上编译和安装

[日期:2014-11-19] 来源:Linux社區  作者:fan_hai_ping [字体: ]

前言

本文详细描述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 InterruptThrottleRate=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代码。

      ….

 

更多详情见请继续阅读下一页的精彩内容http://www.linuxidc.com/Linux/2014-11/109580p2.htm

linux
相关资讯       PF_RING 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用���的评论
  • 参与本评论即表明您已经阅读并接受上述条款