forked from HostSuki/fastnetmon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fastnetmon_install.pl
executable file
·212 lines (155 loc) · 6.61 KB
/
fastnetmon_install.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/perl
use strict;
use warnings;
my $distro_type = '';
my $distro_version = '';
my $pf_ring_version = '6.0.2';
my $pf_ring_url = "http://sourceforge.net/projects/ntop/files/PF_RING/PF_RING-$pf_ring_version.tar.gz/download";
my $fastnetmon_git_path = 'https://github.com/FastVPSEestiOu/fastnetmon.git';
if (-e "/etc/debian_version") {
$distro_type = 'debian';
$distro_version = `cat /etc/debian_version`;
chomp $distro_version;
}
if (-e "/etc/redhat-release") {
$distro_type = 'centos';
my $distro_version_raw = `cat /etc/redhat-release`;
chomp $distro_version_raw;
# CentOS 6:
# CentOS release 6.6 (Final)
# CentOS 7:
# CentOS Linux release 7.0.1406 (Core)
if ($distro_version_raw =~ /(\d+)/) {
$distro_version = $1;
}
}
unless ($distro_type) {
die "This distro is unsupported, please do manual install";
}
install();
sub install {
my $kernel_version = `uname -r`;
chomp $kernel_version;
my $we_have_pfring_support = '';
print "Install PF_RING dependency with package manager\n";
if ($distro_type eq 'debian') {
`apt-get update`;
`apt-get install -y --force-yes build-essential bison flex linux-headers-$kernel_version libnuma-dev wget tar make dpkg-dev dkms debhelper`;
} elsif ($distro_type eq 'centos') {
my $kernel_package_name = 'kernel-devel';
# Fix deplist for OpenVZ
if ($kernel_version =~ /stab/) {
$kernel_package_name = "vzkernel-devel-$kernel_version";
}
`yum install -y make bison flex $kernel_package_name gcc gcc-c++ dkms numactl-devel`;
}
print "Download PF_RING $pf_ring_version sources\n";
my $pf_ring_archive_path = "/usr/src/PF_RING-$pf_ring_version.tar.gz";
my $pf_ring_sources_path = "/usr/src/PF_RING-$pf_ring_version";
`wget $pf_ring_url -O$pf_ring_archive_path`;
print "Unpack PF_RING\n";
mkdir $pf_ring_sources_path;
`tar -xf $pf_ring_archive_path -C /usr/src`;
print "Build PF_RING kernel module\n";
`make -C $pf_ring_sources_path/kernel clean`;
`make -C $pf_ring_sources_path/kernel`;
`make -C $pf_ring_sources_path/kernel install`;
print "Unloade PF_RING if it was installed earlier\n";
`rmmod pf_ring`;
print "Load PF_RING module into kernel\n";
`modprobe pf_ring`;
my @dmesg = `dmesg`;
chomp @dmesg;
if (scalar grep (/\[PF_RING\] Initialized correctly/, @dmesg) > 0) {
print "PF_RING loaded correctly\n";
$we_have_pfring_support = 1;
} else {
warn "PF_RING load error! We disable PF_RING plugin";
$we_have_pfring_support = '';
}
if ($we_have_pfring_support) {
print "Build PF_RING lib\n";
# Because we can't run configure from another folder because it can't find ZC dependency :(
chdir "$pf_ring_sources_path/userland/lib";
`./configure --prefix=/opt/pf_ring_$pf_ring_version`;
`make`;
`make install`;
print "Create library symlink\n";
unlink "/opt/pf_ring";
`ln -s /opt/pf_ring_$pf_ring_version /opt/pf_ring`;
print "Add pf_ring to ld.so.conf\n";
my $pf_ring_ld_so_conf = "/etc/ld.so.conf.d/pf_ring.conf";
open my $pf_ring_ld_so_conf_handle, ">", $pf_ring_ld_so_conf or die "Can't open $! for writing\n";
print {$pf_ring_ld_so_conf_handle} "/opt/pf_ring/lib";
close $pf_ring_ld_so_conf_handle;
print "Run ldconfig\n";
`ldconfig`;
}
print "Install FastNetMon dependency list\n";
if ($distro_type eq 'debian') {
my @fastnetmon_deps = ("git", "g++", "gcc", "libboost-all-dev", "libgpm-dev", "libncurses5-dev", "liblog4cpp5-dev", "libnuma-dev", "libgeoip-dev","libpcap-dev", "clang", "cmake");
my $fastnetmon_deps_as_string = join " ", @fastnetmon_deps;
`apt-get install -y --force-yes $fastnetmon_deps_as_string`;
} elsif ($distro_type eq 'centos') {
my @fastnetmon_deps = ('git', 'make', 'gcc', 'gcc-c++', 'boost-devel', 'GeoIP-devel', 'log4cpp-devel', 'ncurses-devel', 'glibc-static', 'ncurses-static', 'boost-thread', 'libpcap-devel', 'gpm-static', 'gpm-devel', 'clang', 'cmake');
my $fastnetmon_deps_as_string = join " ", @fastnetmon_deps;
`yum install -y $fastnetmon_deps_as_string`;
}
if ($distro_type eq 'centos' && $distro_version >= 7) {
# CentOS 7 has not log4cpp in repo and we should build it manually
`wget 'http://sourceforge.net/projects/log4cpp/files/latest/download?source=files' -O/usr/src/log4cpp-1.1.1.tar.gz`;
chdir "/usr/src";
`tar -xf log4cpp-1.1.1.tar.gz`;
chdir "/usr/src/log4cpp";
`./configure --prefix=/opt/log4cpp1.1.1`;
`make install`;
}
print "Clone FastNetMon repo\n";
chdir "/usr/src";
`git clone $fastnetmon_git_path`;
`mkdir /usr/src/fastnetmon/build`;
chdir "/usr/src/fastnetmon/build";
my $cmake_params = "";
unless ($we_have_pfring_support) {
$cmake_params .= " -DDISABLE_PF_RING_SUPPORT=ON";
}
if ($distro_type eq 'centos' && $distro_version >= 7) {
$cmake_params .= " -DWE_USE_CUSTOM_LOG4CPP=on";
}
`cmake .. $cmake_params`;
`make`;
my $fastnetmon_dir = "/opt/fastnetmon";
my $fastnetmon_build_binary_path = "/usr/src/fastnetmon/build/fastnetmon";
unless (-e $fastnetmon_build_binary_path) {
die "Can't build fastnetmon!";
}
mkdir $fastnetmon_dir;
print "Install fastnetmon to dir $fastnetmon_dir\n";
`cp $fastnetmon_build_binary_path $fastnetmon_dir/fastnetmon`;
`cp /usr/src/fastnetmon/build/fastnetmon_client $fastnetmon_dir/fastnetmon_client`;
my $fastnetmon_config_path = "/etc/fastnetmon.conf";
unless (-e $fastnetmon_config_path) {
print "Create stub conif\n";
`cp /usr/src/fastnetmon/fastnetmon.conf $fastnetmon_config_path`;
my @interfaces = get_active_network_interfaces();
my $interfaces_as_list = join ',', @interfaces;
print "Select $interfaces_as_list as active interfaces\n";
print "Tune config\n";
`sed -i 's/interfaces.*/interfaces = $interfaces_as_list/' $fastnetmon_config_path`;
}
print "Please add your subnets in /etc/networks_list in CIDR format one subnet per line\n";
print "You can run fastnetmon with command: $fastnetmon_dir/fastnetmon\n";
}
sub get_active_network_interfaces {
my @interfaces = `netstat -i|egrep -v 'lo|Iface|Kernel'|awk '{print \$1}'`;
chomp @interfaces;
my @clean_interfaces = ();
for my $iface (@interfaces) {
# skip aliases
if ($iface =~ /:/) {
next;
}
push @clean_interfaces, $iface;
}
return @clean_interfaces;
}