Chinaunix首页 | 论坛 | 博客
  • 博客访问: 386653
  • 博文数量: 25
  • 博客积分: 496
  • 博客等级: 下士
  • 技术积分: 815
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-01 11:18
文章分类
文章存档

2014年(2)

2013年(6)

2012年(17)

分类: 网络与安全

2013-12-30 14:11:06

理论部分请参考聂晓亮(毛蛋哥)分享的“Netflow网络流量 分析手册”

一:操作系统准备

系统:Centos6.4 x64 

系统软件环境:Development tools,可以使用yum groupinstall "Development tools"安装

二:安装Fprobe

软件版本:fprobe-1.1.tar.bz2

安装依赖包:yum install libpcap-devel

tar jxvf fprobe-1.1.tar.bz2

cd fprobe-1.1

./configure

make

make install

 

Fprobe监听eth1数据并输出NetFlow127.0.0.1:9995  #eth1为接到网络设备的镜像端口的网卡。

fprobe -i eth1 127.0.0.1:9995

测试是否收到netflow数据

[root@localhost fprobe-1.1]# tcpdump  -i lo port 9995 

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode

listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes

14:36:53.000221 IP localhost.40448 > localhost.palace-4: UDP, length 552

14:37:03.000222 IP localhost.40448 > localhost.palace-4: UDP, length 792

14:37:13.000215 IP localhost.40448 > localhost.palace-4: UDP, length 1224

14:37:23.000220 IP localhost.40448 > localhost.palace-4: UDP, length 792

14:37:33.000226 IP localhost.40448 > localhost.palace-4: UDP, length 360

14:37:43.000216 IP localhost.40448 > localhost.palace-4: UDP, length 264

14:37:53.000218 IP localhost.40448 > localhost.palace-4: UDP, length 600

14:38:03.000221 IP localhost.40448 > localhost.palace-4: UDP, length 1128

14:38:13.000211 IP localhost.40448 > localhost.palace-4: UDP, length 744

稍等一会儿,不断有以上信息输出,则表示已经成功的将端口镜像的数据转化为Netflow数据并发送至本机的UDP 9995端口。

三:安装nfdumpnfsen

yum groupinstall "Web Server"

yum groupinstall "PHP Support"

安装及所需组件:

yum install perl-rrdtool rrdtool rrdtool-devel rrdutils flex byacc

安装所需模块:

yum install perl-Socket6 perl-MailTools perl-Mail-Sender

安装Nfdump

tar zxvf nfdump-1.6.11.tar.gz

cd nfdump-1.6.11

./configure --enable-nfprofile --with-rrdpath=/usr/bin

make

make install

安装配置nfsen

tar zxvf nfsen-1.3.6.tar.gz

cd nfsen-1.3.6

cp etc/nfsen-dist.conf etc/nfsen.conf

修改nfsen配置文件

注意一点:配置文件中$BASEDIR不要和安装包是同一个目录(如安装包目录为/usr/local/nfsen,不要把$BASEDIR也设置为这个路径),如果把$BASEDIR配置成nfsen软件包目录,安装后nfsen无法启动。

vim etc/nfsen.conf   #以下为主要参数,其他配置默认

$BASEDIR = "/data/nfsen";

$BINDIR="${BASEDIR}/bin";

$HTMLDIR    = "/var/www/html/nfsen/";

$USER    = "apache";

$WWWUSER  = "apache";

$WWWGROUP = "apache";

%sources = (

    'upstream1'    => { 'port' => '9995', 'col' => '#0000ff', 'type' => 'netflow' },

);

开始安装:./install.pl etc/nfsen.conf

启动nfsen

/data/nfsen/bin/nfsen start

Starting nfcapd:(upstream1)[6394]

Starting nfsend.

访问地址查看网络监控

四:安装插件

安装PortTracker插件

重编译开启nftrack

./configure --enable-nfprofile --enable-nftrack --with-rrdpath=/usr/bin

