这篇文章上次修改于 1201 天前,可能其部分内容已经发生变化,如有疑问可询问作者。

使用Suricata时,为了提高流量采集效率,需要要打开pf_ring模式。以下是安装gcc7.3及pf_ring的过程。

0x1 Centos7 mini安装所需环境

yum groupinstall -y 'Development Tools

yum install -y texinfo bison flex gcc-gnat glibc-devel.i686 libgcc.i686

yum install wget lrzsz -y

注:安装 i686 的包是为了安装32位的头文件和库,如果不安装i686的包,请在 configure 时加入--disable-multilib,取消对32位的支持。

0x2配置编译gcc


#获取“gcc-7.3.0”源码包
cd /usr/local/src

wget https://ftp.gnu.org/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz

tar -zxvf gcc-7.3.0.tar.gz

cd gcc-7.3.0/

./contrib/download_prerequisites

#上面命令会下载isl、gmp、mpc、mpfr,网速慢可以手动下载好传上去。
#wget https://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
#wget https://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
#wget https://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
#wget https://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2

mkdir build && cd build

#生成Makefile文件
../configure --prefix=/usr

#-j参数可利用多核CPU加快编译速度

make -j8

make install

gcc --version

#回显信息:
回显信息如下,则表示gcc安装成功。
=========================
gcc (GCC) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
=========================

#重启
reboot

0x3配置编译pf_ring


wget https://github.com/ntop/PF_RING/archive/7.6.0.tar.gz

tar -zxvf PF_RING-7.6.0.tar.gz

cd PF_RING-7.6.0/kernel && make && make install

insmod pf_ring.ko

#编译userland中的libpcap、tcpdump
cd ../userland/lib
./configure && make && make install

cd ../libpcap
./configure && make && make install

cd ../tcpdump
./configure && make && make install

#编译自带examples
cd ../examples && make

#使用pfcount统计端口信息
./pfcount -i eth0

#回显信息:
Using PF_RING v.7.6.0
Capturing from eth0 [mac: FA:16:3E:B1:3E:7B][if_index: 2][speed: 0Mb/s]
# Device RX channels: 2
# Polling threads:    1
Dumping statistics on /proc/net/pf_ring/stats/18549-eth0.3
=========================
Absolute Stats: [3 pkts total][0 pkts dropped][0.0% dropped]
[3 pkts rcvd][532 bytes rcvd]
=========================