天天看點

VS2005下編譯、安裝Net-snmp 5.4.1.2手記(原創)

VS2005下編譯、安裝Net-snmp 5.4.1.2手記

 by Flyfish <[email protected]>   2008-09-08: ======================================================== 0、安裝Active Perl 5.8.8 build820。 1、下載下傳net-snmp-5.4.1.2.zip文檔,并解壓至某目錄,以下稱此目錄為$unzip_dir,稱$unzip_dir/net-snmp-5.4.1.2為$SourceDir. 2、使用VS2005打開$SourceDir/Win32下的win32sdk.dsw,點選“全部是”轉換VC工程。 3、修正Bug: 将libagent工程中的agent_registry.c檔案( 或$SourceDir/agent/agent_registry.c )中從第535行               netsnmp_assert(!"registration != duplicate");          修改為:              if (new_sub->namelen != 1)                    netsnmp_assert(!"registration != duplicate");                     4、編譯代碼前配置:$SourceDir/Win32/net-snmp/net-snmp-config.h頭檔案 a)、定義安裝位置宏INSTALL_BASE: #define INSTALL_BASE "C:/usr" (注意: 使用UNIX路徑分隔符'/') b)、定義PSDK使用宏(MIB-2支援):HAVE_WIN32_PLATFORM_SDK #define HAVE_WIN32_PLATFORM_SDK 1 5、編譯階段:此階段生成的庫檔案(*.lib)都已統一放在$SourceDir/Win32/lib目錄下,而生成的可執行工具都在$SourceDir/Win32/bin目錄下。 a)、生成庫檔案(*.lib) 在VS2005中依次Build如下工程( 注意順序! ), 方法:選中工程-->右鍵-->Rebuild --> libagent工程生成netsnmpagent.lib   --> libhelpers工程生成netsnmphelpers.lib   --> libsnmptrapd工程生成netsnmptrapd.lib   --> netsnmpmibssdk工程生成netsnmpmibs.lib   --> libsnmp工程生成netsnmp.lib(網上有文章說一定要最後生成此lib) b)、生成可執行工具程式( snmpd.exe, snmpget.exe……) VS2005菜單Build-->Batch Build...,選中除a)中已Build過的五個工程之外所有工程,生成Release版程式,點選Rebuild。 c)、編譯perl SNMP module要用到的DLL:netsnmp.dll。 配置$SourceDir/Win32/net-snmp/net-snmp-config.h頭檔案, 定義NETSNMP_USE_DLL宏: #define NETSNMP_USE_DLL 1 在vc中打開libdll.dsw,build-->Batch Build-->clean-->Batch Build-->Rebuild All 6、安裝 a)、打開$SourceDir/Win32/install-net-snmp.bat,確定安裝位置為c:/usr (與第四步 a)中設定一緻 )。 set INSTALL_BASE="c:/usr" ( 注意為windows分隔符'/' ) b)、打開指令提示符視窗,運作install-net-snmp.bat進行安裝。 此步會在c:/usr/目錄下安裝相應檔案。 c)、拷貝$SourceDir/Win32/local/*.bat檔案至c:/usr/bin/目錄下。 拷貝完之後c:/usr/bin下應該有22個檔案(*.exe + *.bat)。 d)、把c:/usr/bin加入到系統環境變量PATH. e)、測試: snmptranslate -IR -Td linkDown 會得到: IF-MIB::linkDown linkDown NOTIFICATION-TYPE  -- FROM       IF-MIB  OBJECTS       { ifIndex, ifAdminStatus, ifOperStatus }  DESCRIPTION   "A linkDown trap signifies that the SNMP entity, acting in            an agent role, has detected that the ifOperStatus object for            one of its communication links is about to enter the down            state from some other state (but not from the notPresent            state).  This other state is indicated by the included value            of ifOperStatus." ::= { iso(1) org(3) dod(6) internet(1) snmpV2(6) snmpModules(3) snmpMIB(1) snmpM IBObjects(1) snmpTraps(5) 3 } 7、配置代理 a)、打開C:/usr/bin/snmpconf.bat,檢查第2行是否為set MYPERLPROGRAM=c:/usr/bin/snmpconf,不是的話請改成這個。 b)、打開C:/usr/bin/snmpconf,查找所有/usr/local/并替換為C:/usr/。       該步驟必須執行,snmpconf中的檔案路徑采用的是UNIX下的/usr/local/,這裡必須改為Windows下的C:/usr/,但/符号仍然保持UNIX下的/符号,不用改成windows下的/符号,否則運作時會提示無法建立路徑。 c)、運作 snmpconf -i (在c:/usr/share/snmp/下生成snmp.conf檔案) 選擇 3: snmp.conf -->選擇 3: Textual mib parsing -->選擇 1: Specifies directories to be searched for mibs -->輸入 c:/usr/share/snmp/mibs -->輸入 finished回車  -->finished回車  -->quit回車,正常退出。 d)、将C:/usr/share/snmp目錄下的snmp.conf拷貝至C:/usr/etc/snmp目錄。 e)、拷貝$SourceDir/win32/EXAMPLE.conf.win32至C:/usr/etc/snmp目錄下,并改名snmpd.conf。 f)、修改snmpd.conf配置代理資訊。 主要是access control的設定,詳見其中注釋說明。 注:配置檔案主要有三個:snmpd.conf--------代理和管理站之間的通信參數,如通路控制、系統資訊、子代理資訊等 snmp.conf---------MIB庫設定 snmptraps.conf-----trap設定 檔案存在于幾個地方: 根目錄、c:/usr/etc/snmp, c:/usr/snmp/persist,以及 c:/usr/share/snmp/ (此目錄下多半為采用perl腳本程式snmpconf向導生成的檔案) 8、運作代理 cmd下輸入: snmpd -f -Le -d (輸出詳細收發資訊) 或 snmpd (不輸出詳細收發資訊) 或 snmpd Ip:port (運作于指定端口) 正常運作提示: NET-SNMP version 5.4.1.2 運作為一個程序,請不要關閉此視窗! 注:a)、如果提示以下資訊,表明無法綁定端口(預設agent為161,trapReceiver為162),請更改端口、或關閉占用該端口其他服務(如windows snmp service)。 Error opening specified endpoint ""        Server Exiting with code 1 b)、若出現以下資訊,表明未修正3中所說Bug。        netsnmp_assert x failed C:/net-snmp-5.4.1/net-snmp-5.4.1/agent/agent_registry.c: 535        netsnmp_assert x failed C:/net-snmp-5.4.1/net-snmp-5.4.1/agent/agent_registry.c: 535        netsnmp_assert x failed C:/net-snmp-5.4.1/net-snmp-5.4.1/agent/agent_registry.c: 535              9、測試        新開cmd視窗, 輸入:        snmpget -c public -v 2c localhost system.sysUpTime.0        目前視窗會得到:        DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (15400) 0:02:34.00        如果運作snmpd時使用了輸出詳細收發資訊,會在運作snmpd的視窗看到諸如下面的資訊:        Received 38 bytes from UDP: [127.0.0.1]:4712 0000: 30 24 02 01  01 04 03 7A  78 6D A0 1A  02 02 6C B4    0$.....zxm....l. 0016: 02 01 00 02  01 00 30 0E  30 0C 06 08  2B 06 01 02    ......0.0...+... 0032: 01 01 03 00  05 00                                    ...... Received SNMP packet(s) from UDP: [127.0.0.1]:4712  GET message    -- DISMAN-EVENT-MIB::sysUpTimeInstance Sending 40 bytes to UDP: [127.0.0.1]:4712 0000: 30 26 02 01  01 04 03 7A  78 6D A2 1C  02 02 6C B4    0&.....zxm....l. 0016: 02 01 00 02  01 00 30 10  30 0E 06 08  2B 06 01 02    ......0.0...+... 0032: 01 01 03 00  43 02 3C 28                              ....C.<(       

