Linux net-snmp-5.7.2安装配置

Linux net-snmp-5.7.2安装配置

安装包

软件名称:net-snmp-5.7.2.tar.gz

下载地址:http://sourceforge.net/projects/net-snmp/files/net-snmp/5.7.2/net-snmp-5.7.2.tar.gz/download

安装

拷贝net-snmp-5.7.2.tar.gz到目录 /downloads下

解压缩

# tar -xzvf  net-snmp-5.7.2.tar.gz

# cd net-snmp-5.7.2

执行配置命令

# ./configure --prefix=/usr/local/net-snmp

                        --with-default-snmp-version="3"

                        --with-sys-contact="[email protected]"

                        --with-sys-location="China"

                        --with-logfile="/var/log/snmpd.log"

                        --with-persistent-directory="/var/net-snmp"

                        --enable-mfd-rewrites

解释:

prefix:net-snmp将要安装的路径
enable-mfd-rewrites:允许用新的MFD重写可用的mid模块
with-default-snmp-version:默认的SNMP版本
with-sys-contact:可以配置该设备的联系人
with-sys-location:该设备的位置
with-logfile:日志文件路径
with-persistent-directory:不变数据存储目录

编译

# make

安装

# make install


配置snmpd.conf

首先:进入/usr/local/net-snmp/share/snmp

# cd /usr/local/net-snmp/share/snmp

接着:使用配置向导创建snmpd.conf

# ../../bin/snmpconf -g basic_setup

The following installed configuration files were found:

   1:  /usr/local/net-snmp/share/snmp/snmpd.conf

Would you like me to read them in?  Their content will be merged with the
output files created by this session.

Valid answer examples: "all", "none","3","1,2,5"

Read in which (default = all): none
************************************************ 
*** Beginning basic system information setup ***
************************************************ 
Do you want to configure the information returned in the system MIB group (contact info, etc)? (default = y): y

Configuring: syslocation
Description:
  The [typically physical] location of the system.
    Note that setting this value here means that when trying to
    perform an snmp SET operation to the sysLocation.0 variable will make
    the agent return the "notWritable" error code.  IE, including
    this token in the snmpd.conf file will disable write access to
    the variable.
    arguments:  location_string

The location of the system: tianjin

Finished Output: syslocation  tianjin

Configuring: syscontact
Description:
  The contact information for the administrator
    Note that setting this value here means that when trying to
    perform an snmp SET operation to the sysContact.0 variable will make
    the agent return the "notWritable" error code.  IE, including
    this token in the snmpd.conf file will disable write access to
    the variable.
    arguments:  contact_string

The contact information: [email protected]

