1
0
mirror of https://github.com/pavel-odintsov/fastnetmon synced 2024-12-04 19:08:22 +01:00
fastnetmon-rewritten/fastnetmon_install.pl

176 lines
5.4 KiB
Perl
Raw Normal View History

2014-11-23 20:31:37 +01:00
#!/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;
}
2014-11-24 19:51:48 +01:00
if (-e "/etc/redhat-release") {
$distro_type = 'centos';
$distro_version = `cat /etc/redhat-release | awk '{print \$3}'`;
chomp $distro_version;
}
unless ($distro_type) {
2014-11-23 20:31:37 +01:00
die "This distro is unsupported, please do manual install";
}
2014-11-24 19:51:48 +01:00
install();
2014-11-23 20:31:37 +01:00
2014-11-24 19:51:48 +01:00
sub install {
2014-11-23 20:31:37 +01:00
my $kernel_version = `uname -r`;
chomp $kernel_version;
2014-11-24 19:51:48 +01:00
print "Install PF_RING dependency with package manager\n";
if ($distro_type eq 'debian') {
`apt-get update`;
2014-12-08 10:04:16 +01:00
`apt-get install -y --force-yes build-essential bison flex linux-headers-$kernel_version libnuma-dev wget tar make dpkg-dev dkms debhelper`;
2014-11-24 19:51:48 +01:00
} elsif ($distro_type eq 'centos') {
my $kernel_package_name = 'kernel-devel';
# Fix deplist for OpenVZ
if ($kernel_version =~ /stab/) {
2014-12-01 09:30:45 +01:00
$kernel_package_name = "vzkernel-devel-$kernel_version";
2014-11-24 19:51:48 +01:00
}
2014-12-08 10:04:16 +01:00
`yum install -y make bison flex $kernel_package_name gcc gcc-c++ dkms`;
2014-11-24 19:51:48 +01:00
}
2014-11-23 20:31:37 +01:00
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";
} else {
die "PF_RING load error!";
}
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";
2014-11-24 19:51:48 +01:00
if ($distro_type eq 'debian') {
2014-11-28 15:58:12 +01:00
my @fastnetmon_deps = ("git", "g++", "gcc", "libboost-all-dev", "libgpm-dev", "libncurses5-dev", "liblog4cpp5-dev", "libnuma-dev", "libgeoip-dev","libpcap-dev", "clang", "cmake");
2014-11-24 19:51:48 +01:00
my $fastnetmon_deps_as_string = join " ", @fastnetmon_deps;
`apt-get install -y --force-yes $fastnetmon_deps_as_string`;
} elsif ($distro_type eq 'centos') {
2014-11-28 15:58:12 +01:00
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');
2014-11-24 19:51:48 +01:00
my $fastnetmon_deps_as_string = join " ", @fastnetmon_deps;
`yum install -y $fastnetmon_deps_as_string`;
}
2014-11-23 20:31:37 +01:00
print "Clone FastNetMon repo\n";
chdir "/usr/src";
2014-12-01 09:42:39 +01:00
`git clone $fastnetmon_git_path`;
2014-11-23 20:31:37 +01:00
2014-12-01 09:36:05 +01:00
`mkdir /usr/src/fastnetmon/build`;
chdir "/usr/src/fastnetmon/build";
2014-12-01 09:26:52 +01:00
`cmake ..`;
2014-11-23 20:31:37 +01:00
`make`;
my $fastnetmon_dir = "/opt/fastnetmon";
my $fastnetmon_build_binary_path = "/usr/src/fastnetmon/fastnetmon";
unless (-e $fastnetmon_build_binary_path) {
die "Can't build fastnetmon!";
}
mkdir $fastnetmon_dir;
print "Install fastnetmon to dir $fastnetmon_dir";
`cp $fastnetmon_build_binary_path $fastnetmon_dir/fastnetmon`;
my $fastnetmon_config_path = "/etc/fastnetmon.conf";
unless (-e $fastnetmon_config_path) {
print "Create stub conif\n";
`cp 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";
2014-11-24 20:05:19 +01:00
`sed -i 's/interfaces.*/interfaces = $interfaces_as_list/' $fastnetmon_config_path`;
2014-11-23 20:31:37 +01:00
}
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;
2014-11-24 20:05:19 +01:00
my @clean_interfaces = ();
for my $iface (@interfaces) {
# skip aliases
if ($iface =~ /:/) {
next;
}
push @clean_interfaces, $iface;
}
return @clean_interfaces;
2014-11-23 20:31:37 +01:00
}