10、Perl SNMP Module安裝 注意:一定要使用DLL版的SNMP Lib,即5c)中生成的netsnmp.dll。且已經安裝好了靜态庫版本的NET-SNMP在$INSTALL_BASE下(Perl SNMP 子產品測試需要用到snmpd.exe 和 snmptrapd.exe)。 安裝依照$SourceDir/perl/snmp/readme說明文檔。 cmd下進入$SourceDir/,運作./nmakeperl.bat -->確定目前目錄已在$SourceDir/perl/下 -->nmake install 在我的安裝過程中,直至第9步都很順利,但是perl SNMP子產品的安裝出了點問題: nmake 不過。 nmake.out提示資訊如下: …… fatal error U1077: '"c:/program files/microsoft visual studio 8/vc/bin/cl.EXE"' : return code '0xc0000135' …… 網上有文章說是cl.exe找不到以下四個檔案:msobj80.dll、mspdb80.dll、mspdbcore.dll、mspdbsrv.exe 把這四個檔案從C:/Program Files/Microsoft Visual Studio 8/Common7/IDE拷到C:/Program Files/Microsoft Visual Studio 8/Vc/bin下後又出現問題: nmake.exe error LNK2001 unresolved external symbol……_security_cookie 網上也有解決方法,說是cl.exe的緩沖區安全檢查選項作怪,關掉即可(使用/Gs-), 可是指令行下不知怎麼關掉。 我的機子同時安裝了vs2005和vc6.0sp6. 最後換用vc6.0安裝目錄下的nmake、cl、link,安裝Microsoft Platform SDK for Windows Server 2003 SP1,最終解決此問題,詳細步驟如下: a)、安裝PSDK b)、Start Menu -->Programs ->Microsoft Platform SDK... ->Visual Studio Registration ->Register PSDK Directories with Visual Studio" c)、在windows環境變量PATH中,把vc6的nmake、cl、link路徑C:/Program Files/Microsoft Visual Studio/VC98/Bin加到最前面。 d)、把PSDK的D:/PROGRAM FILES/MICROSOFT PLATFORM SDK/INCLUDE、D:/PROGRAM FILES/MICROSOFT PLATFORM SDK/lib目錄分别加到include和lib環境變量中。 e)、用vc6.0打開libsdll.dsw。把PSDK的目錄加到VC6設定中去: 工具-->選項-->目錄,把D:/PROGRAM FILES/MICROSOFT PLATFORM SDK/INCLUDE加到include files的頂部,D:/PROGRAM FILES/MICROSOFT PLATFORM SDK/lib加到library files的頂部。 f)、把$Source/include/net-snmp/目錄拷到C:/Program Files/Microsoft Visual Studio/VC98/Include中去。(此步是否真需要?) g)、把$source/snmplib/winservice.c加到工程Libnetsnmptrapd中去。 h)、按照5 c)中編譯DLL的步驟重新編譯DLL i)、執行步驟6安裝 j)、運作nmakeperl.bat,可能會測試不通過,但沒問題。 k)、nmake install。安裝成功!

