现在的位置: 首页 > 综合 > 正文

net-snmp在linux下的安装及snmp开发

2013年08月19日 ⁄ 综合 ⁄ 共 1661字 ⁄ 字号 评论关闭
一.环境
OS:RHEL AS4
net-snmp version:5.3.2
二.步骤
1.用root帐户登录
2.运行snmpwalk和snmpget命令,看是否已经安装snmp,如果已经安装就没必要再安装了;-)
3.将net-snmp-5.3.2.tar.gz解压(tar -zxvf net-snmp-5.3.2.tar.gz)
4.进入net-snmp-5.3.2目录
5.运行./configure,根据提示输入相应信息
6.运行make
7.运行make install
8.安装完毕
三.可能遇到的问题
1.找不到libbeecrypt.la,在make时可能出现如下error

libtool: link: cannot find the library `/usr/lib/libbeecrypt.la' (librpmio.la: /usr/lib/libbeecrypt.la)

make[1]: *** [snmpd] Error 1

make[1]: Leaving directory `/home/xxx/net-snmp-5.3.2/agent'

make: *** [subdirs] Error 1

解决办法:
http://sourceforge.net/projects/beecrypt下载beecrypt-4.1.2.tar.gz
然后运行如下命令:
#tar -zxvf beecrypt-4.1.2.tar.gz
#./configure -prefix=/usr(默认是安装在/usr/local,我们需要安装在/usr目录下)
#make
#make install
2./usr/bin/ld: cannot find -lelf,在make时可能出现如下error

/usr/bin/ld: cannot find -lelf

collect2: ld returned 1 exit status

make[1]: *** [snmpd] Error 1

make[1]: Leaving directory `/home/xxx/net-snmp-5.3.2/agent'

make: *** [subdirs] Error 1

解决办法:
#ln -s libelf.so.1 /usr/lib/libelf.so
3.我在安装的过程中没有碰到这个问题,在此作为参考
echo /usr/local/lib >/etc/ld.so.conf.d/libnetsnmp.conf
#/sbin/ldconfig -v
#make install

 

 

开发注意事项:

1.使用mib2c, mib文件须放在/usr/local/share/snmp/mibs/下。
2.流程:写mib文件,mib2c转换成c代码,加入工程,注册,并修改makefile。
3.header_xxxTable函数的实现?table_size为entry的个数,如几个端口。

4.新加的oid节点是用户自己定义的。

5.判断oid节点是否有效的函数header_generic(简单变量),header_simple_table(简单表)等如果使用不当,会导致找不到节点。

6.返回给管理端的数据是通过下面的过程实现的:

switch(vp->magic) {

       case ETHERSTATSDROPEVENTS:
       
        long_ret = 0;
        return (unsigned char *) &long_ret;

    case ETHERSTATSOCTETS:
       
        long_ret = 0;
        return (unsigned char *) &long_ret;

......

}

 当然,这些值是需要调用相应的底层函数取得的。

links:

http://groups.google.com/group/ems-nms?hl=zh-CN%3Fhl%3Den

http://www.net-snmp.org/wiki/index.php/Tutorials

抱歉!评论已关闭.