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

net-snmp的编译

2013年08月17日 ⁄ 综合 ⁄ 共 6385字 ⁄ 字号 评论关闭

对net-snmp5.2.4静态交叉编译(arm-linux-gcc)后得到的各文件大小如下:

Snmpd  735k

Snmpset, snmpget, snmptrap, snmpusm 分别约为360k。

总计约2.2M。

5.2.4版本默认为静态编译,使用libtools的makefile工具编译。后要修改成动态编译,对libtools不熟,没有成功。

后来发现5.4.1版本同时存在静态与动态编译。5.4.1的交叉编译有一个bug,就是已经在配置中去掉了perl模块(使用./configure --without-perl-modules),但实际编译时还会去编译perl,我的arm-linux-交叉编译器没有perl库,所以编不过去。解决办法:去掉5.4.1版本的两个makefile中的libperl库,在apps/Makefile,agent/Makefile,vi中冒号模式下查找“/lperl”,删掉-lperl, 编译通过。

使用—enable-mini-agent选项,得到各个文件大小如下:

Libs:

Libnetsnmpagent.so    131k

Libnetsnmphelpers.so  118k

Libnetsnmp.so          53k

Libnetsnmpmibs.so     71k

Bin/Sbin:

Snmpd                 21k

Snmpusm              24.5k

Snmpvacm             20.7k

Snmpset               7.7k

Snmpget               6.3k

snmptrap              9k

    总计大小为453K

    在pc上试运行Miniagent之后(使用gcc编译),通过mibbrowser观察发现支持的mib很少,只有部分rfc1213-mib。

默认编译各个模块,得到各个文件大小如下:

Libs:

Libnetsnmpagent.so    127k

Libnetsnmphelpers.so   81k

Libnetsnmp.so         366k

Libnetsnmpmibs.so     509k

Bin/Sbin:

Snmpd                 18k

Snmpusm              24.5k

Snmpvacm             20.7k

Snmpset               7.7k

Snmpget               6.3k

snmptrap              9k

总计大小为1186K。默认的模块和mibs包括mibII,ucd_snmp, snmpv3mibs, notification, target, agent_mibs, agentx, utilities.

以上大小都为strip之后的值。如果去掉部分mibs,大小估计能缩小到1M以内。

2007.7.31

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

使用选项 --with-out-mib-modules="agentx", 编译之后,libnetsnmpagent.so变为94k,其它不变,缩小33k。

使用选项 --with-out-mib-modules="agentx host",编译之后,libnetsnmpmibs.so变为470k,其它不变,缩小72k。

使用选项 --with-out-mib-modules="agentx host disman/event disman/schedule",编译之后,libnetsnmpmibs.so变为408k,其它不变,缩小134。

使用选项 --with-out-mib-modules="agentx host disman/event disman/schedule ucd_snmp",编译之后,libnetsnmpmibs.so变为338k,其它不变,缩小204k。 目前netsnmp总体大小为964k。

添加选项--disable-mib-loading,则libnetsnmphelpers.so为78k,libnetsnmp.so为288k。缩小285k。目前总体大小为883k。但是对于这个选项是否可用,具体情况还不知道。该选项好像是去除对mibfiles的解析的代码。

 

 

 

net-snmp的配置脚本及其他

在配置之前先设置一下环境变量:

source /home/peter/WP701/environment.linux.sh

主要是设置交叉编译器的路径和工程中某些模块的路径。

net-snmp的配置脚本:

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

#!/bin/bash
target=net-snmp5.4_v3_arm_almost
prefix_path=`pwd`/tmp/${target}
exec_prefix_path=${prefix_path}/exec

./configure --host=arm-linux /
            --with-endianness=little  /
            --without-perl-modules /
            --disable-perl-cc-checks /
            --disable-ipv6        /
            --without-rpm        /
            --prefix=${prefix_path}   /
            --exec-prefix=${exec_prefix_path}   /
            --disable-manuals      /
            --disable-scripts      /
            --disable-debugging   /
            #--enable-mini-agent    /
            #--disable-applications  /
            #--disable-mib-loading 
            #!--with-mib-modules="mibII snmpv3mibs ucd_snmp agent_mibs notification target agentx utilities"

