[转]VS2005下编译、安装Net-snmp 5.4.1.2

来源:互联网 发布:时时彩平台程序源码 编辑:程序博客网 时间:2024/05/29 19:09
 

VS2005下编译、安装Net-snmp 5.4.1.2手记


 by Flyfish <zxm0718@yahoo.com.cn>
 
========================================================
 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"); /* always false */
         修改为:
             if (new_sub->namelen != 1) /* ignore root OID dups */
                   netsnmp_assert(!"registration != duplicate"); /* always false */
                  
 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模块就可以运行了...

原创粉丝点击