Files
Knowledge/1 使用/Linux/SNMP_23013RK75C_Dec-26-2235-2024_1.md

5.5 KiB
Raw Permalink Blame History

监测管理网络设备的工具。SNMP="Simple Network Management Protocol"="简单网络管理协议",应用层协议,传输层一般采用UDP。SNMP采用 UDP 161端口接收和发送请求,162端口接收trap。

SNMP 目前共有 3 个版本,分别为 v1、v2 和 v3,说明如下:

  • SNMP v1:是 SNMP 协议的最初版本,在 1988 年被制定,并被 Internet 体系结构委员会(IAB)采纳作为一个短期的网络管理解决方案。不过依然是众多厂家实现SNMP基本方式。
  • SNMP v2:是 1992 年发布的 SNMP 的第二个版本。它修订了第一版,并且在性能、安全、机密性和管理者之间通信等方面进行了大量改进。通常被指是基于community的SNMP V2。Community实质上就是密码。
  • SNMP v3:是目前最新的版本。它是 2004 年制定的,协议编号为 RFC3411-RFC3418(STD0062)。它为提升协议的安全性,增加了认证和密文传输功能,它对网络管理最大的贡献在于其安全性

架构

SNMP网络架构组成:NMS(网络管理站)、Agent(代理)、MIB(管理信息库)

Agent(代理)运行在被管理的网络节点上。 NMS(网络管理站)负责收集维护各个SNMP 元素的信息(NMS主动向Agent请求,或Agent主动SNMP trap 上传),能请求/上传哪些内容去MIB中读取(MIB定义了设备中的被管理对象)。

!7c1f20e259bd77445fba6dd39df75b22_f0a37d4194ff4267bfedd0e8e852b3dd.png

配置

cd /etc/snmp/

有 snmpd.conf 、snmptrapd.conf 两个配置文件。

允许远程主机访问

默认情况下,snmp服务只是对本地开启,是无法通过远程获取该主机的snmp信息的:

root@apig:/etc/snmp# sudo netstat -antup | grep 161
udp        0      0 127.0.0.1:161           0.0.0.0:*                           19410/snmpd

可以看到,161端口只对本机开放(161端口号是snmp服务的端口号),我们需要修改一下,让snmp服务对外开放。

修改/etc/snmp/snmpd.conf配置文件,大概在15行,将下面一行注释掉:

agentAddress  udp:127.0.0.1:161

同时去掉下面这一行的注释:

#agentAddress udp:161,udp6:[::1]:161

在这里插入图片描述

 重新启动snmp服务,再通过命令观察:

root@apig:/etc/snmp# sudo service snmpd restart
root@apig:/etc/snmp# sudo netstat -antup | grep 161
udp        0      0 0.0.0.0:161             0.0.0.0:*                           19770/snmpd         
udp6       0      0 ::1:161                 :::*                                19770/snmpd

配置共同体(可理解为密码)

snmpd.conf 中需要配置

rocommunity public
syslocation "Your Location"
syscontact your@email.com

SNMP community strings leverage a user ID or password to access the router or other device information. SNMP community strings are only available with SNMPv1 and SNMPv2c protocols. SNMPv3 requires username/password authentication as well as an encryption key. Many SNMPv1 and v2c devices are shipped with a “public” read-only community string. Most network administrators customize the community strings in the device settings as a best practice.

自行修改

rocommunity sunyard
syslocation "Hangzhou Zhejiang China"
syscontact scm@sunyard.com

!Pasted image 20241023152807.png

SNMP OID

Network Interface Statistics List NIC names: .1.3.6.1.2.1.2.2.1.2 Get Bytes IN: .1.3.6.1.2.1.2.2.1.10 Get Bytes IN for NIC 4: .1.3.6.1.2.1.2.2.1.10.4 Get Bytes OUT: .1.3.6.1.2.1.2.2.1.16 Get Bytes OUT for NIC 4: .1.3.6.1.2.1.2.2.1.16.4

CPU Statistics Load 1 minute Load: .1.3.6.1.4.1.2021.10.1.3.1 5 minute Load: .1.3.6.1.4.1.2021.10.1.3.2 15 minute Load: .1.3.6.1.4.1.2021.10.1.3.3

CPU times percentage of user CPU time: .1.3.6.1.4.1.2021.11.9.0 raw user cpu time: .1.3.6.1.4.1.2021.11.50.0 percentages of system CPU time: .1.3.6.1.4.1.2021.11.10.0 raw system cpu time: .1.3.6.1.4.1.2021.11.52.0 percentages of idle CPU time: .1.3.6.1.4.1.2021.11.11.0 raw idle cpu time: .1.3.6.1.4.1.2021.11.53.0 raw nice cpu time: .1.3.6.1.4.1.2021.11.51.0

Memory Statistics Total Swap Size: .1.3.6.1.4.1.2021.4.3.0 Available Swap Space: .1.3.6.1.4.1.2021.4.4.0 Total RAM in machine: .1.3.6.1.4.1.2021.4.5.0 Total RAM used: .1.3.6.1.4.1.2021.4.6.0 Total RAM Free: .1.3.6.1.4.1.2021.4.11.0 Total RAM Shared: .1.3.6.1.4.1.2021.4.13.0 Total RAM Buffered: .1.3.6.1.4.1.2021.4.14.0 Total Cached Memory: .1.3.6.1.4.1.2021.4.15.0

Disk Statistics Add the following line to snmpd.conf and restart: includeAllDisks 10% for all partitions and disks

Disk OID's Path where the disk is mounted: .1.3.6.1.4.1.2021.9.1.2.1 Path of the device for the partition: .1.3.6.1.4.1.2021.9.1.3.1 Total size of the disk/partion (kBytes): .1.3.6.1.4.1.2021.9.1.6.1 Available space on the disk: .1.3.6.1.4.1.2021.9.1.7.1 Used space on the disk: .1.3.6.1.4.1.2021.9.1.8.1 Percentage of space used on disk: .1.3.6.1.4.1.2021.9.1.9.1 Percentage of inodes used on disk: .1.3.6.1.4.1.2021.9.1.10.1

System Uptime: .1.3.6.1.2.1.1.3.0

什么是SNMP trap?

被管理设备主动上发消息

参考