zoukankan      html  css  js  c++  java
  • zabbix 监控snmp设备

                zabbix 监控snmp设备

                                         作者:尹正杰

    版权声明:原创作品,谢绝转载!否则将追究法律责任。

    一.SNMP协议概述

    1>.什么是SNMP协议

      SNMP是英文“Simple Network Management Protocol”的缩写,中文意思是“简单网络管理协议,SNMP是一种简单网络管理协议,它属于TCP/IP五层协议中的应用层协议,用于网络管理的协议,SNMP主要用于网络设备的管理。

    2>.SNMP的基本思想

      为不同种类的设备、不同厂家生产的设备、不同型号的设备,定义为一个统一的接口和协议,使得管理员可以是使用统一的外观面对这些需要管理的网络设备进行管理。通过网络,管理员可以管理位于不同物理空间的设备,从而大大提高网络管理的效率,简化网络管理员的工作。

    3>.SNMP的版本

      SNMP协议是TCP/IP协议簇的一个应用层协议,在1988年被制定,并被Internet体系结构委员会(IAB)采纳作为一个短期的网络管理解决方案,由于SNMP的简单性,在Internet时代得到了蓬勃的发展,1992年发布了SNMPv2版本,以增强SNMPv1的安全性和功能,SNMP的协议版本目前有SNMP v1、SNMP v2c和SNMP v3三种版本,其具体差别如下:
        SNMP v1:
          采用团体名(Community Name)认证,团体名用来定义SNMP NMS和SNMP Agent的关系,如果SNMP报文携带的团体名没有得到设备的认可,该报文将被丢弃,团体名起到了类似于密码的作用,用来限制SNMP NMS对SNMP Agent的访问。
        SNMP v2c:
          也采用团体名认证,它在兼容SNMP v1的同时又扩充了SNMP v1的功能,它提供了更多的操作类型(GetBulk和InformRequest)、支持更多的数据类型(Counter64等)、提供了更丰富的错误代码且能够更细致地区分错误。
        SNMP v3:
          提供了基于用户的安全模型(USM,User
    -Based Security Model)的认证机制,用户可以设置认证和加密功能,认证用于验证报文发送方的合法性,避免非法用户的访问,加密则是对NMS和Agent之间的传输报文进行加密,以免被窃听。通过有无认证和有无加密等功能组合,可以为SNMP NMS和SNMP Agent之间的通信提供更高的安全性。

    4>.SNMP工作机制

      SNMP的工作机制SNMP网络元素分为NMS和Agent两种:
        NMS(Network Management Station,网络管理站):
          是运行SNMP客户端程序的工作站,能够提供非常友好的人机交互界面,方便网络管理员完成绝大多数的网络管理工作。     Agent:
          是驻留在设备上的一个进程,负责接收、处理来自NMS的请求报文。在一些紧急情况下,如接口状态发生改变等,Agent也会主动通知NMS。
      温馨提示:
        NMS是SNMP网络的管理者,Agent是SNMP网络的被管理者。NMS和Agent之间通过SNMP协议来交互管理信息。

    5>.SNMP数据交互

      SNMP管理进程与代理进程之前为了交互信息,定义了5种报文:
        get-request操作:
          从代理进程处提取一个或多个参数值。     get
    -next-request操作:
          从代理进程处提取一个或多个参数的下一个参数值。     set
    -request操作:
          设置代理进程的一个或多个参数值。     get
    -response操作:
          返回的一个或多个参数值。这个操作是由代理进程发出的。     trap操作:
          代理进程主动发出的报文,通知管理进程有某些事情发生。

    6>.SNMP 组织结构

      一套完整的SNMP系统主要包括以下几个方面:
        SNMP报文协议。
        管理信息结构(SMI,Structure ofManagementInformation),一套公用的结构和表示符号。
        管理信息库(MIB,Management Information Base),管理信息库包含所有代理进程的所有可被查询和修改的参数。
        OID(Object Identifiers),一个OID是一个唯一的键值对,用于标识具体某一个设备的某个具体信息(对象标识),如端口信息、设备名称等。

    7>.SNMP MIB

      所谓(MIB)管理信息库,就是所有代理进程包含的、并且能够被管理进程进行查询和设置的信息的集合。

      MIB是基于对象标识树的,对象标识是一个整数序列,中间以"."分割,这些整数构成一个树型结构,类似于DNS或Unix的文件系统,MIB被划分为若干个组,如system,interfaces,nat(地址转换)和ip组等。

      iso.org.dod.internet.private.enterprises(1.3.6.1.4.1)这个标识,是给厂家自定义而预留的,比如华为的为1.3.6.1.4.1.2011,华三的为1.3.6.1.4.1.25506

    8>.SNMP OID

      Centos 部分常用的OID如下所示:
    
      snmpwalk是SNMP的一个工具,它使用SNMP的GET请求查询指定OID(SNMP协议中的对象标识)入口的所有OID树信息,并显示给用户。通过snmpwalk也可以查看支持SNMP协议(可网管)的设备的一些其他信息,比如cisco交换机或路由器IP地址、内存使用率等,也可用来协助开发SNMP功能。

      要使用snmpwalk需要先安装net
    -snmp软件包中,以CentOS为例:     [root@node102.yinzhengjie.org.cn ~]# yum -y install net-snmp-utils     [root@node102.yinzhengjie.org.cn ~]# snmpwalk-h     USAGE: snmpwalk[OPTIONS] AGENT [OID]     –h:显示帮助。     –v:指定snmp的版本, 1或者2c或者3。     –c:指定连接设备SNMP密码。     –V:显示当前snmpwalk命令行版本。     –r:指定重试次数,默认为0次。     –t:指定每次请求的等待超时时间,单为秒,默认为3秒。     –l:指定安全级别:noAuthNoPriv|authNoPriv|authPriv。     –a:验证协议:MD5|SHA。只有-l指定为authNoPriv或authPriv时才需要。     –A:验证字符串。只有-l指定为authNoPriv或authPriv时才需要。     –x:加密协议:DES。只有-l指定为authPriv时才需要。     –X:加密字符串。只有-l指定为authPriv时才需要。

    二.Centos服务器安装配置SNMP

    1>.安装SNMP服务

    [root@node202.yinzhengjie.org.cn ~]# yum -y install net-snmp
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirror.bit.edu.cn
     * extras: mirrors.tuna.tsinghua.edu.cn
     * updates: mirror.bit.edu.cn
    base                                                                                                                                                                                                                                                   | 3.6 kB  00:00:00     
    docker-ce-stable                                                                                                                                                                                                                                       | 3.5 kB  00:00:00     
    extras                                                                                                                                                                                                                                                 | 2.9 kB  00:00:00     
    kubernetes                                                                                                                                                                                                                                             | 1.4 kB  00:00:00     
    updates                                                                                                                                                                                                                                                | 2.9 kB  00:00:00     
    zabbix                                                                                                                                                                                                                                                 | 2.9 kB  00:00:00     
    zabbix-non-supported                                                                                                                                                                                                                                   |  951 B  00:00:00     
    Resolving Dependencies
    --> Running transaction check
    ---> Package net-snmp.x86_64 1:5.7.2-43.el7_7.3 will be installed
    --> Processing Dependency: net-snmp-libs = 1:5.7.2-43.el7_7.3 for package: 1:net-snmp-5.7.2-43.el7_7.3.x86_64
    --> Processing Dependency: net-snmp-agent-libs = 1:5.7.2-43.el7_7.3 for package: 1:net-snmp-5.7.2-43.el7_7.3.x86_64
    --> Processing Dependency: perl(Data::Dumper) for package: 1:net-snmp-5.7.2-43.el7_7.3.x86_64
    --> Processing Dependency: libsensors.so.4()(64bit) for package: 1:net-snmp-5.7.2-43.el7_7.3.x86_64
    --> Processing Dependency: libnetsnmptrapd.so.31()(64bit) for package: 1:net-snmp-5.7.2-43.el7_7.3.x86_64
    --> Processing Dependency: libnetsnmpmibs.so.31()(64bit) for package: 1:net-snmp-5.7.2-43.el7_7.3.x86_64
    --> Processing Dependency: libnetsnmpagent.so.31()(64bit) for package: 1:net-snmp-5.7.2-43.el7_7.3.x86_64
    --> Processing Dependency: libnetsnmp.so.31()(64bit) for package: 1:net-snmp-5.7.2-43.el7_7.3.x86_64
    --> Running transaction check
    ---> Package lm_sensors-libs.x86_64 0:3.4.0-8.20160601gitf9185e5.el7 will be installed
    ---> Package net-snmp-agent-libs.x86_64 1:5.7.2-43.el7_7.3 will be installed
    ---> Package net-snmp-libs.x86_64 1:5.7.2-43.el7_7.3 will be installed
    ---> Package perl-Data-Dumper.x86_64 0:2.145-3.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ==============================================================================================================================================================================================================================================================================
     Package                                                              Arch                                                    Version                                                                          Repository                                                Size
    ==============================================================================================================================================================================================================================================================================
    Installing:
     net-snmp                                                             x86_64                                                  1:5.7.2-43.el7_7.3                                                               updates                                                  332 k
    Installing for dependencies:
     lm_sensors-libs                                                      x86_64                                                  3.4.0-8.20160601gitf9185e5.el7                                                   base                                                      42 k
     net-snmp-agent-libs                                                  x86_64                                                  1:5.7.2-43.el7_7.3                                                               updates                                                  707 k
     net-snmp-libs                                                        x86_64                                                  1:5.7.2-43.el7_7.3                                                               updates                                                  750 k
     perl-Data-Dumper                                                     x86_64                                                  2.145-3.el7                                                                      base                                                      47 k
    
    Transaction Summary
    ==============================================================================================================================================================================================================================================================================
    Install  1 Package (+4 Dependent packages)
    
    Total download size: 1.8 M
    Installed size: 6.0 M
    Downloading packages:
    (1/5): net-snmp-5.7.2-43.el7_7.3.x86_64.rpm                                                                                                                                                                                                            | 332 kB  00:00:00     
    (2/5): perl-Data-Dumper-2.145-3.el7.x86_64.rpm                                                                                                                                                                                                         |  47 kB  00:00:00     
    (3/5): net-snmp-agent-libs-5.7.2-43.el7_7.3.x86_64.rpm                                                                                                                                                                                                 | 707 kB  00:00:00     
    (4/5): lm_sensors-libs-3.4.0-8.20160601gitf9185e5.el7.x86_64.rpm                                                                                                                                                                                       |  42 kB  00:00:00     
    (5/5): net-snmp-libs-5.7.2-43.el7_7.3.x86_64.rpm                                                                                                                                                                                                       | 750 kB  00:00:00     
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Total                                                                                                                                                                                                                                         3.2 MB/s | 1.8 MB  00:00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : lm_sensors-libs-3.4.0-8.20160601gitf9185e5.el7.x86_64                                                                                                                                                                                                      1/5 
      Installing : 1:net-snmp-libs-5.7.2-43.el7_7.3.x86_64                                                                                                                                                                                                                    2/5 
      Installing : 1:net-snmp-agent-libs-5.7.2-43.el7_7.3.x86_64                                                                                                                                                                                                              3/5 
      Installing : perl-Data-Dumper-2.145-3.el7.x86_64                                                                                                                                                                                                                        4/5 
      Installing : 1:net-snmp-5.7.2-43.el7_7.3.x86_64                                                                                                                                                                                                                         5/5 
      Verifying  : perl-Data-Dumper-2.145-3.el7.x86_64                                                                                                                                                                                                                        1/5 
      Verifying  : 1:net-snmp-libs-5.7.2-43.el7_7.3.x86_64                                                                                                                                                                                                                    2/5 
      Verifying  : lm_sensors-libs-3.4.0-8.20160601gitf9185e5.el7.x86_64                                                                                                                                                                                                      3/5 
      Verifying  : 1:net-snmp-5.7.2-43.el7_7.3.x86_64                                                                                                                                                                                                                         4/5 
      Verifying  : 1:net-snmp-agent-libs-5.7.2-43.el7_7.3.x86_64                                                                                                                                                                                                              5/5 
    
    Installed:
      net-snmp.x86_64 1:5.7.2-43.el7_7.3                                                                                                                                                                                                                                          
    
    Dependency Installed:
      lm_sensors-libs.x86_64 0:3.4.0-8.20160601gitf9185e5.el7                       net-snmp-agent-libs.x86_64 1:5.7.2-43.el7_7.3                       net-snmp-libs.x86_64 1:5.7.2-43.el7_7.3                       perl-Data-Dumper.x86_64 0:2.145-3.el7                      
    
    Complete!
    [root@node202.yinzhengjie.org.cn ~]# 
    [root@node202.yinzhengjie.org.cn ~]# yum -y install net-snmp
    [root@node202.yinzhengjie.org.cn ~]# rpm -ql net-snmp
    /etc/snmp
    /etc/snmp/snmpd.conf
    /etc/snmp/snmptrapd.conf
    /etc/sysconfig/snmpd
    /etc/sysconfig/snmptrapd
    /usr/bin/agentxtrap
    /usr/bin/net-snmp-config
    /usr/bin/net-snmp-config-x86_64
    /usr/bin/net-snmp-create-v3-user
    /usr/bin/snmpconf
    /usr/lib/systemd/system/snmpd.service
    /usr/lib/systemd/system/snmptrapd.service
    /usr/lib/tmpfiles.d/net-snmp.conf
    /usr/sbin/snmpd
    /usr/sbin/snmptrapd
    /usr/share/doc/net-snmp-5.7.2
    /usr/share/doc/net-snmp-5.7.2/AGENT.txt
    /usr/share/doc/net-snmp-5.7.2/COPYING
    /usr/share/doc/net-snmp-5.7.2/ChangeLog.trimmed
    /usr/share/doc/net-snmp-5.7.2/EXAMPLE.conf
    /usr/share/doc/net-snmp-5.7.2/FAQ
    /usr/share/doc/net-snmp-5.7.2/NEWS
    /usr/share/doc/net-snmp-5.7.2/PORTING
    /usr/share/doc/net-snmp-5.7.2/README
    /usr/share/doc/net-snmp-5.7.2/README.agent-mibs
    /usr/share/doc/net-snmp-5.7.2/README.agentx
    /usr/share/doc/net-snmp-5.7.2/README.krb5
    /usr/share/doc/net-snmp-5.7.2/README.mib2c
    /usr/share/doc/net-snmp-5.7.2/README.snmpv3
    /usr/share/doc/net-snmp-5.7.2/README.thread
    /usr/share/doc/net-snmp-5.7.2/TODO
    /usr/share/doc/net-snmp-5.7.2/ipf-mod.pl
    /usr/share/doc/net-snmp-5.7.2/passtest
    /usr/share/man/man1/net-snmp-config.1.gz
    /usr/share/man/man1/net-snmp-create-v3-user.1.gz
    /usr/share/man/man1/snmpconf.1.gz
    /usr/share/man/man5/snmp_config.5.gz
    /usr/share/man/man5/snmpd.conf.5.gz
    /usr/share/man/man5/snmpd.examples.5.gz
    /usr/share/man/man5/snmpd.internal.5.gz
    /usr/share/man/man5/snmptrapd.conf.5.gz
    /usr/share/man/man5/variables.5.gz
    /usr/share/man/man8/snmpd.8.gz
    /usr/share/man/man8/snmptrapd.8.gz
    /usr/share/snmp
    /usr/share/snmp/snmpconf-data
    /usr/share/snmp/snmpconf-data/snmp-data
    /usr/share/snmp/snmpconf-data/snmp-data/authopts
    /usr/share/snmp/snmpconf-data/snmp-data/debugging
    /usr/share/snmp/snmpconf-data/snmp-data/mibs
    /usr/share/snmp/snmpconf-data/snmp-data/output
    /usr/share/snmp/snmpconf-data/snmp-data/snmpconf-config
    /usr/share/snmp/snmpconf-data/snmpd-data
    /usr/share/snmp/snmpconf-data/snmpd-data/acl
    /usr/share/snmp/snmpconf-data/snmpd-data/basic_setup
    /usr/share/snmp/snmpconf-data/snmpd-data/extending
    /usr/share/snmp/snmpconf-data/snmpd-data/monitor
    /usr/share/snmp/snmpconf-data/snmpd-data/operation
    /usr/share/snmp/snmpconf-data/snmpd-data/snmpconf-config
    /usr/share/snmp/snmpconf-data/snmpd-data/system
    /usr/share/snmp/snmpconf-data/snmpd-data/trapsinks
    /usr/share/snmp/snmpconf-data/snmptrapd-data
    /usr/share/snmp/snmpconf-data/snmptrapd-data/authentication
    /usr/share/snmp/snmpconf-data/snmptrapd-data/formatting
    /usr/share/snmp/snmpconf-data/snmptrapd-data/logging
    /usr/share/snmp/snmpconf-data/snmptrapd-data/runtime
    /usr/share/snmp/snmpconf-data/snmptrapd-data/snmpconf-config
    /usr/share/snmp/snmpconf-data/snmptrapd-data/traphandle
    /var/run/net-snmp
    [root@node202.yinzhengjie.org.cn ~]# 
    [root@node202.yinzhengjie.org.cn ~]# rpm -ql net-snmp

    2>.修改SNMPD服务的配置文件并设置开机自启动

    [root@node202.yinzhengjie.org.cn ~]# grep "^[a-Z]" /etc/snmp/snmpd.conf 
    com2sec notConfigUser  default       yinzhengjie
    group   notConfigGroup v1           notConfigUser
    group   notConfigGroup v2c           notConfigUser
    view    systemview    included   .1.3.6.1.2.1.1
    view    systemview    included   .1.3.6.1.2.1.25.1.1
    view    systemview    included   .1.3.6.
    access  notConfigGroup ""      any       noauth    exact  systemview none none
    syslocation Unknown (edit /etc/snmp/snmpd.conf)
    syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
    dontLogTCPWrappersConnects yes
    [root@node202.yinzhengjie.org.cn ~]# 

     

    三.zabbix WebUI配置监控SNMP主机

    1>.安装snmpwalk工具(Ubuntu系统的snmp包中自带snmpwalk工具)

    [root@zabbix203.yinzhengjie.org.cn ~]# apt install snmp
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following NEW packages will be installed:
      snmp
    0 upgraded, 1 newly installed, 0 to remove and 86 not upgraded.
    Need to get 158 kB of archives.
    After this operation, 563 kB of additional disk space will be used.
    Get:1 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 snmp amd64 5.7.3+dfsg-1.8ubuntu3.3 [158 kB]
    Fetched 158 kB in 0s (1,289 kB/s)
    Selecting previously unselected package snmp.
    (Reading database ... 129530 files and directories currently installed.)
    Preparing to unpack .../snmp_5.7.3+dfsg-1.8ubuntu3.3_amd64.deb ...
    Unpacking snmp (5.7.3+dfsg-1.8ubuntu3.3) ...
    Setting up snmp (5.7.3+dfsg-1.8ubuntu3.3) ...
    Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
    [root@zabbix203.yinzhengjie.org.cn ~]# 
    [root@zabbix203.yinzhengjie.org.cn ~]# apt install snmp

    2>.使用snmpwalk工具测试捕获"node202.yinzhengjie.org.cn"节点的监控数据

    [root@zabbix203.yinzhengjie.org.cn ~]# snmpwalk -v 2c -c yinzhengjie 172.200.1.202 .1.3.6.1.4.1.2021.10.1.3.1
    iso.3.6.1.4.1.2021.10.1.3.1 = STRING: "0.03"
    [root@zabbix203.yinzhengjie.org.cn ~]# 

    3>.配置主机的SNMP接口

    4>.为SNMP主机添加zabbix 自带的监控模板

    5>.模板添加成功

    6>.更新模板的团体名

    7>.查看链接模板

    8>.间隔一段时间后再来查看主机的监控logo是否变量

    9>.查看node202.yinzhengjie.org.cn的最新数据

    10>.查看node202.yinzhengjie.org.cn主机的图形(这些图形是自动生成的,我们只需要等待即可,如果仅为了快速看到试验效果可以使用批量更改模板的间隔时间)

    11>.使用zabbix监控网络设备

      博主推荐阅读:
        https://www.cnblogs.com/yinzhengjie/p/6768006.html
  • 相关阅读:
    php lesson1
    微信红包算法java版本
    spring注解
    Java时间戳
    集成环信 服务器端遇见的坑:关于Request body is invalid.解决
    环信java后台发送消息时提示msg 应该为JSONObject 的坑
    jboss设置允许外网访问
    redis实现单点登录
    qq在线客服
    图片纯css控制宽高比
  • 原文地址:https://www.cnblogs.com/yinzhengjie2020/p/12381110.html
Copyright © 2011-2022 走看看