net-snmp在linux下的安裝及snmp開發

一.環境
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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章