armbian系统安装和卸载snmp服务(SNMPV2操作版本)

2023-12-13 10:35:14


在这里插入图片描述

说明

  • 由于各位小伙伴,可能在安装过程中出现意外或者其他情况,本文先说明卸载步骤,然后再介绍安装步骤

基知

  • SNMP (Simple Network Management Protocol) 是一种网络管理协议,用于监控和管理网络设备
  • MIB 文件定义了 SNMP 管理信息的结构和属性。
  • armbian上设备SNMP管理的相关软件介绍
    • snmp 是用于在客户端上进行SNMP操作的工具包
    • snmpd SNMP代理服务,用于在服务器上提供SNMP功能(SNMP 的守护进程,负责接收 SNMP 请求并提供相关的网络管理功能
    • snmp-mibs-downloader 是用于下载和安装 SNMP MIB (Management Information Base) 文件的工具。

干净卸载snmp服务并清除配置文件

  1. 停止snmpd服务:

    sudo systemctl stop snmpd
    
  2. 卸载 snmp、snmpd、snmp-mibs-downloader 软件包:

    sudo apt remove --purge snmpd snmp-mibs-downloader
    
  3. 清理残留文件:

    sudo apt autoremove卸载 snmp、snmpd、snmp-mibs-downloader 软件包
    

安装SNMP

  • Armbian 操作系统上安装 SNMP(Simple Network Management Protocol)步骤:
  1. 更新软件包列表:

    sudo apt update
    
  2. 安装 SNMP 相关的软件包:SNMP 客户端工具(snmp)、SNMP 代理服务(snmpd)和 SNMP MIB 文件下载器(snmp-mibs-downloader):

    sudo apt install snmp snmpd snmp-mibs-downloader
    
  3. 安装完毕后,SNMP服务将自动启动。

    sudo systemctl status snmpd
    
  4. 配置 SNMP 代理服务:默认情况下,SNMP 代理服务已经自动配置好。配置文件位于 /etc/snmp/snmpd.conf

    sudo vim /etc/snmp/snmpd.conf
    

SNMPV2远程连接配置

  • 修改SNMP配置文件以允许接受使远程主机使用public社区字符串,连接并具有整个MIB的读写权限:
  1. 打开SNMP配置文件:

    sudo vim /etc/snmp/snmpd.conf
    
  2. 修改agentaddress 127.0.0.1,[::1]或者#agentAddress udp:161,udp6:[::1]:161,最终将其修改为agentAddress udp:161,udp6:[::1]:161

    agentAddress udp:161,udp6:[::1]:161
    #rocommunity public localhost
    
  3. 把public社区字符串的权限从只读(“rocommunity”)改为读写(“rwcommunity”),找到以下两行:

    rocommunity  public default -V systemonly
    rocommunity6 public default -V systemonly
    
  4. 将这两行修改为:

    rwcommunity public
    rwcommunity6 public default -V systemonly
    
  5. 保存并关闭文件。

  6. 重启SNMP服务以使配置更改生效:

    sudo systemctl restart snmpd
    

  • 以下是我的设备修改后的配置文件内容,小伙伴们可以参考一下:
###########################################################################
#
# snmpd.conf
# An example configuration file for configuring the Net-SNMP agent ('snmpd')
# See snmpd.conf(5) man page for details
#
###########################################################################
# SECTION: System Information Setup
#

# syslocation: The [typically physical] location of the system.
#   Note that setting this value here means that when trying to
#   perform an snmp SET operation to the sysLocation.0 variable will make
#   the agent return the "notWritable" error code.  IE, including
#   this token in the snmpd.conf file will disable write access to
#   the variable.
#   arguments:  location_string
sysLocation    Sitting on the Dock of the Bay
sysContact     Me <me@example.org>

# sysservices: The proper value for the sysServices object.
#   arguments:  sysservices_number
sysServices    72



###########################################################################
# SECTION: Agent Operating Mode
#
#   This section defines how the agent will operate when it
#   is running.

# master: Should the agent operate as a master agent or not.
#   Currently, the only supported master agent type for this token
#   is "agentx".
#   
#   arguments: (on|yes|agentx|all|off|no)

master  agentx

# agentaddress: The IP address and port number that the agent will listen on.
#   By default the agent listens to any and all traffic from any
#   interface on the default SNMP port (161).  This allows you to
#   specify which address, interface, transport type and port(s) that you
#   want the agent to listen on.  Multiple definitions of this token
#   are concatenated together (using ':'s).
#   arguments: [transport:]port[@interface/address],...

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



###########################################################################
# SECTION: Access Control Setup
#
#   This section defines who is allowed to talk to your running
#   snmp agent.

# Views 
#   arguments viewname included [oid]

#  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


# rocommunity: a SNMPv1/SNMPv2c read-only access community name
#   arguments:  community [default|hostname|network/bits] [oid | -V view]

# Read-only access to everyone to the systemonly view
#rocommunity  public default -V systemonly
#rocommunity6 public default -V systemonly
#rwcommunity public default -V systemonly
rwcommunity public 
rwcommunity6 public default -V systemonly

# SNMPv3 doesn't use communities, but users with (optionally) an
# authentication and encryption string. This user needs to be created
# with what they can view with rouser/rwuser lines in this file.
#
# createUser username (MD5|SHA|SHA-512|SHA-384|SHA-256|SHA-224) authpassphrase [DES|AES] [privpassphrase]
# e.g.
# createuser authPrivUser SHA-512 myauthphrase AES myprivphrase
#
# This should be put into /var/lib/snmp/snmpd.conf 
#
# rouser: a SNMPv3 read-only access username
#    arguments: username [noauth|auth|priv [OID | -V VIEW [CONTEXT]]]
rouser authPrivUser authpriv -V systemonly

  • 同时可以看到,联系人和位置也是配置在这里的!!

基本设备信息查询

  • 在本机使用SNMP工具查询本机的基本信息:
  1. 安装SNMP工具:首先,确保已经安装了SNMP工具。可以使用以下命令在Linux系统上进行安装:
    sudo apt-get update
    sudo apt-get install snmp
    
  2. 查询系统基本信息:使用SNMP工具的snmpget命令来查询系统的基本信息。下面是一些常用的OID(对象标识符)和对应的基本信息查询命令示例:
  • 查询系统描述:

    snmpget -v 2c -c public localhost SNMPv2-MIB::sysDescr.0
    
  • 查询系统名称:

    snmpget -v 2c -c public localhost SNMPv2-MIB::sysName.0
    
  • 查询系统联系人:

    snmpget -v 2c -c public localhost SNMPv2-MIB::sysContact.0
    
  • 查询系统位置:

    snmpget -v 2c -c public localhost SNMPv2-MIB::sysLocation.0
    
  • 这些命令中的-v 2c表示使用SNMP版本2c,-c public表示使用默认的SNMP共同体字符串(通常为public)。localhost表示查询本地主机,也可以使用主机的IP地址进行查询。

    root@armbian:~# snmpget -v 2c -c public localhost SNMPv2-MIB::sysDescr.0
    SNMPv2-MIB::sysDescr.0 = STRING: Linux armbian 6.1.27-ophub #1 SMP Mon May  1 13:03:40 EDT 2023 aarch64
    root@armbian:~# snmpget -v 2c -c public localhost SNMPv2-MIB::sysName.0
    SNMPv2-MIB::sysName.0 = STRING: armbian
    root@armbian:~# snmpget -v 2c -c public localhost SNMPv2-MIB::sysContact.0
    SNMPv2-MIB::sysContact.0 = STRING: Me <me@example.org>
    root@armbian:~# snmpget -v 2c -c public localhost SNMPv2-MIB::sysLocation.0
    SNMPv2-MIB::sysLocation.0 = STRING: Sitting on the Dock of the Bay
    
    • 系统的位置信息为"Sitting on the Dock of the Bay"。通常情况下,这个值是由系统管理员设置的,用于指示系统所在的位置。它可以是一个具体的地理位置,也可以是一个描述性的文本。在这种情况下,"Sitting on the Dock of the Bay"是一个象征性的值,代表系统的位置。

问题

Errors were encountered while processing: snmpd

  • 运行sudo apt install snmp snmpd snmp-mibs-downloader后出现的问题
    Processing triggers for man-db (2.9.4-2) ...
    Errors were encountered while processing:
     snmpd
    

可能的原因和解决方法:

  1. 系统依赖问题:snmpd软件包可能依赖于其他软件包或库,而这些依赖项可能缺失或版本不兼容。你可以尝试运行以下命令修复依赖关系:
    sudo apt --fix-broken install
    

然后再次运行安装SNMP服务的命令。

  1. 软件包损坏或下载问题:有时软件包可能下载不完整或损坏。你可以尝试清除已下载的软件包缓存,并重新运行安装命令:

    sudo apt update
    sudo apt clean
    sudo apt install snmp snmpd snmp-mibs-downloader
    
  2. 网络连接问题:检查网络连接,确保设备已连接互联网,并且可以访问软件仓库。

Cannot adopt OID……

  • 安装完成后可能遇到的问题
root@armbian:~# sudo systemctl status snmpd
● snmpd.service - Simple Network Management Protocol (SNMP) Daemon.
     Loaded: loaded (/lib/systemd/system/snmpd.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2023-12-09 08:26:55 CST; 1min 57s ago
    Process: 116556 ExecStartPre=/bin/mkdir -p /var/run/agentx (code=exited, status=0/SUCCESS)
   Main PID: 116557 (snmpd)
      Tasks: 1 (limit: 4382)
     Memory: 4.9M
        CPU: 516ms
     CGroup: /system.slice/snmpd.service
             └─116557 /usr/sbin/snmpd -LOw -u Debian-snmp -g Debian-snmp -I -smux mteTrigger mteTriggerConf -f -p /run/snmpd.pid

Dec 09 08:26:55 armbian snmpd[116557]: Cannot adopt OID in NET-SNMP-AGENT-MIB: nsNotifyShutdown ::= { netSnmpNotifications 2 }
Dec 09 08:26:55 armbian snmpd[116557]: Cannot adopt OID in NET-SNMP-AGENT-MIB: nsNotifyRestart ::= { netSnmpNotifications 3 }
Dec 09 08:26:55 armbian snmpd[116557]: Cannot adopt OID in UCD-SNMP-MIB: laErrMessage ::= { laEntry 101 }
Dec 09 08:26:55 armbian snmpd[116557]: Cannot adopt OID in UCD-SNMP-MIB: laErrorFlag ::= { laEntry 100 }
Dec 09 08:26:55 armbian snmpd[116557]: Cannot adopt OID in UCD-SNMP-MIB: laLoadFloat ::= { laEntry 6 }
Dec 09 08:26:55 armbian snmpd[116557]: Cannot adopt OID in UCD-SNMP-MIB: laLoadInt ::= { laEntry 5 }
Dec 09 08:26:55 armbian snmpd[116557]: Cannot adopt OID in UCD-SNMP-MIB: laConfig ::= { laEntry 4 }
Dec 09 08:26:55 armbian snmpd[116557]: Cannot adopt OID in UCD-SNMP-MIB: laLoad ::= { laEntry 3 }
Dec 09 08:26:55 armbian snmpd[116557]: Cannot adopt OID in UCD-SNMP-MIB: laNames ::= { laEntry 2 }
Dec 09 08:26:55 armbian snmpd[116557]: Cannot adopt OID in UCD-SNMP-MIB: laIndex ::= { laEntry 1 }

  • snmpd 服务已经处于活动状态(active (running)),没有明显的错误或问题。
  • 日志信息显示了一些警告消息,指出无法采用某些 OID。这些警告消息可能与缺少必要的 MIB(Management Information Base)文件有关。
  1. 安装 snmp-mibs-downloader 软件包:运行以下命令以安装 snmp-mibs-downloader 软件包:
    sudo apt install snmp-mibs-downloader
    
  2. 使用 snmp-mibs-downloader 下载 MIB 文件:运行以下命令以下载 MIB 文件:
    sudo download-mibs
    
  3. 重新启动 snmpd 服务:运行以下命令以重新启动 snmpd 服务:
    sudo systemctl restart snmpd
    
  • 完美解决
    root@armbian:~# sudo systemctl status snmpd
    ● snmpd.service - Simple Network Management Protocol (SNMP) Daemon.
         Loaded: loaded (/lib/systemd/system/snmpd.service; enabled; vendor preset: enabled)
         Active: active (running) since Sat 2023-12-09 08:33:27 CST; 16s ago
        Process: 121820 ExecStartPre=/bin/mkdir -p /var/run/agentx (code=exited, status=0/SUCCESS)
       Main PID: 121821 (snmpd)
          Tasks: 1 (limit: 4382)
         Memory: 5.4M
            CPU: 201ms
         CGroup: /system.slice/snmpd.service
                 └─121821 /usr/sbin/snmpd -LOw -u Debian-snmp -g Debian-snmp -I -smux mteTrigger mteTriggerConf -f -p /run/snmpd.pid
    
    Dec 09 08:33:27 armbian systemd[1]: Starting Simple Network Management Protocol (SNMP) Daemon....
    Dec 09 08:33:27 armbian systemd[1]: Started Simple Network Management Protocol (SNMP) Daemon..
    

文章来源:https://blog.csdn.net/yang2330648064/article/details/134890282
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。