net-snmp的定製編譯

對net-snmp5.2.4靜態交叉編譯(arm-linux-gcc)後獲得的各文件大小以下:linux

Snmpd  735kbash

Snmpset, snmpget, snmptrap, snmpusm 分別約爲360k。app

總計約2.2M。dom

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, 編譯經過。ui

使用—enable-mini-agent選項,獲得各個文件大小以下:this

Libs:debug

Libnetsnmpagent.so    131krest

Libnetsnmphelpers.so  118kcode

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.

相關文章
相關標籤/搜索