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="brusezhu9@gmail.com"

                        --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

  1. The following installed configuration files were found:  
  2.   
  3.    1:  /usr/local/net-snmp/share/snmp/snmpd.conf  
  4.   
  5. Would you like me to read them in?  Their content will be merged with the  
  6. output files created by this session.  
  7.   
  8. Valid answer examples: "all", "none","3","1,2,5"  
  9.   
  10. Read in which (default = all): none  
  11. ************************************************   
  12. *** Beginning basic system information setup ***  
  13. ************************************************   
  14. Do you want to configure the information returned in the system MIB group (contact info, etc)? (default = y): y  
  15.   
  16. Configuring: syslocation  
  17. Description:  
  18.   The [typically physical] location of the system.  
  19.     Note that setting this value here means that when trying to  
  20.     perform an snmp SET operation to the sysLocation.0 variable will make  
  21.     the agent return the "notWritable" error code.  IE, including  
  22.     this token in the snmpd.conf file will disable write access to  
  23.     the variable.  
  24.     arguments:  location_string  
  25.   
  26. The location of the system: tianjin  
  27.   
  28. Finished Output: syslocation  tianjin  
  29.   
  30. Configuring: syscontact  
  31. Description:  
  32.   The contact information for the administrator  
  33.     Note that setting this value here means that when trying to  
  34.     perform an snmp SET operation to the sysContact.0 variable will make  
  35.     the agent return the "notWritable" error code.  IE, including  
  36.     this token in the snmpd.conf file will disable write access to  
  37.     the variable.  
  38.     arguments:  contact_string  
  39.   
  40. The contact information: brusezhu9@gmail.com  
  41.   
  42. Finished Output: syscontact  brusezhu9@gmail.com  
  43. Do you want to properly set the value of the sysServices.0 OID (if you don't know, just say no)? (default = y): no  
  44. **************************************   
  45. *** BEGINNING ACCESS CONTROL SETUP ***  
  46. **************************************   
  47. Do you want to configure the agent's access control? (default = y):   
  48. Do you want to allow SNMPv3 read-write user based access (default = y): n  
  49. Do you want to allow SNMPv3 read-only user based access (default = y): n  
  50. Do you want to allow SNMPv1/v2c read-write community access (default = y): n  
  51. Do you want to allow SNMPv1/v2c read-only community access (default = y): y  
  52.   
  53. Configuring: rocommunity  
  54. Description:  
  55.   a SNMPv1/SNMPv2c read-only access community name  
  56.     arguments:  community [default|hostname|network/bits] [oid]  
  57.   
  58. The community name to add read-only access for: public  
  59. The hostname or network address to accept this community name from [RETURN for all]:   
  60. The OID that this community should be restricted to [RETURN for no-restriction]:   
  61.   
  62. Finished Output: rocommunity  public    
  63. Do another rocommunity line? (default = y): n  
  64. ****************************************   
  65. *** Beginning trap destination setup ***  
  66. ****************************************   
  67. Do you want to configure where and if the agent will send traps? (default = y): n  
  68. ****************************************   
  69. *** Beginning monitoring setup ***  
  70. ****************************************   
  71. Do you want to configure the agent's ability to monitor various aspects of your system? (default = y): n  
  72.   
  73.   
  74. The following files were created:  
  75. snmpd.conf /usr/local/net-snmp/share/snmp/  
  76.   snmpd.conf    
  77.   
  78. These files should be moved to /usr/local/net-snmp/share/snmp if you  
  79. want them used by everyone on the system.  In the future, if you add   
  80. the -i option to the command line I'll copy them there automatically for you.  
  81.   
  82. Or, if you want them for your personal use only, copy them to  
  83. /root/.snmp .  In the future, if you add the -p option to the  
  84. 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一下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值