您的位置:首页 > 运维架构 > Linux

net-snmp5.7.3移植到arm-linux平台

2015-09-16 20:50 711 查看

net-snmp5.7.3移植到arm-linux平台

本次交叉编译在ubuntu 15.04 64位系统下进行。

准备工作

在编译移植前有几项准备工作需要完成。

1下载net-snmp 5.7.3源码包

2安装交叉编译环境(arm-linux-gnueabi-gcc)

使用命令
sudo apt-get install gcc-arm-linux-gnueabi
安装即可。

编译配置

解压net-snmp源码包,然后进入源码包目录

unzip net-snmp-5.7.3.zip
cd net-snmp-5.7.3/

可以使用
./configure --help
查看一下配置选项有那些。这里不贴了,直接给出。

选项说明
–host=arm-linux运行平台
–target=arm-linux目标平台
–build=i686-linux编译平台
–with-cc=arm-linux-gcc交叉编译器
–with-ar=arm-linux-ar使用的程序打包
–prefix=/usr/local/net-snmp安装目录
–disable-shared静态编译
–disable-scripts不要安装mib2c等脚本
–with-endianness=little指定小端模式
-enable-mini-agent最小的snmpd
–enable-debugging打开调试信息
–with-openssl=/opt/hardhatopenssl库路径
–disable-ipv6不使用IPv6
–disable-manuals不安装manpage说明页
–disable-ucd-snmp-compatibility不需要兼容ucd-snmp
–enable-as-needed如果只使用其他方法行不通,链接libperl针对应用而非Net-SNMP库。
–disable-snmptrapd-subagent不用支持snmptrapd的子代理
–disable-embedded-perl在SNMP代理和snmptrapd禁用嵌入式Perl。默认启用
–disable-applications是否关闭snmpget等功能,根据自己的需要选择
--with-default-snmp-version="3"指定默认协议版本
--enable-as-needed 仅链接需要库,不链接不必要的库
下面是我使用的配置

configure

./configure --host=arm-linux --target=arm-linux --build=i686-linux  --with-cc=arm-linux-gnueabi-gcc-4.9 --with-ar=arm-linux-gnueabi-gcc-ar-4.9 --prefix=/usr/local/net-snmp --disable-shared --disable-scripts --with-endianness=little -enable-mini-agent --disable-ipv6 --disable-manuals  --disable-ucd-snmp-compatibility --enable-as-needed

配置的时候你可以指定一个空目录来作为安装目录,比如
/home/o/123
。那么
make
成功后可以
make install
来安装。移植到
arm
开发板上的时候可以直接将这个目录打包拷贝过去。

configre成功输出的信息

---------------------------------------------------------
Net-SNMP configuration summary:
---------------------------------------------------------

SNMP Versions Supported:    1 2c 3
Building for:               linux
Net-SNMP Version:           5.7.3
Network transport support:  Callback Unix Alias TCP UDP IPv4Base SocketBase TCPBase UDPIPv4Base UDPBase
SNMPv3 Security Modules:     usm
Agent MIB code:            default_modules =>  snmpv3mibs mibII/snmp_mib mibII/system_mib mibII/sysORTable mibII/vacm_vars mibII/vacm_conf
MYSQL Trap Logging:         unavailable
Embedded Perl support:      disabled
SNMP Perl modules:          building -- not embeddable
SNMP Python modules:        disabled
Crypto support from:        internal
Authentication support:     MD5 SHA1
Encryption support:         DES AES
Local DNSSEC validation:    disabled

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

编译

配置成功后使用
make
命令编译一下。

编译成功后将输出下面两行。

chmod a+x net-snmp-config
touch net-snmp-config-x

编译完成后可以进入agent文件夹,看是否输出了
snmpd
文件。

o@o-pc:~/snmp/net-snmp-5.7.3/agent$ ll snmpd
-rwxrwxr-x 1 o o 3029820  9月 16 20:31 snmpd*

o@o-pc:~/snmp/net-snmp-5.7.3/agent$ file snmpd
snmpd: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=735ab05f48664e1af99c639e6519893be9413d2b, not stripped

压缩可执行文件

编译完成之后是可以直接拿过去用的,但是也可以先压缩一下来节约空间。使用
arm-linux-gnueabi-strip
程序来压缩

o@o-pc:~/snmp/net-snmp-5.7.3/agent$ arm-linux-gnueabi-strip snmpd
o@o-pc:~/snmp/net-snmp-5.7.3/agent$ ll snmpd
-rwxrwxr-x 1 o o 703836  9月 16 20:51 snmpd*

可以看出,压缩之后可执行文件的大小由接近
3MB
降到了不到
700KB


安装到目标平台

编译成功后就可以安装到目标平台了。首先拷贝出
agent
目录下的
snmpd
文件到目标机器。

然后再在目标机器上创建
snmpd.conf
配置文件,具体怎么配置,可以参考/content/4271917.html的第五部分。

然后就可以启动试试了。

sudo ./snmpd -c snmpd.conf  –f –Le –d

出现的问题与解决方法

没有perl库的问题

编译的时候出现找不到perl库的问题,这个问题其实也好解决,编译一个就是嘛。但是呢,没有这个必要,麻烦。

/usr/lib/gcc-cross/arm-linux-gnueabi/4.9/../../../../arm-linux-gnueabi/bin/ld: cannot find -lperl
collect2: error: ld returned 1 exit status
Makefile:484: recipe for target 'libnetsnmpagent.la' failed
make[1]: *** [libnetsnmpagent.la] Error 1
make[1]: Leaving directory '/home/o/snmp/net-snmp-5.7.3/agent'
Makefile:656: recipe for target 'subdirs' failed
make: *** [subdirs] Error 1

解决办法

其实很简单,将之前
configure
配置的时候加上一个参数
--disable-embedded-perl
,然后再次
make
就可以了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: