snmpd的移植

来源:互联网 发布:蚂蚁网络电视手机版 编辑:程序博客网 时间:2024/04/30 14:23
1 下载
 
www.net-snmp.org
本系统使用版本: net-snmp-5.1.4
2 交叉编译

解压缩有进入源码目录键入 ./configure --help 查看配置选项

CC=ppc_440ep-gcc               确定交叉编译工具
LD=ppc_440ep-ld                确定交叉链接工具
--prefix=/home/work/lxg/snmp   指定安装路径
--with-perl-modules            指定编译Perl模块
--build=BUILD                  指定在BUILD进行编译
--host=ppc-linux               指定编译好的程序在什么类型机器上运行
--target=ppc-linux             制定目标系统
--with-endianness=little       指定目标机的大小端  注意:powerPC为大端  这里应设为big
--with-cc=ppc_440ep-gcc        确定交叉编译工具
--with-ar=ppc_440ep-ar         确定编译库的工具
--with-mibdirs=  
--with-mibdirs=
--with-mibfiles
--disable-applications         指定不编译SNMP的应用(即snmpget、snmpgetnext等)
--disable-manuals              指定不编译manual手册
--disable-debugging            指定不编译debug信息
--disable-scripts   指定不安装Perl脚本
--disable-snmptrapd-subagent

了解编译选项后我们开始编译

CC=ppc_440ep-gcc ./configure --host=ppc-linux --prefix=/home/work/lxg/snmp  --enable-mini-agent --disable-ipv6 --with-endianness=big --disable-applications --disable-manuals --disable-scripts --disable-ucd-snmp-compatibility

运行configure的过程中需要选择几项,可以一路回车使用默认值
由于没有安装某些依赖库,所以这里采用静态编译
make LDFLAGS="-static"
make install


完成后在 /home/work/lxg/snmp 下会生成相应的文件夹,我们所要的文件都在此。

3 配置

由于本系统只需要snmp代理(即snmpd)因此如使其正常运行只需 snmpd snmp.conf 和 mib文件
静态编译的snmpd大概有1.3M,strip后600K,snmp.conf可以从源码里拷贝,然后是mib文件,如最小启动只需三个文件 :
SNMPv2-MIB.txt
SNMPv2-SMI.txt
SNMPv2-TM.txt
本系统mibs路径为 /usr/share/snmp/mibs

snmp.conf的配置
其实配制一个snmpd.conf文件不算太难,
(1) 首选是定义一个共同体名(community),这里是public,及可以访问这个public的用户名(sec name),这里是notConfigUser。Public相当于用户notConfigUser的密码:)

# sec.name source          community
com2sec notConfigUser default       public

(2) 定义一个组名(groupName)这里是notConfigGroup,及组的安全级别,把notConfigGroup这个用户加到这个组中。

groupName      securityModel securityName
group   notConfigGroup   v1      notConfigUser
group   notConfigGroup   v2c     notConfigUser

(3) 定义一个可操作的范围(view)名, 这里是all,范围是 .1

#name  incl/excl     subtree      mask(optional)
view all             included     .1

(4) 定义notConfigUser这个组在all这个view范围内可做的操作,这时定义了notConfigUser组的成员可对.1这个范围做只读操作。
#group          context sec.model sec.level prefix read   write notif
access notConfigGroup ""      any       noauth    exact all none none

配置完snmp.conf后拷贝到目标板/etc下

运行snmpd
将snmpd拷贝目标版/bin 或 /sbin 下后键入:

snmpd -Lsd -c /etc/snmp.conf -M /usr/share/snmp/mibs

注:snmpd命令的有用选项
-c FILE                指定文件为配置文件
-C                     不读取默认的配置文件
-d                     dump接收和发送SNMP数据包
-D TOKEN               对于给定的TOKEN(标志)打开调试信息   ( -Dmib_init)
-I [-]INITLIST    对于要初始化的MIB列表显示
-M DIRLIST        指定MIB库的路径
-V                显示详细信息
-Le                     把错误信息输出到日志中
-Lf FILE                 把错误信息输出到指定文件中
-m MIBLIST        use MIBLIST instead of the default MIB list