Agenda: exercise2-install-nfdump-nfsen.txt

File exercise2-install-nfdump-nfsen.txt, 7.7 KB (added by carmas, 6 years ago)

Exercise2-NfSen?

Line 
1% Monitoring Netflow with NFsen
2%
3% Network Monitoring and Management
4
5# Introduction
6
7## Goals
8
9* Learn how to install the nfdump and NfSen tools
10
11## Notes
12
13* Commands preceded with "$" imply that you should execute the command as
14  a general user - not as root.
15* Commands preceded with "#" imply that you should be working as root.
16* Commands with more specific command lines (e.g. "RTR-GW>" or "mysql>")
17  imply that you are executing commands on remote equipment, or within
18  another program.
19
20## Assumption
21
22This assumes you have already configured your router to export flows to a PC in
23your group and that your neighbor group has configured a router to export flows
24to the same PC. See exercise1-flow-export for additional details.
25
26# Configure Your Collector
27
28## Install NFDump and associated software
29
30NFdump is the Netflow flow collector. We install several additional packages
31that we will need a bit later:
32
33~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34$ sudo apt-get install rrdtool mrtg librrds-perl librrdp-perl librrd-dev \
35libmailtools-perl php5 bison flex
36~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37
38If prompted to "Make /etc/mrtg.cfg owned by and readable only by root?" select
39"<Yes>" and press ENTER to continue.
40
41### Building and installing nfdump
42
43We are still missing some tools:
44
45nfcapd, nfdump, nfreplay, nfexpire, nftest, nfgen
46
47There is a package in Ubuntu, but it's too old - so we've built a newer one
48which is ready to download from the NOC:
49
50~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51cd /tmp/
52wget http://noc.ws.nsrc.org/downloads/nfdump_1.6.6-1_i386.deb
53wget http://noc.ws.nsrc.org/downloads/nfdump-flow-tools_1.6.6-1_i386.deb
54~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55
56Installation:
57 
58~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59sudo dpkg --install nfdump_1.6.6-1_i386.deb
60sudo dpkg --install nfdump-flow-tools_1.6.6-1_i386.deb
61~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62
63
64### Testing nfcapd and nfdump
65
66~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67mkdir /tmp/nfcap-test
68nfcapd -E  -p 9001 -l /tmp/nfcap-test
69~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70
71... after a while, a series of flows should be dumped on your screen.
72
73Stop the tool with CTRL+C, then look at the contents of /tmp/nfcap-test
74
75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76$ ls -l /tmp/nfcap-test
77~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78
79You should see one or more files called nfcapd.2013xxyyzz
80
81Process the file(s) with nfdump:
82 
83~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
84nfdump -r nfcapd.2013xxyyzz | less
85nfdump -r nfcapd.2013xxyyzz -s srcip/bytes
86~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87
88You should get some useful information :)
89
90
91
92## Installing and setting up NfSen
93
94~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
95cd /usr/local/src
96sudo wget http://noc.ws.nsrc.org/downloads/nfsen-1.3.6p1.tar.gz
97sudo tar xvzf nfsen-1.3.6p1.tar.gz
98cd nfsen-1.3.6p1
99sudo wget http://noc.ws.nsrc.org/downloads/nfsen-socket6.patch
100sudo patch -p0 < nfsen-socket6.patch
101cd etc
102sudo cp nfsen-dist.conf nfsen.conf
103sudo editor nfsen.conf
104~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
105
106Set the $BASEDIR variable
107
108~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109$BASEDIR="/var/nfsen";
110~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111
112Adjust the tools path to where items actually reside:
113
114~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
115# nfdump tools path
116$PREFIX = '/usr/bin';
117~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
118
119Set the users appropriately so that Apache can access files:
120
121~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
122$WWWUSER = 'www-data';
123$WWWGROUP = 'www-data';
124~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
125
126Set the buffer size to something small, so that we see data quickly
127
128~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
129# Receive buffer size for nfcapd - see man page nfcapd(1)
130$BUFFLEN = 2000;
131~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132
133Find the %sources definition, and change it to:
134
135~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
136%sources=(
137'rtr1' => {'port'=>'9001','col'=>'#0000ff','type'=>'netflow'},
138'rtr2' => {'port'=>'9002','col'=>'#00ff00','type'=>'netflow'},
139 );                               
140~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
141
142Now save and exit from the file.
143
144
145## Create the netflow user on the system
146
147~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
148$ sudo useradd -d /var/netflow -G www-data -m -s /bin/false netflow
149~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150
151
152## Install NfSen and start it
153
154Make sure we are in the right location:
155
156~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
157$ cd /usr/local/src/nfsen-1.3.6p1
158~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
159
160Now, finally, we install:
161
162~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
163$ sudo perl install.pl etc/nfsen.conf
164~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
165
166Press ENTER when prompted for the path to Perl.
167
168## Install init script
169
170In order to have nfsen start and stop automatically when the system starts,
171add a link to the init.d diretory pointing to the nfsen startup script:
172
173~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
174sudo ln -s /var/nfsen/bin/nfsen /etc/init.d/nfsen
175update-rc.d nfsen defaults 20
176~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
177
178Start NfSen
179
180~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
181sudo service nfsen start
182~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
183
184
185## View flows via the web:
186
187You can find the nfsen page here:
188
189~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190http://pcX.ws.nsrc.org/nfsen/nfsen.php
191~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
192
193You may see a message such as:
194
195~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
196Frontend - Backend version missmatch!
197~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
198
199This will go away if you reload the page, it's not a problem.
200
201Done! Move on to the third lab, exercise3-NfSen-PortTracker
202
203* NOTES:
204
205## Adding sources
206
207To add new sources to nfsen, the way to proceed is as follows:
208
209- edit /var/nfsen/etc/nfsen.conf, and add the source, for example:
210
211~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
212%sources = (
213    'rtrX'  => { 'port' => '900X', 'col' => '#0000ff', 'type' => 'netflow' },
214    'rtrY'  => { 'port' => '900Y', 'col' => '#00ff00', 'type' => 'netflow' },
215    'rtr10' => { 'port' => '9010', 'col' => '#ff0000', 'type' => 'netflow' }, # <- new
216);
217~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
218
219- Reconfigure NfSen.
220
221You will need to run this every time you modify /var/nfsen/etc/nfsen.conf:
222
223~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
224$ sudo /etc/init.d/nfsen reconfig
225~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
226
227You should see:
228
229New sources to configure : rtr10
230Continue? [y/n] y
231
232Add source 'rtr10'
233
234Reconfig done!