Finished Output: syscontact  [email protected]
Do you want to properly set the value of the sysServices.0 OID (if you don't know, just say no)? (default = y): no
************************************** 
*** BEGINNING ACCESS CONTROL SETUP ***
************************************** 
Do you want to configure the agent's access control? (default = y): 
Do you want to allow SNMPv3 read-write user based access (default = y): n
Do you want to allow SNMPv3 read-only user based access (default = y): n
Do you want to allow SNMPv1/v2c read-write community access (default = y): n
Do you want to allow SNMPv1/v2c read-only community access (default = y): y

Configuring: rocommunity
Description:
  a SNMPv1/SNMPv2c read-only access community name
    arguments:  community [default|hostname|network/bits] [oid]

The community name to add read-only access for: public
The hostname or network address to accept this community name from [RETURN for all]: 
The OID that this community should be restricted to [RETURN for no-restriction]: 

Finished Output: rocommunity  public  
Do another rocommunity line? (default = y): n
**************************************** 
*** Beginning trap destination setup ***
**************************************** 
Do you want to configure where and if the agent will send traps? (default = y): n
**************************************** 
*** Beginning monitoring setup ***
**************************************** 
Do you want to configure the agent's ability to monitor various aspects of your system? (default = y): n


The following files were created:
snmpd.conf /usr/local/net-snmp/share/snmp/
  snmpd.conf  

These files should be moved to /usr/local/net-snmp/share/snmp if you
want them used by everyone on the system.  In the future, if you add 
the -i option to the command line I'll copy them there automatically for you.

Or, if you want them for your personal use only, copy them to
/root/.snmp .  In the future, if you add the -p option to the
command line I'll copy them there automatically for you.
继续:拷贝新创建的snmpd.conf到提示的目录“/usr/local/net-snmp/share/snmp/”

# snmpd.conf    /usr/local/net-snmp/share/snmp/

启动服务

# cd /usr/local/net-snmp/sbin

# ./snmpd -c /usr/local/net-snmp/share/snmp/snmpd.conf &

检查服务

# ps -ef | grep snmpd

root      9244     1  0 15:38 ?        00:00:00 ./snmpd -c /usr/local/net-snmp/share/snmp/snmpd.conf
root      9247 27939  0 15:39 pts/1    00:00:00 grep snmpd

说明服务已经正常启动

检测161端口

# lsof -i:161

COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
snmpd   9244 root    6u  IPv4 445768      0t0  UDP *:snmp

注意:*表示允许所有主机的访问161端口


设置net-snmp自启动

在/etc/rc.local文件的末尾加上如下所示代码

/usr/local/net-snmp/sbin/snmpd -c /usr/local/net-snmp/share/snmp/snmpd.conf &

设置环境变量

在/etc/profile文件中export前面添加如下代码

PATH=/usr/local/net-snmp/sbin:/usr/local/net-snmp/bin:$PATH

LD_LIBRARY_PATH=/usr/local/net-snmp/lib:$LD_LIBRARY_PATH


测试

localhost测试

# snmpwalk -v 2c -c public localhost if

出现如下信息

IF-MIB::ifIndex.1 = INTEGER: 1
IF-MIB::ifIndex.2 = INTEGER: 2
IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifDescr.2 = STRING: eth0
IF-MIB::ifType.1 = INTEGER: softwareLoopback(24)
IF-MIB::ifType.2 = INTEGER: ethernetCsmacd(6)
IF-MIB::ifMtu.1 = INTEGER: 16436
IF-MIB::ifMtu.2 = INTEGER: 1500
IF-MIB::ifSpeed.1 = Gauge32: 10000000
IF-MIB::ifSpeed.2 = Gauge32: 100000000
IF-MIB::ifPhysAddress.1 = STRING:
IF-MIB::ifPhysAddress.2 = STRING: d4:3d:7e:24:17:5a
IF-MIB::ifAdminStatus.1 = INTEGER: up(1)
IF-MIB::ifAdminStatus.2 = INTEGER: up(1)
IF-MIB::ifOperStatus.1 = INTEGER: up(1)
IF-MIB::ifOperStatus.2 = INTEGER: up(1)
IF-MIB::ifLastChange.1 = Timeticks: (0) 0:00:00.00
IF-MIB::ifLastChange.2 = Timeticks: (0) 0:00:00.00
IF-MIB::ifInOctets.1 = Counter32: 872801
IF-MIB::ifInOctets.2 = Counter32: 27205892
IF-MIB::ifInUcastPkts.1 = Counter32: 15809
IF-MIB::ifInUcastPkts.2 = Counter32: 145137
IF-MIB::ifInNUcastPkts.1 = Counter32: 0
IF-MIB::ifInNUcastPkts.2 = Counter32: 0
IF-MIB::ifInDiscards.1 = Counter32: 0
IF-MIB::ifInDiscards.2 = Counter32: 0
IF-MIB::ifInErrors.1 = Counter32: 0
IF-MIB::ifInErrors.2 = Counter32: 0
IF-MIB::ifInUnknownProtos.1 = Counter32: 0
IF-MIB::ifInUnknownProtos.2 = Counter32: 0
IF-MIB::ifOutOctets.1 = Counter32: 872801
IF-MIB::ifOutOctets.2 = Counter32: 86801071
IF-MIB::ifOutUcastPkts.1 = Counter32: 15809
IF-MIB::ifOutUcastPkts.2 = Counter32: 121285
IF-MIB::ifOutNUcastPkts.1 = Counter32: 0
IF-MIB::ifOutNUcastPkts.2 = Counter32: 0
IF-MIB::ifOutDiscards.1 = Counter32: 0
IF-MIB::ifOutDiscards.2 = Counter32: 0
IF-MIB::ifOutErrors.1 = Counter32: 0
IF-MIB::ifOutErrors.2 = Counter32: 0
IF-MIB::ifOutQLen.1 = Gauge32: 0
IF-MIB::ifOutQLen.2 = Gauge32: 0
IF-MIB::ifSpecific.1 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.2 = OID: SNMPv2-SMI::zeroDotZero

远程测试

使用工具mibbrowser查看,这里就不说明了,大家可以google一下


你可能感兴趣的:(Linux)