#! if don't want to build some modules add:        

#--with-out-mib-modules="agentx utilities ***"  /

 #!default setup modules: mibII snmpv3mibs ucd_snmp agent_mibs notification target agentx utilities

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

有非常多的配置选项,上面只用到了一点点,具体得看configure.in这个配置文件,不过内容相当多,有3千多行。运行该脚本之后,就生成了各个Makefile,然后make,makeinstall, 就安装好了net-snmp,安装在${prefix_path}指定的目录下,包括lib,bin,sbin,share,include目录。mibs的txt文件在share/snmp/mibs/下面,在运行时好像是没有用的,是为了开发才放在那里的,好像是...^^,有待证实。

FAQ中有这么一个问题:Do I actually need the MIB files?
--------------------------------

  Probably not.
  The MIB files play two main roles - they are used to translate
  between numeric OIDs and the corresponding textual names, and
  they define the structure and syntax of the relevant MIB objects.

    This second role is perhaps best thought of in terms of a design
  document.  It's vital while developing an application (typically
  the MIB module or handler within the agent), since it defines
  what the application (MIB) must actually do.  But once the code
  has been written, the design document becomes redundent.
  The agent then has the same information hardcoded into it
  (literally!), and no longer needs the MIB file.

    The translation task is not strictly necessary - SNMP will
  operate fine without any MIB files at all, as long as you're
  happy to work with numeric OIDs throughout, and know which MIB
  objects you're interested in.  But it's much easier to work with
  the (hopefully) meaningful names, enumeration tags and the like,
  and to view the description of a particular object.
  This requires having the relevant MIB files installed and loaded.

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

对于减小占用资源,FAQ中的下面两个问题可能会有帮助:

How can I reduce the memory footprint?
--------------------------------------

  In order to reduce the memory footprint (for instance, to
  embed the snmpd into a device), the following configure options
  could be used.

  '--disable-debugging'
     This turns off the compilation of all debugging statements.

  '--enable-mini-agent' '--with-out-mib-modules=examples/ucdDemoPublic'
     This creates an agent with just the essential MIB modules included.
     NOTE: If you need additional MIB modules, then simply add them
     using the option '--with-mib-modules=...' but this will of course
     increase the memory footprint.

  '--with-transports=UDP'
     This option specifies the transport domains to include.
     For a simple standalone agent, just UDP should be sufficient.
     (Although the 'disman' and 'agentx' modules may require the
      Callback, TCP and/or Unix transport domains as well).

   '--without-kmem-usage'
     This can be used in order to omit the code that operates on the
     /dev/kmem interface. Clearly, this option cannot be used when
     one of the configured MIB modules depends on it.

   '--with-mibdirs=' and '--with-mibs='
     These options tell the agent not to load any MIB modules.
     This doesn't affect the size of libraries or application
     binaries, but will reduce the memory footprint during runtime.

   '--disable-mib-loading'
     This can be used in order to omit the code that loads and
     parses the MIB files altogether.  This will reduce both the
     runtime memory footprint, and the binary sizes.

  Once the agent (snmpd) has been linked, you might also try running
  'strip snmpd' to remove un-necessary debug/symbol information.

 

How can I reduce the installation footprint or speed up compilation?
-------------------------------------------------------------------

  If you are using net-snmp v5.1 or above, then the following
  configure options may be useful to you:
                                                                               
  --disable-agent                 Do not build the agent (snmpd).
  --disable-applications          Do not build the apps (snmpget, ...).
  --disable-manuals               Do not install the manuals.
  --disable-scripts               Do not install the scripts (mib2c, ...).
  --disable-mibs                  Do not install the mib files.
  --disable-mib-loading           Do not include code that parses and
                                  manipulates the mib files.

抱歉!评论已关闭.