make

cp bin/nftrack /usr/local/bin/

cp nfsen-1.3.6/contrib/PortTracker/PortTracker.pm  /data/nfsen/plugins/

cp nfsen-1.3.6/contrib/PortTracker/PortTracker.php  /var/www/html/nfsen/plugins/

创建PortTracker数据存放目录(目录路径可以在/data/nfsen/plugins/ PortTracker.pm配置文件中的PORTSDBDIR参数配置):

mkdir /data/ports-db

chown apache.apache /data/ports-db

修改配置文件添加插件信息:

@plugins = (

    # profile    # module

    # [ '*',     'demoplugin' ],

    [ 'live',     'PortTracker' ],

);

生成PortTracker数据:

nftrack -I -d  /data/ports-db/   8.2G大小的rrd文件

因为是root账户执行的,所以要修改属主

chown -R  apache.apache /data/ports-db/

重新加载Nfsen:

/data/nfsen/bin/nfsen reload

等5分钟左右访问Nfsen界面选择Plugins即可看到相应信息:


如果发现PortTracker插件的Top 10 Statistics有数据显示,但是没有产生视图,检查/var/log/message日志文件是否有“nfsen[17392]: Error reading channel stat information. Missing key 'first'  ”错误信息,如果有,执行/data/nfsen/bin/nfsen –r live即可解决不出图的问题。

安装HostStats插件:

插件版本:HostStats-1.0.4.tar.gz

tar zxvf HostStats-1.0.4.tar.gz

cd HostStats-1.0.4,这个目录中有INSTALL文件,详细的说明了该如何安装

make

make install

重新加载nfsen服务:/data/nfsen/bin/nfsen reload

chown  apache.apache -R /data/hoststats

修改hoststats配置文件

vim /data/hoststats/hoststats.conf,修改数据源路径

flow-data-path = /data/netflow/%source/%y/%m/%d/nfcapd.%y%m%d%H%M

修改为:

flow-data-path = /data/nfsen/profiles-data/live/upstream1/%y/%m/%d/nfcapd.%y%m%d%H%M

运行hoststats插件:

su – apache

/data/hoststats/hoststats

会在以下目录生成数据文件,需要稍等几分钟,刚开始/var/log/message中会有报错日志“Database: Can't open file '/data/hoststats/data/all/hs.201312250930' for reading.”,没关系,待会会有hscleaner进程来清理数据文件,然后重新生成数据,hoststats插件每次重新启动都会这样。

[root@localhost data]# cd /data/hoststats/data/

[root@localhost data]# ls

all  dns  ssh  telnet

[root@localhost data]# ll

total 16

drwxr-xr-x. 2 apache apache 4096 Dec 25 16:31 all

drwxr-xr-x. 2 apache apache 4096 Dec 25 16:31 dns

drwxr-xr-x. 2 apache apache 4096 Dec 25 16:31 ssh

drwxr-xr-x. 2 apache apache 4096 Dec 25 16:31 telnet

 

等十分钟左右就可以在nfsen管理页面中看到了





安装SURFmap插件:

wget

chmod +x install.sh

安装依赖包:yum install php-mbstring

开始安装:./install.sh   #会从网络上下载包自动安装

安装完后重新载入nfsen服务:/data/nfsen/bin/nfsen reload

等几分钟后可以在nfsen管理页面看到。

具体安装步骤参考文档:

安装SSHCure插件:

安装依赖包:yum install perl-DBD-SQLite perl-JSON perl-libwww-perl 

wget http://downloads.sourceforge.net/project/sshcure/install.sh

chmod +x install.sh

开始安装:

./install.sh

安装完后重新载入nfsen服务:/data/nfsen/bin/nfsen reload

等几分钟后可以在nfsen管理页面看到。

具体安装步骤参考文档:http://sourceforge.net/projects/sshcure/files/manual/


阅读(15785) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~