*********************************************************************************************** 運作nmakeperl.bat輸出: (其中 "E:/NMS/SNMP實作--20080825/有關Net-SNMP/net-snmp-5.4.1.2" 為我的源代碼目錄,也即$source) E:/NMS/SNMP實作--20080825/有關Net-SNMP/net-snmp-5.4.1.2>./win32/nmakeperl.bat Remember to run this script from the base of the source directory. Net-SNMP base directory: E:/NMS/SNMP實作--20080825/有關Net-SNMP/net-snmp-5.4.1.2 Net-SNMP base directory: E:/NMS/SNMP實作--20080825/有關Net-SNMP/net-snmp-5.4.1.2 Writing Makefile for NetSNMP::default_store Net-SNMP base directory: E:/NMS/SNMP實作--20080825/有關Net-SNMP/net-snmp-5.4.1.2 Writing Makefile for NetSNMP::ASN Net-SNMP base directory: E:/NMS/SNMP實作--20080825/有關Net-SNMP/net-snmp-5.4.1.2 Writing Makefile for NetSNMP::OID Net-SNMP base directory: E:/NMS/SNMP實作--20080825/有關Net-SNMP/net-snmp-5.4.1.2 Net-SNMP base directory: E:/NMS/SNMP實作--20080825/有關Net-SNMP/net-snmp-5.4.1.2 Writing Makefile for NetSNMP::agent::Support Net-SNMP base directory: E:/NMS/SNMP實作--20080825/有關Net-SNMP/net-snmp-5.4.1.2 Writing Makefile for NetSNMP::agent::default_store Writing Makefile for NetSNMP::agent Net-SNMP base directory: E:/NMS/SNMP實作--20080825/有關Net-SNMP/net-snmp-5.4.1.2 Writing Makefile for SNMP Net-SNMP base directory: E:/NMS/SNMP實作--20080825/有關Net-SNMP/net-snmp-5.4.1.2 Writing Makefile for NetSNMP::TrapReceiver Writing Makefile for Bundle::NetSNMP Make the Perl SNMP modules. If errors are seen stop here and review perl/nmake.out. 請按任意鍵繼續. . . Test the Perl SNMP modules. 終止批處理操作嗎(Y/N)? y E:/NMS/SNMP實作--20080825/有關Net-SNMP/net-snmp-5.4.1.2/perl> *********************************************************************************************** 運作nmake install 輸出: (其中"D:/Perl/"為我的Active Perl安裝目錄) E:/NMS/SNMP實作--20080825/有關Net-SNMP/net-snmp-5.4.1.2/perl>nmake install

