目录
1. 平台信息
2. SNMP协议
3. 移植和交叉编译SNMP
3.1 下载源码
3.2 配置configure,生成.config文件
3.3 编译安装
3.4 配置文件snmp.conf的修改
4. 移植到目标板
4.1指令流程:
4.2 运行snmpd
4.3 注意事项
4.3.1 iptables 防火墙对外开放udp:161端口访问权限
4.3.2 确保udp:161端口不被占用(161是snmp默认端口,一般情况下不会被其他占用)
4.3.3 mibs文件路径可以不用指定,运行也没有问题,但是snmpd.conf配置文件路径必需要指定。
5. snmp测试
5.1 SNMP 的网络架构
5.1.1 NMS(网络管理站)
5.1.2 Agent 代理
5.1.3 MIB 管理信息库
5.2 SNMP 的测试
Linux:VMware® Workstation 12 Pro + Ubuntu 12.04 64bit
ARM:ZLG EPC-M6G2C 工控主板
涉及工具:SecureCRT(串口终端)、SugarNMSTool 智和网管软件
交叉工具链:arm-linux-gnueabihf-gcc (gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux)
SNMP源码版本:net-snmp-5.7.3
SNMP是简单的网络管理协议,它不是一个软件,而是用于网络管理的一套规则。利用SNMP,一个管理工作站可以远程管理所有支持这种协议的网络设备,包括监视网络状态、修改网络设备配置、接收网络事件警告等。
但话又说回来,为什么要使用SNMP协议?
因为网络设备可能来自不同的厂商,如果每个厂商提供一套独立的管理接口,将使网络管理变得越来越复杂,若想对网络中来自不同厂商的设备监控,用基于SNMP开发的软件进行管理最方便的,因为大部分的设备都支持SNMP协议。
更多:
https://blog.csdn.net/bbwangj/article/details/80981098
https://blog.csdn.net/shmily_cml0603/article/details/12968157
官网下载地址:http://www.net-snmp.org/download.html
本次下载的是5.7.3版本:https://sourceforge.net/projects/net-snmp/files/net-snmp/5.7.3/
选择下载压缩包:net-snmp-5.7.3.tar.gz
在指定目录下,解压缩源码包:
root@Linux-host:~/hu/SNMP# tar -xzvf net-snmp-5.7.3.tar.gzsnmp的configure配置,可以使用./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最小化构建agent--disable-deprecated不编译弃用的功能--without-logfile指定snmpd不输出日志文件(可以使用--with-logfile指定默认日志文件位置)--disable-minimalist删除所有非基本的代码功能–enable-debugging打开调试信息--disable-testing-code不使用测试代码(某些代码不被使用)–with-openssl=/opt/hardhatopenssl库路径(用于支持加密等)–disable-ipv6不使用IPv6–disable-manuals不安装manpage说明页–disable-ucd-snmp-compatibility不需要兼容ucd-snmp–disable-snmptrapd-subagent不用支持snmptrapd的子代理–disable-embedded-perl在SNMP代理和snmptrapd禁用嵌入式Perl。默认启用–disable-applications是否关闭snmpget等功能,根据自己的需要选择--with-default-snmp-version="3"指定默认协议版本--enable-as-needed仅链接需要库,不链接不必要的库(如果只使用其他方法行不通,链接libperl针对应用而非Net-SNMP库。)对于交叉编译,我的配置如下:
root@Linux-host:~/hu/SNMP/net-snmp-5.7.3# ./configure --host=arm-linux \ --build=i686-linux --with-cc=arm-linux-gnueabihf-gcc \ --with-ar=arm-linux-gnueabihf-ar --with-endianness=little \ --disable-ipv6 --disable-embedded-perl --disable-shared \ --prefix=/root/hu/SNMP/arm-snmp
其中
--with-cc=arm-linux-gnueabihf-gcc需要自己根据情况而定,
--disable-ipv6 取消ipv6的支持
--disable-embedded-perl 不加这一配置,会报错找不到perl库,如下提示:
/usr/bin/ld: cannot find -lperl collect2: error: ld returned 1 exit status make[1]: *** [libnetsnmpagent.la] 错误 1也可以安装相关库:
sudo apt-get install libperl-dev没有出错时,最后提示信息:
... --------------------------------------------------------- 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 ucd_snmp notification notification-log-mib target agent_mibs agentx disman/event disman/schedule utilities host MYSQL Trap Logging: unavailable Embedded Perl support: disabled SNMP Perl modules: disabled SNMP Python modules: disabled Crypto support from: internal Authentication support: MD5 SHA1 Encryption support: DES AES Local DNSSEC validation: disabled ---------------------------------------------------------编译:
root@Linux-host:~/hu/SNMP/net-snmp-5.7.3# make ... chmod a+x net-snmp-config touch net-snmp-config-x用arm-linux-gnueabihf-strip工具可以对生成的snmpd进行瘦身:
root@Linux-host:~/hu/SNMP/net-snmp-5.7.3# ll agent/snmpd -rwxr-xr-x 1 root root 6528914 7月 2 15:07 agent/snmpd* root@Linux-host:~/hu/SNMP/net-snmp-5.7.3# arm-linux-gnueabihf-strip agent/snmpd root@Linux-host:~/hu/SNMP/net-snmp-5.7.3# ll agent/snmpd -rwxr-xr-x 1 root root 1336548 7月 2 15:08 agent/snmpd*由上可以看出,snmpd由6M多变为1.3M
安装:
root@Linux-host:~/hu/SNMP/net-snmp-5.7.3# make install之后可以在指定的目录下得到安装后的文件。
root@Linux-host:~/hu/SNMP/net-snmp-5.7.3# cd ../arm-snmp/ root@Linux-host:~/hu/SNMP/arm-snmp# ls bin include lib sbin share先将示例的配置文件拷贝到安装目录下:
root@Linux-host:~/hu/SNMP/net-snmp-5.7.3# cp EXAMPLE.conf ../arm-snmp/share/snmp/snmpd.conf
后进行修改:
root@Linux-host:~/hu/SNMP/arm-snmp# vim share/snmp/snmpd.conf
修改1:打开对外udp:161端口
# Listen for connections from the local system only #agentAddress udp:127.0.0.1:161 #注释掉 # Listen for connections on all interfaces (both IPv4 *and* IPv6) #agentAddress udp:161,udp6:[::1]:161agentAddress udp:161 #添加
修改2:选择SNMP协议版本
# # ACTIVE MONITORING #
# send SNMPv1 traps #trapsink localhost public # send SNMPv2c trapstrap2sink localhost public # send SNMPv2c INFORMs #informsink localhost public
修改3:设置访问权限
# # ACCESS CONTROL #
# system + hrSystem groups only view systemonly included .1.3.6.1.2.1.1 view systemonly included .1.3.6.1.2.1.25.1
# Full access from the local host #rocommunity public localhost # Default access to basic system info # rocommunity public default -V systemonlyrocommunity public default
将make install生成目录下的sbin/snmpd 以及 share/snmp/mibs/ + snmpd.conf(修改过的),打包为arm-net-snmp-5.7.3.tar,拷贝到SD卡中,最后拷贝到ARM板上。
snmpd命令选项:
注: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 -f do not fork from the shell依次可执行:
[root@EPC-M6G2C arm-net-snmp-5.7.3]# snmpd -c /usr/local/share/snmp/snmpd.conf - f -Le -d -M /usr/local/share/snmp/mibs/ Turning on AgentX master support. Failed to create the persistent directory for /var/net-snmp/snmpd.conf read_config_store open failure on /var/net-snmp/snmpd.conf Failed to create the persistent directory for /var/net-snmp/snmpd.conf read_config_store open failure on /var/net-snmp/snmpd.conf Failed to create the persistent directory for /var/net-snmp/snmpd.conf read_config_store open failure on /var/net-snmp/snmpd.conf Failed to create the persistent directory for /var/net-snmp/snmpd.conf read_config_store open failure on /var/net-snmp/snmpd.conf Failed to create the persistent directory for /var/net-snmp/snmpd.conf read_config_store open failure on /var/net-snmp/snmpd.conf Failed to create the persistent directory for /var/net-snmp/snmpd.conf read_config_store open failure on /var/net-snmp/snmpd.conf Failed to create the persistent directory for /var/net-snmp/snmpd.conf read_config_store open failure on /var/net-snmp/snmpd.conf Failed to create the persistent directory for /var/net-snmp/snmpd.conf read_config_store open failure on /var/net-snmp/snmpd.conf Failed to create the persistent directory for /var/net-snmp/snmpd.conf read_config_store open failure on /var/net-snmp/snmpd.conf Failed to create the persistent directory for /var/net-snmp/snmpd.conf read_config_store open failure on /var/net-snmp/snmpd.conf Failed to create the persistent directory for /var/net-snmp/snmpd.conf read_config_store open failure on /var/net-snmp/snmpd.conf Failed to create the persistent directory for /var/net-snmp/snmpd.conf read_config_store open failure on /var/net-snmp/snmpd.conf Failed to create the persistent directory for /var/net-snmp/snmpd.conf read_config_store open failure on /var/net-snmp/snmpd.conf Failed to create the persistent directory for /var/net-snmp/snmpd.conf read_config_store open failure on /var/net-snmp/snmpd.conf Failed to create the persistent directory for /var/net-snmp/snmpd.conf read_config_store open failure on /var/net-snmp/snmpd.conf Failed to create the persistent directory for /var/net-snmp/snmpd.conf read_config_store open failure on /var/net-snmp/snmpd.conf Sending 44 bytes to UDP: [127.0.0.1]:162->[0.0.0.0]:0 0000: 30 2A 02 01 00 04 06 70 75 62 6C 69 63 A4 1D 06 0*.....public... 0016: 0A 2B 06 01 04 01 BF 08 03 02 0A 40 04 C0 A8 0A .+.........@.... 0032: 74 02 01 00 02 01 00 43 01 62 30 00 t......C.b0. NET-SNMP version 5.7.3 Sending 1 bytes to callback: 2 on fd 5 0000: 00 . Received 1 byte packet from callback: 1 on fd 3 0000: 00 . Sending 1 bytes to callback: 1 on fd 3 0000: 00 . Received 1 byte packet from callback: 2 on fd 5 0000: 00 . Sending 1 bytes to callback: 2 on fd 5 0000: 00 . Received 1 byte packet from callback: 1 on fd 3 0000: 00 . Sending 1 bytes to callback: 1 on fd 3 0000: 00 .可以看出运行正常,有发送和接受的udp数据包。
可用命令查看当前情况:
iptables -L
可用命令查看端口情况:
netstat -an |grep 161
明天再写,先下班。
SNMP网络架构由三部分组成:NMS(网络管理站)、Agent(代理)、MIB(管理信息库)
NMS是网络中的管理者,是一个利用SNMP协议对网络设备进行管理和监视的系统。可以是一台专门用来进行网络管理的服务器,也可以指某个设备中之中管理功能的一个应用程序。
NMS可以向Agent发出请求,查询或修改一个或多个具体的参数值。同时,NMS可以接收Agent主动发送的Trap信息,以获知被管理设备当前的状态
Agent是网络设备中的一个应用模块,用于维护被管理设备的信息数据,并响应NMS的请求,把管理数据汇报给发送请求的NMS。
Agent接收到NMS的请求信息后,完成查询或修改操作,并把操作结果发送给NMS,完成响应。同时,当设备发生故障或者其他事件的时候,Agent会主动发送Trap信息给NMS,通知设备当前的状态变化。
任何一个被管理的资源都表示成一个对象,称为被管理的对象。MIB就是被管理对象的集合。它定义了被管理对象的一系列的属性:对象的名称、对象的访问权限和对象的数据类型等。每个Agent都有自己的MIB。MIB也可以看做是NMS和Agent之间的一个接口,通过这个接口,NMS可以对Agent中的每一个被管理对象进行读/写操作,从而达到管理和监控设备的目的
NMS、Agent 和 MIB 之间的关系如图所示:
MIB的结构:
MIB是以树状结构进行存储的,树的节点表示被管理对象,它可以用从根开始的一条路径唯一地识别,这条路径就称为OID。
如图所示,管理对象system可以用一串数字{1.3.6.1.2.1.1}唯一标识,这串数字就是system的OID。
首先,在板端运行snmpd 服务进程,详见4.2;
然后用网线将板端的网口与windows相连,必要时手动修改Windows IP,确保板端与Windows处于同一网域;
最后在windows平台下运行SugarNMSTool 网络管理工具,运行效果如下。
如上图所示
IP : 192.168.10.116 是ARM的地址,搜索设备时,可以按这一网段进行搜索。
SNMP5.7.3的源码包 以及 SugarNMSTool 工具的下载链接(其中包含使用说明):
https://download.csdn.net/download/sunny_hu92/12572162
以上就是这两天时间来,完成的SNMP在Linux下交叉编译和移植到ARM板,以及利用NMS工具测试的全部流程,期间也遇到很多坑,关键点在于./configure的配置参数,大家一定要注意。以此博文记录,以备后查。
20200703