net-snmp的編譯

對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.

發佈了4 篇原創文章 · 獲贊 0 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章