Microsoft (R) Program Maintenance Utility   Version 6.00.8168.0 Copyright (C) Microsoft Corp 1988-1998. All rights reserved.        NMAKE -f Makefile all -nologo        cd ..        NMAKE -f Makefile all -nologo        cd ..        NMAKE -f Makefile all -nologo        cd ..        NMAKE -f Makefile all -nologo        NMAKE -f Makefile all -nologo        cd ..        NMAKE -f Makefile all -nologo        cd ..        cd ..        NMAKE -f Makefile all -nologo        cd ..        NMAKE -f Makefile all -nologo        cd .. Installing D:/Perl/site/lib/auto/NetSNMP/agent/agent.dll Installing D:/Perl/site/lib/auto/NetSNMP/agent/agent.exp Installing D:/Perl/site/lib/auto/NetSNMP/agent/agent.lib Installing D:/Perl/site/lib/auto/NetSNMP/agent/agent.pdb Installing D:/Perl/site/lib/auto/NetSNMP/agent/default_store/default_store.dll Installing D:/Perl/site/lib/auto/NetSNMP/agent/default_store/default_store.exp Installing D:/Perl/site/lib/auto/NetSNMP/agent/default_store/default_store.lib Installing D:/Perl/site/lib/auto/NetSNMP/agent/default_store/default_store.pdb Installing D:/Perl/site/lib/auto/NetSNMP/ASN/ASN.dll Installing D:/Perl/site/lib/auto/NetSNMP/ASN/ASN.exp Installing D:/Perl/site/lib/auto/NetSNMP/ASN/ASN.lib Installing D:/Perl/site/lib/auto/NetSNMP/ASN/ASN.pdb Installing D:/Perl/site/lib/auto/NetSNMP/default_store/default_store.dll Installing D:/Perl/site/lib/auto/NetSNMP/default_store/default_store.exp Installing D:/Perl/site/lib/auto/NetSNMP/default_store/default_store.lib Installing D:/Perl/site/lib/auto/NetSNMP/default_store/default_store.pdb Installing D:/Perl/site/lib/auto/NetSNMP/OID/OID.dll Installing D:/Perl/site/lib/auto/NetSNMP/OID/OID.exp Installing D:/Perl/site/lib/auto/NetSNMP/OID/OID.lib Installing D:/Perl/site/lib/auto/NetSNMP/OID/OID.pdb Installing D:/Perl/site/lib/auto/NetSNMP/TrapReceiver/TrapReceiver.dll Installing D:/Perl/site/lib/auto/NetSNMP/TrapReceiver/TrapReceiver.exp Installing D:/Perl/site/lib/auto/NetSNMP/TrapReceiver/TrapReceiver.lib Installing D:/Perl/site/lib/auto/NetSNMP/TrapReceiver/TrapReceiver.pdb Installing D:/Perl/site/lib/auto/SNMP/SNMP.dll Installing D:/Perl/site/lib/auto/SNMP/SNMP.exp Installing D:/Perl/site/lib/auto/SNMP/SNMP.lib Installing D:/Perl/site/lib/auto/SNMP/SNMP.pdb Files found in blib/arch: installing files in blib/lib into architecture depende nt library tree Appending installation info to D:/Perl/lib/perllocal.pod E:/NMS/SNMP實作--20080825/有關Net-SNMP/net-snmp-5.4.1.2/perl> 之後Perl SNMP子產品就可以運作了... **************************************************************************************************

繼續閱讀