歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> PF_RING 6.0.2在Redhat 6.3 x86_64上編譯和安裝

PF_RING 6.0.2在Redhat 6.3 x86_64上編譯和安裝

日期:2017/2/28 14:25:43   编辑:Linux教程

前言

本文詳細描述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

Copyright © Linux教程網 All Rights Reserved