为什么我无法在 Ubuntu 18.04 上安装 Perl Net-SNMP

Why I'm not able to install Perl Net-SNMP on Ubuntu 18.04

我正在尝试将 Perl Net-SNMP 用于 Ubuntu 18.04.[=37 上的一些监控脚本=] 但是当我执行 Perl 脚本时,它说:Can't locate SNMP.pm in @INC (you may need to install the SNMP module).

我尝试了所有可能的方法来安装 Perl Net-SNMP,但无法成功安装。
以下是我尝试在 Ubuntu 18.04 上安装 Perl Net-SNMP 的命令:

sudo apt-get install perl-net-snmp
sudo apt-get install net-snmp

我什至尝试使用 tar ball 安装 tar ball [ net-snmp_5.7.3+dfsg.orig.tar.xz ] 下载自:Here

寻求积极的帮助以摆脱这种情况。
这个问题之前没有人问过,所以请先好好研究一下标记为重复。

我的 Perl 脚本:

#!/usr/bin/perl
use warnings;
use strict;
use SNMP;
use Socket;

# VARIABLES YOU SHOULD EDIT.
my $comm = 'public';    # EDIT ME!
my $dest = 'localhost'; # EDIT ME!
my $mib  = 'sysDescr';  # Toy with this to get different
                        # results.
my $sver = '2';         # EDIT ME!

# VARIABLES YOU SHOULD LEAVE ALONE.
my $sess; # The SNMP::Session object that does the work.
my $var;  # Used to hold the individual responses.
my $vb;   # The Varbind object used for the 'real' query.

# Initialize the MIB (else you can't do queries).
&SNMP::initMib();

my %snmpparms;
$snmpparms{Community} = $comm;
$snmpparms{DestHost} = inet_ntoa(inet_aton($dest));
$snmpparms{Version} = $sver;
$snmpparms{UseSprintValue} = '1';
$sess = new SNMP::Session(%snmpparms);

# Turn the MIB object into something we can actually use.
$vb = new SNMP::Varbind([$mib,'0']); # '0' is the instance.

$var = $sess->get($vb); # Get exactly what we asked for.
if ($sess->{ErrorNum}) {
  die "Got $sess->{ErrorStr} querying $dest for $mib.\n";
  # Done as a block since you may not always want to die
  # in here.  You could set up another query, just go on,
  # or whatever...
}
print $vb->tag, ".", $vb->iid, " : $var\n";

# Now let's show a MIB that might return multiple instances.
$mib = 'ipNetToMediaPhysAddress'; # The ARP table!
$vb = new SNMP::Varbind([$mib]);  # No instance this time.

# I prefer this loop method.  YMMV.
for ( $var = $sess->getnext($vb);
      ($vb->tag eq $mib) and not ($sess->{ErrorNum});
      $var = $sess->getnext($vb)
    ) {
  print $vb->tag, ".", $vb->iid, " : ", $var, "\n";
}
if ($sess->{ErrorNum}) {
  die "Got $sess->{ErrorStr} querying $dest for $mib.\n";
}

exit;

完成错误:

Can't locate SNMP.pm in @INC (you may need to install the SNMP module) (@INC contains: /home/prak/perl5/lib/perl5/5.26.1/x86_64-linux-gnu-thread-multi /home/prak/perl5/lib/perl5/5.26.1 /home/prak/perl5/lib/perl5/x86_64-linux-gnu-thread-multi /home/prak/perl5/lib/perl5 /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /home/prak/perl5/lib/perl5/5.26.0 /home/prak/perl5/lib/perl5/5.26.0/x86_64-linux-gnu-thread-multi /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at snmp1.pl line 4.
BEGIN failed--compilation aborted at snmp1.pl line 4.

您需要安装的包名为 libnet-snmp-perl。 Debian 和相关发行版上的 Perl 模块包名称始终以 lib 开头并以 -perl.

结尾

您安装的文件是一组 SNMP 实用程序,而不是 Perl 模块。

尝试 sudo apt-get install libsnmp-perl,然后只需从 CPAN 安装 SNMP 作为 CPAN SNMP.