本文主要记录了在ubuntu9.10上用源码方式编译安装net-snmp-5.3的方法与步骤、遇到的问题及其处理方法。总体来说,在linux上安装net-snmp软件包是比较容易的。虽然安装的net-snmp版本是5.3版本的,但应该不限于此版本。

1. 下载net-snmp源码包

进入网址:http://sourceforge.net/projects/net-snmp/files/net-snmp,找到对应版本的net-snmp,然后下载到本地ubuntu上。由于本人2011年就下载了当时最新版本的net-snmp源码包,即net-snmp-5.3.0.1。而当前提供可下载的是5.3版本的稳定版本:net-snmp-5.3.4。本人安装的版本是之前下载的5.3.0.1。5.3.4版本的应当是同样的安装方法。

2. 解压net-snmp源码包
cd /home/reille/snmp/

tar xzvf net-snmp-5.3.0.1.tar.gz
3. 编译安装

源码包安装方法一般都是经典的三部曲:./configure, make, make install,net-snmp的编译安装也是如此。

3.1 ./configure

cd /home/reille/snmp/net-snmp-5.3.0.1

sudo ./configure

net-snmp的配置脚本将会询问一些问题,如:default version of-snmp-version(默认的SNMP协议版本)、Systemcontact information(配置该设备的联系信息)、System location (该系统设备的地理位置)、Location to write logfile (日志文件位置)、Location to Write persistent(数据存储目录)等,除了默认的SNMP协议版本外,其余都可以直接回车,即采用默认的。

configure完成后,将看到一个net-snmp的配置信息,如下所示:

---------------------------------------------------------
            Net-SNMP configuration summary:
---------------------------------------------------------

  SNMP Versions Supported:    1 2c 3
  Building for:               linux
  Net-SNMP Version:           5.6.1
  Network transport support:  Callback Unix Alias TCP UDP IPv4Base SocketBase TCPBase UDPIPv4Base UDPBase
  SNMPv3 Security Modules:     usm
  Agent MIB code:             default_modules =>  snmpv3mibs mibII ucd_snmp notification notification-log-mib target
agent_mibs agentx disman/event disman/schedule utilities host
  MYSQL Trap Logging:         unavailable
  Embedded Perl support:      enabled
  SNMP Perl modules:          building -- embeddable
  SNMP Python modules:        disabled
  Crypto support from:        internal
  Authentication support:     MD5 SHA1
  Encryption support:         DES AES

---------------------------------------------------------

上述执行configure采用默认的方式,缺省安装在/usr/local/bin下,相关文件在/usr/local/share/snmp下。

也可在configure时带上参数,这样在configure时,就不会询问你相关问题:

./configure --with-default-snmp-version="3" --with-sys-contact="@@no.where" --with-sys-location="Unknown" --with-logfile="/var/log/snmpd.log" --with-persistent-directory="/var/net-snmp"

本人直接执行:sudo ./configure

3.2 make和make install

执行命令:

sudo make

make完成 后,执行命令:

sudo make install
4. 配置

为net-snmp agent建立snmpd.conf配置文件。

由于采用的是缺省安装,因此将snmpd.conf配置文件放在/usr/local/share/snmp目录下。该配置文件的建立和配置如下:

4.1 从net-snmp源文件目录下复制配置文件:

sudo cp EXAMPLE.conf /usr/local/share/snmp/snmpd.conf

4.2 配置com2sec:

sudo gedit /usr/local/share/snmp/snmpd.conf

打开后,建议先看下这个文件的说明。

找到com2sec,大概61行,根据其说明,把61、62行的COMMUNITY换成public,把NETWORK换成访问本SNMP agent信息的IP地址,如想让另一台IP为:10.10.10.2电脑访问本ubuntu的SNMP,则把NETWORK换成:10.10.10.2。

保存退出。

5. 运行snmpd即运行net-snmp代理

上述步骤完成后,可使用如下命令检查下安装是否成功:

snmpget --version

如果可以显示正确的版本信息,则说明net-snmp已安装成功。然后就可以运行snmpd这个snmp代理了。

在这里,遇到了问题,在命令行直接输入命令:snmpd后,用命令(关于snmpwalk的用法,详见:snmpwalk介绍及其用法):

snmpwalk -v 2c -c public localhost if

去读取SNMP信息时,却显示:Timeout: No Response from localhost

再用ps -A命令查看进程,却发现没有snmpd进程,也就是说snmpd没运行起来。这是什么原因呢?

后面找到了本文下面的:参考资料4:net-snmp的FAQ:Agent18,在这篇英文文章中,说到snmpd没启动起来是因为snmpd启动时出现了错误。可带上-f –Le选项查看出错的原因(关于选项的使用,请参考本文正下面的:参考资料3:snmp 代理端 安装参数配置)。因此重新输入命令:

snmpd -f -Le

出现如下错误:

Error opening specified endpoint “udp:161”
Server Exiting with code 1

从字面理解,是snmp agent使用的默认端口161不能打开而导致了错误。那怎么会打不开呢?

百思不得其解,google搜索也没结果。

最后,还是在参考资料4的文章中找到了答案,如下所述:

One possible cause might be an existing agent (or some other process) that’s already listening on the SNMP port. Trying to start a second agent will fail with an error about “opening the specified endpoint”.

If you’re starting the agent as a non-root user, then this may also fail with the very same error. By default, the agent (and trap handler) will attempt to listen on the standard SNMP port 161 (or 162 for the trap handler). These are defined as “privileged ports”, and processes will need to be running as root in order to open them.

注意上面的红色部分。也就是说,161端口需要root权限,正好上面执行snmpd时没有root权限,于是加上root权限再执行:

sudo snmpd

果然可以运行起来了,再用snmpwalk命令读snmp信息,可看到读取到的snmp信息了。哈哈,爽。

 

6. 参考资料

参考资料1:老外写的在ubuntu上安装net-snmp的笔记:http://www.net-snmp.org/wiki/index.php/Net-Snmp_on_Ubuntu

参考资料2:net-snmp安装笔记:http://blog.csdn.net/hshxf/article/details/6657822

参考资料3:snmp 代理端 安装参数配置:http://hi.baidu.com/xiaohei9514/blog/item/f471b4ca5c06e383c8176826.html

参考资料4:net-snmp的FAQ:Agent18: FAQ:Agent 18:When I run the agent it runs and then quits without staying around. Why?

参考资料5:net-snmp的FAQ:http://www.net-snmp.org/wiki/index.php/FAQ:Agent

» 文章出处: reille博客—http://velep.com , 如果没有特别声明,文章均为reille博客原创作品
» 郑重声明: 原创作品未经允许不得转载,如需转载请联系reille#qq.com(#换成@)
分享到:

  2 Responses to “ubuntu9.10上编译安装net-snmmp-5.3”

  1. 多谢多谢,折腾了上午,原来卡在这里了,有效。

 Leave a Reply

(必须)

(我会替您保密的)(必须)

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.

   
© 2012 velep.com | reille blog | 管理| 粤ICP备15065318号-2| 谷歌地图| 百度地图| Suffusion theme|Sayontan Sinha

无觅相关文章插件,快速提升流量