前言
本文详细描述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_ring2)从下载网址下载最新版本的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_ring2)编译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... noPlease 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 #./alldevs1. 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/kernelmake && 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# 编译TCPDUMPcd ../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
- PF_RING Libzero中使用HugePage (11/19/2014 17:34:57)
| - PF_RING 6.0.2发布 (11/19/2014 17:34:15)
|
本文评论 查看全部评论 (0)