架构师成长之路-多维监控体系_硬件监控

点击架构师成长之路

架构师成长之路-多维监控体系_硬件监控

监控其实占用了正常运维至少60%的工作量,往往大家谈及监控可能回答就是如何使用zabbix、nagix系统,但其不太注重总结监控本质。

监控入门:

  • 识别监控对象:
  • 监控对象的理解:CPU工作原理  
  • 监控对象的指标:CPU使用率、CPU负载 、CPU个数、 CPU上下文切换
  • 确认告警基准线:怎么样才算故障?CPU负载多少才算高?

预中级监控需要做:

  • 工具化和监控分离
  • 监控对象的分类:
    硬件监控(机房巡检、IPMI、SNMP) 
    系统监控(对象:CPU、内存、IO[磁盘、网络]、进程等)
    服务监控(对象:各类服务[Nginx|Tomcat|RabbitMQ|Openstack|Mysql|*])
    日志监控(方法:Elastic Stack)
    网络监控(方法:第三方、Smokeping)
    APM应用性能管理(工具:PINPoint)
    流量监控(工具:Piwik、xx统计、xx分析)
    其他监控(APP监控、安全监控、业务监控、舆论监控、xx监控)
  • 掌握一个监控工具:比如zabbix

中级监控需要做

  • 标准化监控(标准化的脚本、模板等等)
  • 分布式监控(主动、被动、分布式)
  • 自动化监控(自动发现、主动注册[Agent主动注册、Server通过API主动添加])
  • 性能优化(数据采集、数据存储、数据查询)
  • 二次开发(定制报表、API调用、xxx)

进阶监控需要做:

  • 动态告警
  • 智能告警:1.告警去重 2.去除依赖性
  • 故障自愈
  • 大规模监控

硬件监控

1  服务器硬件监控_IPMI

远程控制卡:可以说和服务器完全独立存在,远程控制卡都是通过IPMI标准。

智能平台管理接口 (IPMI) 是一种开放标准的硬件管理接口规格,定义了嵌入式管理子系统进行通信的特定方法。用户可以利用 IPMI 监视服务器的物理特征,如温度、电压、电扇工作状态、电源供应以及机箱入侵等。Ipmi 最大的优势在 于它是独立于 CPU BIOS 和 OS 的,所以用户无论在开机还是关机的状态下,只要接通电源就可以实现对服务器的监控。Ipmi 是一种规范的标准,其中最重要的物理部件就是BMC(Baseboard Management Controller),一种嵌入式管理微控制器,它相当于整个平台管理的“大脑”,通过它 ipmi 可以监控各个传感器的数据并记录各种事件的日志。

服务器厂家远程控制卡名字:

  •      DELL服务器:IDRAC
  •      HP服务器:ILO
  •      IBM服务器:IMM

如果在linux下使用IPMI对服务器进行硬件监控,需要什么条件?

  • 硬件必须支持
  • 操作系统必须支持:linux系统肯定支持
  • 管理工具:linux系统采用ipmitool (ipmitool 是一种可用在 linux 系统下的命令行方式的 ipmi 平台管理工具,它支持 ipmi 1.5 规范(最新的规范为 ipmi 2.0),通过它可以实现获取传感器的信息、显示系统日志内容、网络远程开关机等功能。)
yum install -y OpenIPMI ipmitool   #安装IPMI
systemctl start  ipmi   #启动IPMI

使用IPMI两种方式:

  • 本地调用
  • 远程网路调试  需要IP地址,用户名和密码

 IPMI配置网络两种方式:

  • ipmi over lan  网络数据包通过网卡
  • 独立配置IP地址(推荐)

2  路由器和交换机硬件监控_SNMP

2.1  SNMP简介  

  SNMP是英文"Simple Network Management Protocol"的缩写,中文意思是"简单网络管理协议"。SNMP是一种简单网络管理协议,它属于TCP/IP五层协议中的应用层协议,用于网络管理的协议。SNMP主要用于网络设备的管理。由于SNMP协议简单可靠 ,受到了众多厂商的欢迎,成为了目前最为广泛的网管协议。

  SNMP协议主要由两大部分构成:SNMP管理站和SNMP代理。SNMP管理站是一个中心节点,负责收集维护各个SNMP元素的信息,并对这些信息进行处理,最后反馈给网络管理员;而SNMP代理是运行在各个被管理的网络节点之上,负责统计该节点的各项信息,并且负责与SNMP管理站交互,接收并执行管理站的命令,上传各种本地的网络信息。

  SNMP管理站和SNMP代理之间是松散耦合。他们之间的通信是通过UDP协议完成的。一般情况下,SNMP管理站通过UDP协议向SNMP代理发送各种命令,当SNMP代理收到命令后,返回SNMP管理站需要的参数。但是当SNMP代理检测到网络元素异常的时候,也可以主动向SNMP管理站发送消息,通告当前异常状况。

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

  SNMP的工作方式:管理员需要向设备获取数据,所以SNMP提供了【读】操作;
                                       管理员需要向设备执行设置操作,所以SNMP提供了【写】操作;
                                       设备需要在重要状况改变的时候,向管理员通报事件的发生,所以SNMP提供了【Trap】操作。

2.2 SNMP 和 UDP

  SNMP采用UDP协议在管理端和agent之间传输信息。 SNMP采用UDP 161端口接收和发送请求,162端口接收trap,执行SNMP的设备缺省都必须采用这些端口。

2.3 Snmp版本

  SNMP目前共有v1,v2,v3这三个版本: 

  • SNMP v1是SNMP协议的最初版本,不过依然是众多厂家实现SNMP基本方式。 
  • SNMP v2通常被指是基于community的SNMP V2。Community实质上就是密码。
  • SNMP v3 是最新版本的SNMP。它对网络管理最大的贡献在于其安全性。增加了对认证和密文传输的支持。

2.4 Snmp的实现结构

SNMP管理的网络主要由三部分组成:
  • 被管理的设备:
  • SNMP代理 :    【被】监管的设备上运行一个SNMP代理(Agent)),代理实现设备与管理站的SNMP通信。
  • 网络管理系统(NMS):   负责网管命令的发出、数据存储、及数据分析。又称为【管理站】
它们之间的关系
  • 网络中被管理的每一个设备都存在一个管理信息库(MIB)用于收集并储存管理信息。
        通过SNMP协议,NMS能获取这些信息。被管理设备,又称为网络单元或网络节点,可以是支持SNMP协议的路由器、交换机、服务器或者主机等等。
  • SNMP代理是被管理设备上的一个网络管理软件模块,拥有本地设备的相关管理信息,并用于将它们转换成与SNMP兼容的格式,传递给NMS。
  • NMS运行应用程序来实现监控被管理设备的功能。另外,NMS还为网络管理提供大量的处理程序及必须的储存资源。

                                                                                                     

(1)管理信息库MIB  

        MIB文件中的变量使用的名字取自ISO和ITU管理的对象标识符(object identifier)名字空间。它是一种分级树的结构。

        OID(Object Identifier):
        每个管理对象都有自己的OID(Object Identifier),管理对象通过树状结构进行组织,OID由树上的一系列整数组成,整数之间用点( . )分隔开,树的叶子节点才是真正能够被管理的对象。
        如下图所示,第一级有三个节点:ccitt、iso、iso-ccitt。低级的对象ID分别由相关组织分配。一个特定对象的标识符可通过由根到该对象的路径获得。一般网络设备取iso节点下的对象内容。
        如名字空间ip结点下一个名字为ipInReceives的MIB变量被指派数字值3,因而该变量的名字为: iso.org.dod.internet.mgmt.mib.ip.ipInReceives  ,,对应的对象标识符OID为:  1.3.6.1.2.1.4.3

 

        当网络管理协议在报文中使用MIB变量时,每个变量名后还要加一个后缀,以作为该变量的一个实例。如ipInReceives的实例数字表示为:1.3.6.1.2.1.4.3.0. 需要注意的是,MIB中的管理对象的OID有些需要动态确            定:如IP路由表,为了指明地址172.18.20.220的下一站路由(next hop),我们可以引用这样的实例:

         iso.org.dod.internet.mgmt.mib.ip. ipRouteTable.ipRouteEntry.ipRouteNextHop.172.18.20.220, 相应的数字表示为:1.3.6.1.2.1.4.21.1.7.172.18.20.220

(2)管理信息结构(SMI)

          SMI定义了SNMP框架所用信息的组织、组成和标识,它还为描述MIB对象和描述协议怎样交换信息奠定了基础。SMI定义的数据类型:

   ◆  简单类型(simple)

  • Integer:整型是-2,147,483,648~2,147,483,647的有符号整数
  • octet string: 字符串是0~65535个字节的有序序列
  • OBJECT IDENTIFIER: 来自按照ASN.1规则分配的对象标识符集

  ◆  简单结构类型(simple-constructed)

  • SEQUENCE 用于列表。这一数据类型与大多数程序设计语言中的“structure”类似。一个SEQUENCE包括0个或更多元素,每一个元素又是另一个ASN.1数据类型
  • SEQUENCE OF type 用于表格。这一数据类型与大多数程序设计语言中的“array”类似。一个表格包括0个或更多元素,每一个元素又是另一个ASN.1数据类型。

  ◆  应用类型(application-wide)

  • IpAddress: 以网络序表示的IP地址。因为它是一个32位的值,所以定义为4个字节;
  • counter:计数器是一个非负的整数,它递增至最大值,而后回零。在SNMPv1中定义的计数器是32位的,即最大值为4,294,967,295;
  • Gauge :也是一个非负整数,它可以递增或递减,但达到最大值时保持在最大值,最大值为232-1;
  • time ticks:是一个时间单位,表示以0.01秒为单位计算的时间;

(3)SNMP报文

       SNMP中定义了五种消息类型:Get-Request、Get-Response、Get-Next-Request、Set-Request和Trap 。

  • get-request操作:从代理进程处提取一个或多个参数值。Get-Request是由管理站发送到代理侧的161端口的;
  • get-next-request操作:从代理进程处提取一个或多个参数的下一个参数值。Get-Next-Request是由管理站发送到代理侧的161端口的;
  • set-request操作:设置代理进程的一个或多个参数值。Set-Request是由管理站发送到代理侧的161端口的;
  • response操作:返回的一个或多个参数值。这个操作是由代理进程发出的。它是前面3中操作的响应操作。
  • trap操作:代理进程主动发出的报文,通知管理进程有某些事情发生。Trap 是由代理进程发给管理进程的,其中Trap消息被发送到管理进程的162端口,所有数据都是走UDP封装。

2.5 SNMP报文格式

(1)公共SNMP首部 共三个字段: 

  •  版本  该字段的值是通过SNMP版本号减1得到的,所以:

        XX=0 对应SNMPv1

        XX=1 对应SNMPv2c

        XX=2 对应SNMPv2

        XX=3 对应SNMPv3

  • 共同体(community)共同体就是一个字符串,作为管理进程和代理进程之间的明文口令,常用的是6个字符“public”。
  • PDU类型: 如下图:

(2)get/set首部

  • 请求标识符(request ID)  : 这是由管理进程设置的一个整数值。代理进程在发送get-response报文时也要返回此请求标识符。管理进程可同时向许多代理发出get报文,这些报文都使用UDP传送,先发送的有可能后到达。设置了请求标识符可使管理进程能够识别返回的响应报文对于哪一个请求报文
  •  差错状态(error status):由代理进程回答时填入0~5中的一个数字,如下:

  •  差错索引(error index): 当出现noSuchName、badValue或readOnly的差错时,由代理进程在回答时设置的一个整数,它指明有差错的变量在变量列表中的偏移。

(3)trap首部

  • 企业(enterprise):填入trap报文的网络设备的对象标识符。此对象标识符肯定是在图3的对象命名树上的enterprise结点{1.3.6.1.4.1}下面的一棵子树上。
  • trap类型 :此字段正式的名称是generic-trap,共分为7种:

              当使用上述类型2、3、5时,在报文后面变量部分的第一个变量应标识响应的接口。

  • 特定代码(specific-code) : 指明代理自定义的时间(若trap类型为6),否则为0。
  • 时间戳(timestamp) : 指明自代理进程初始化到trap报告的事件发生所经历的时间,单位为10ms。例如时间戳为1908表明在代理初始化后1908ms发生了该时间。

(4)变量绑定(variable-bindings)    指明一个或多个变量的名和对应的值。在get或get-next报文中,变量的值应忽略。 

2.6 代理和管理站的模型

    Snmp分2种角色:SNMP管理站和SNMP代理(agent)。

  • 管理站指的是运行了可以执行网络管理任务软件的服务器,通常被称作为网络管理工作站(NMS),NMS负责采样网络中agent的信息,并接受agent的trap。
  • 代理是实际网络设备中用来实现SNMP功能的部分。

     代理在UDP的161端口接收NMS的读写请求消息,管理站在UDP的162端口接收代理的事件通告消息。
     所以,一旦获取设备的访问权限(community,默认为public),就可以访问设备信息、改写和配置设备参数。由于采用UDP协议,不需要在代理和管理站之间保持连接。

2.7 SNMP的操作命令

     SNMP协议之所以易于使用,这是因为它对外提供了三种用于控制MIB对象的基本操作命令。它们是:Get、Set 和 Trap

  • Get:管理站读取代理者处对象的值。它是SNMP协议中使用率最高的一个命令,因为该命令是从网络设备中获得管理信息的基本方式。
  • Set:管理站设置代理者处对象的值。它是一个特权命令,因为可以通过它来改动设备的配置或控制设备的运转状态。它可以设置设备的名称,关掉一个端口或清除一个地址解析表中的项等。
  • Trap: 代理者主动向管理站通报重要事件。它的功能就是在网络管理系统没有明确要求的前提下,由管理代理通知网络管理系统有一些特别的情况或问题 发生了。如果发生意外情况,客户会向服务器的162端口发送一个消息,告知服务器指定的变量值发生了变化。通常由服务器请求而获得的数据由服务器的161 端口接收。Trap 消息可以用来通知管理站线路的故障、连接的终端和恢复、认证失败等消息。管理站可相应的作出处理。

2.8 SNMP的消息构成

      SNMP协议定义了数据包的格式,及网络管理员和管理代理之间的信息交换,它还控制着管理代理的MIB数据对象。因此,可用于处理管理代理定义的各种任务。

      一条SNMP消息由"版本号"、"SNMP共同体名"和"协议数据单元(PDU)"构成,数据包的长度不是固定的。

  • 版本识别符(version identifier):用于说明现在使用的是哪个版本的SNMP协议,确保SNMP代理使用相同的协议,每个SNMP代理都直接抛弃与自己协议版本不同的数据报。
  • 团体名(Community Name)团体(community)是基本的安全机制,用于实现SNMP网络管理员访问SNMP管理代理时的身份验证。类似于密码,默认值为 public。团体名(Community name)是管理代理的口令,管理员被允许访问数据对象的前提就是网络管理员知道网络代理的口令。如果把配置管理代理成可以执行Trap命令,当网络管理 员用一个错误的分区名查询管理代理时,系统就发送一个autenticationFailure trap报文。
  • 协议数据单元(PDU)PDU (协议数据单元)是SNMP消息中的数据区, 即Snmp通信时报文数据的载体。PDU指明了SNMP的消息类型及其相关参数。

2.9 NET-SNMP 

     2.9.1 NET-SNMP简介   

      在 Linux 系统中,我们可以选择 net-snmp 来处理绝大多数和 SNMP 相关的工作。

      NET-SNMP 是一种开放源代码的 SNMP 协议实现。它支持 SNMP v1, SNMP v2c 与 SNMP v3,并可以使用 IPV4 及 IPV6 。也包含 SNMP Trap 的所有相关实现。
      NET-SNMP 包含了 snmp 实用程序集和完整的 snmp 开发库。

  • 路由器和交换机需要配置SNMP
snmp-server community carlos88 RO 100
  • 服务器需要安装SNMP 
 yum install net-snmp net-snmp-utils  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

snmp -v2c -c carlos88 172.18.20.220 1.3.6.1.2.1.1.3.0 # 获取系统的运行时间
snmp -v2c -c carlos88 172.18.20.220 1.3.6.1.4.1.2021.10.1.3.1 # 获取系统第一分钟的负载
 

  

    2.9.2 snmpd.conf文件

通常 SNMP 服务的配置文件位于 /etc/snmp/snmpd.conf,先来看一下这个文件:

###############################################################################
#
# snmpd.conf:
#   An example configuration file for configuring the ucd-snmp snmpd agent.
#
###############################################################################
#
# This file is intended to only be as a starting point.  Many more
# configuration directives exist than are mentioned in this file.  For
# full details, see the snmpd.conf(5) manual page.
#
# All lines beginning with a '#' are comments and are intended for you
# to read.  All other lines are configuration commands for the agent.

###############################################################################
# Access Control
###############################################################################

# As shipped, the snmpd demon will only respond to queries on the
# system mib group until this file is replaced or modified for
# security purposes.  Examples are shown below about how to increase the
# level of access.

# By far, the most common question I get about the agent is "why won't
# it work?", when really it should be "how do I configure the agent to
# allow me to access it?"
#
# By default, the agent responds to the "public" community for read
# only access, if run out of the box without any configuration file in
# place.  The following examples show you other ways of configuring
# the agent so that you can change the community names, and give
# yourself write access to the mib tree as well.
#
# For more information, read the FAQ as well as the snmpd.conf(5)
# manual page.

####
# First, map the community name "public" into a "security name"

#       sec.name  source          community
com2sec notConfigUser  default       public

####
# Second, map the security name into a group name:

#       groupName      securityModel securityName
group   notConfigGroup v1           notConfigUser
group   notConfigGroup v2c           notConfigUser

####
# Third, create a view for us to let the group have rights to:

# Make at least  snmpwalk -v 1 localhost -c public system fast again.
#       name           incl/excl     subtree         mask(optional)
view    systemview    included   .1.3.6.1.2.1.1
view    systemview    included   .1.3.6.1.2.1.25.1.1

####
# Finally, grant the group read-only access to the systemview view.

#       group          context sec.model sec.level prefix read   write  notif
access  notConfigGroup ""      any       noauth    exact  systemview none none

# -----------------------------------------------------------------------------

# Here is a commented out example configuration that allows less
# restrictive access.

# YOU SHOULD CHANGE THE "COMMUNITY" TOKEN BELOW TO A NEW KEYWORD ONLY
# KNOWN AT YOUR SITE.  YOU *MUST* CHANGE THE NETWORK TOKEN BELOW TO
# SOMETHING REFLECTING YOUR LOCAL NETWORK ADDRESS SPACE.

##       sec.name  source          community
#com2sec local     localhost       COMMUNITY
#com2sec mynetwork NETWORK/24      COMMUNITY

##     group.name sec.model  sec.name
#group MyRWGroup  any        local
#group MyROGroup  any        mynetwork
#
#group MyRWGroup  any        otherv3user
#...

##           incl/excl subtree                          mask
#view all    included  .1                               80

## -or just the mib2 tree-

#view mib2   included  .iso.org.dod.internet.mgmt.mib-2 fc


##                context sec.model sec.level prefix read   write  notif
#access MyROGroup ""      any       noauth    0      all    none   none
#access MyRWGroup ""      any       noauth    0      all    all    all


###############################################################################
# Sample configuration to make net-snmpd RFC 1213.
# Unfortunately v1 and v2c don't allow any user based authentification, so
# opening up the default config is not an option from a security point.
#
# WARNING: If you uncomment the following lines you allow write access to your
# snmpd daemon from any source! To avoid this use different names for your
# community or split out the write access to a different community and
# restrict it to your local network.
# Also remember to comment the syslocation and syscontact parameters later as
# otherwise they are still read only (see FAQ for net-snmp).
#

# First, map the community name "public" into a "security name"
#       sec.name        source          community
#com2sec notConfigUser   default         public

# Second, map the security name into a group name:
#       groupName       securityModel   securityName
#group   notConfigGroup  v1              notConfigUser
#group   notConfigGroup  v2c             notConfigUser

# Third, create a view for us to let the group have rights to:
# Open up the whole tree for ro, make the RFC 1213 required ones rw.
#       name            incl/excl       subtree mask(optional)
#view    roview          included        .1
#view    rwview          included        system.sysContact
#view    rwview          included        system.sysName
#view    rwview          included        system.sysLocation
#view    rwview          included        interfaces.ifTable.ifEntry.ifAdminStatus
#view    rwview          included        at.atTable.atEntry.atPhysAddress
#view    rwview          included        at.atTable.atEntry.atNetAddress
#view    rwview          included        ip.ipForwarding
#view    rwview          included        ip.ipDefaultTTL
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteDest
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteIfIndex
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteMetric1
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteMetric2
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteMetric3
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteMetric4
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteType
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteAge
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteMask
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteMetric5
#view    rwview          included        ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaIfIndex
#view    rwview          included        ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaPhysAddress
#view    rwview          included        ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaNetAddress
#view    rwview          included        ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType
#view    rwview          included        tcp.tcpConnTable.tcpConnEntry.tcpConnState
#view    rwview          included        egp.egpNeighTable.egpNeighEntry.egpNeighEventTrigger
#view    rwview          included        snmp.snmpEnableAuthenTraps

# Finally, grant the group read-only access to the systemview view.
#       group          context sec.model sec.level prefix read   write  notif
#access  notConfigGroup ""      any       noauth    exact  roview rwview none



###############################################################################
# System contact information
#

# It is also possible to set the sysContact and sysLocation system
# variables through the snmpd.conf file:

syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)

# Example output of snmpwalk:
#   % snmpwalk -v 1 localhost -c public system
#   system.sysDescr.0 = "SunOS name sun4c"
#   system.sysObjectID.0 = OID: enterprises.ucdavis.ucdSnmpAgent.sunos4
#   system.sysUpTime.0 = Timeticks: (595637548) 68 days, 22:32:55
#   system.sysContact.0 = "Me <me@somewhere.org>"
#   system.sysName.0 = "name"
#   system.sysLocation.0 = "Right here, right now."
#   system.sysServices.0 = 72


###############################################################################
# Logging
#

# We do not want annoying "Connection from UDP: " messages in syslog.
# If the following option is commented out, snmpd will print each incoming
# connection, which can be useful for debugging.

dontLogTCPWrappersConnects yes

# -----------------------------------------------------------------------------


###############################################################################
# Process checks.
#
#  The following are examples of how to use the agent to check for
#  processes running on the host.  The syntax looks something like:
#
#  proc NAME [MAX=0] [MIN=0]
#
#  NAME:  the name of the process to check for.  It must match
#         exactly (ie, http will not find httpd processes).
#  MAX:   the maximum number allowed to be running.  Defaults to 0.
#  MIN:   the minimum number to be running.  Defaults to 0.

#
#  Examples (commented out by default):
#

#  Make sure mountd is running
#proc mountd

#  Make sure there are no more than 4 ntalkds running, but 0 is ok too.
#proc ntalkd 4

#  Make sure at least one sendmail, but less than or equal to 10 are running.
#proc sendmail 10 1

#  A snmpwalk of the process mib tree would look something like this:
#
# % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.2
# enterprises.ucdavis.procTable.prEntry.prIndex.1 = 1
# enterprises.ucdavis.procTable.prEntry.prIndex.2 = 2
# enterprises.ucdavis.procTable.prEntry.prIndex.3 = 3
# enterprises.ucdavis.procTable.prEntry.prNames.1 = "mountd"
# enterprises.ucdavis.procTable.prEntry.prNames.2 = "ntalkd"
# enterprises.ucdavis.procTable.prEntry.prNames.3 = "sendmail"
# enterprises.ucdavis.procTable.prEntry.prMin.1 = 0
# enterprises.ucdavis.procTable.prEntry.prMin.2 = 0
# enterprises.ucdavis.procTable.prEntry.prMin.3 = 1
# enterprises.ucdavis.procTable.prEntry.prMax.1 = 0
# enterprises.ucdavis.procTable.prEntry.prMax.2 = 4
# enterprises.ucdavis.procTable.prEntry.prMax.3 = 10
# enterprises.ucdavis.procTable.prEntry.prCount.1 = 0
# enterprises.ucdavis.procTable.prEntry.prCount.2 = 0
# enterprises.ucdavis.procTable.prEntry.prCount.3 = 1
# enterprises.ucdavis.procTable.prEntry.prErrorFlag.1 = 1
# enterprises.ucdavis.procTable.prEntry.prErrorFlag.2 = 0
# enterprises.ucdavis.procTable.prEntry.prErrorFlag.3 = 0
# enterprises.ucdavis.procTable.prEntry.prErrMessage.1 = "No mountd process running."
# enterprises.ucdavis.procTable.prEntry.prErrMessage.2 = ""
# enterprises.ucdavis.procTable.prEntry.prErrMessage.3 = ""
# enterprises.ucdavis.procTable.prEntry.prErrFix.1 = 0
# enterprises.ucdavis.procTable.prEntry.prErrFix.2 = 0
# enterprises.ucdavis.procTable.prEntry.prErrFix.3 = 0
#
#  Note that the errorFlag for mountd is set to 1 because one is not
#  running (in this case an rpc.mountd is, but thats not good enough),
#  and the ErrMessage tells you what's wrong.  The configuration
#  imposed in the snmpd.conf file is also shown.
#
#  Special Case:  When the min and max numbers are both 0, it assumes
#  you want a max of infinity and a min of 1.
#


# -----------------------------------------------------------------------------


###############################################################################
# Executables/scripts
#

#
#  You can also have programs run by the agent that return a single
#  line of output and an exit code.  Here are two examples.
#
#  exec NAME PROGRAM [ARGS ...]
#
#  NAME:     A generic name. The name must be unique for each exec statement.
#  PROGRAM:  The program to run.  Include the path!
#  ARGS:     optional arguments to be passed to the program

# a simple hello world
#exec echotest /bin/echo hello world

# Run a shell script containing:
#
# #!/bin/sh
# echo hello world
# echo hi there
# exit 35
#
# Note:  this has been specifically commented out to prevent
# accidental security holes due to someone else on your system writing
# a /tmp/shtest before you do.  Uncomment to use it.
#
#exec shelltest /bin/sh /tmp/shtest

# Then,
# % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.8
# enterprises.ucdavis.extTable.extEntry.extIndex.1 = 1
# enterprises.ucdavis.extTable.extEntry.extIndex.2 = 2
# enterprises.ucdavis.extTable.extEntry.extNames.1 = "echotest"
# enterprises.ucdavis.extTable.extEntry.extNames.2 = "shelltest"
# enterprises.ucdavis.extTable.extEntry.extCommand.1 = "/bin/echo hello world"
# enterprises.ucdavis.extTable.extEntry.extCommand.2 = "/bin/sh /tmp/shtest"
# enterprises.ucdavis.extTable.extEntry.extResult.1 = 0
# enterprises.ucdavis.extTable.extEntry.extResult.2 = 35
# enterprises.ucdavis.extTable.extEntry.extOutput.1 = "hello world."
# enterprises.ucdavis.extTable.extEntry.extOutput.2 = "hello world."
# enterprises.ucdavis.extTable.extEntry.extErrFix.1 = 0
# enterprises.ucdavis.extTable.extEntry.extErrFix.2 = 0

# Note that the second line of the /tmp/shtest shell script is cut
# off.  Also note that the exit status of 35 was returned.

# -----------------------------------------------------------------------------


###############################################################################
# disk checks
#

# The agent can check the amount of available disk space, and make
# sure it is above a set limit.

# disk PATH [MIN=100000]
#
# PATH:  mount path to the disk in question.
# MIN:   Disks with space below this value will have the Mib's errorFlag set.
#        Default value = 100000.

# Check the / partition and make sure it contains at least 10 megs.

#disk / 10000

# % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.9
# enterprises.ucdavis.diskTable.dskEntry.diskIndex.1 = 0
# enterprises.ucdavis.diskTable.dskEntry.diskPath.1 = "/" Hex: 2F
# enterprises.ucdavis.diskTable.dskEntry.diskDevice.1 = "/dev/dsk/c201d6s0"
# enterprises.ucdavis.diskTable.dskEntry.diskMinimum.1 = 10000
# enterprises.ucdavis.diskTable.dskEntry.diskTotal.1 = 837130
# enterprises.ucdavis.diskTable.dskEntry.diskAvail.1 = 316325
# enterprises.ucdavis.diskTable.dskEntry.diskUsed.1 = 437092
# enterprises.ucdavis.diskTable.dskEntry.diskPercent.1 = 58
# enterprises.ucdavis.diskTable.dskEntry.diskErrorFlag.1 = 0
# enterprises.ucdavis.diskTable.dskEntry.diskErrorMsg.1 = ""

# -----------------------------------------------------------------------------


###############################################################################
# load average checks
#

# load [1MAX=12.0] [5MAX=12.0] [15MAX=12.0]
#
# 1MAX:   If the 1 minute load average is above this limit at query
#         time, the errorFlag will be set.
# 5MAX:   Similar, but for 5 min average.
# 15MAX:  Similar, but for 15 min average.

# Check for loads:
#load 12 14 14

# % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.10
# enterprises.ucdavis.loadTable.laEntry.loadaveIndex.1 = 1
# enterprises.ucdavis.loadTable.laEntry.loadaveIndex.2 = 2
# enterprises.ucdavis.loadTable.laEntry.loadaveIndex.3 = 3
# enterprises.ucdavis.loadTable.laEntry.loadaveNames.1 = "Load-1"
# enterprises.ucdavis.loadTable.laEntry.loadaveNames.2 = "Load-5"
# enterprises.ucdavis.loadTable.laEntry.loadaveNames.3 = "Load-15"
# enterprises.ucdavis.loadTable.laEntry.loadaveLoad.1 = "0.49" Hex: 30 2E 34 39
# enterprises.ucdavis.loadTable.laEntry.loadaveLoad.2 = "0.31" Hex: 30 2E 33 31
# enterprises.ucdavis.loadTable.laEntry.loadaveLoad.3 = "0.26" Hex: 30 2E 32 36
# enterprises.ucdavis.loadTable.laEntry.loadaveConfig.1 = "12.00"
# enterprises.ucdavis.loadTable.laEntry.loadaveConfig.2 = "14.00"
# enterprises.ucdavis.loadTable.laEntry.loadaveConfig.3 = "14.00"
# enterprises.ucdavis.loadTable.laEntry.loadaveErrorFlag.1 = 0
# enterprises.ucdavis.loadTable.laEntry.loadaveErrorFlag.2 = 0
# enterprises.ucdavis.loadTable.laEntry.loadaveErrorFlag.3 = 0
# enterprises.ucdavis.loadTable.laEntry.loadaveErrMessage.1 = ""
# enterprises.ucdavis.loadTable.laEntry.loadaveErrMessage.2 = ""
# enterprises.ucdavis.loadTable.laEntry.loadaveErrMessage.3 = ""

# -----------------------------------------------------------------------------


###############################################################################
# Extensible sections.
#

# This alleviates the multiple line output problem found in the
# previous executable mib by placing each mib in its own mib table:

# Run a shell script containing:
#
# #!/bin/sh
# echo hello world
# echo hi there
# exit 35
#
# Note:  this has been specifically commented out to prevent
# accidental security holes due to someone else on your system writing
# a /tmp/shtest before you do.  Uncomment to use it.
#
# exec .1.3.6.1.4.1.2021.50 shelltest /bin/sh /tmp/shtest

# % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.50
# enterprises.ucdavis.50.1.1 = 1
# enterprises.ucdavis.50.2.1 = "shelltest"
# enterprises.ucdavis.50.3.1 = "/bin/sh /tmp/shtest"
# enterprises.ucdavis.50.100.1 = 35
# enterprises.ucdavis.50.101.1 = "hello world."
# enterprises.ucdavis.50.101.2 = "hi there."
# enterprises.ucdavis.50.102.1 = 0

# Now the Output has grown to two lines, and we can see the 'hi
# there.' output as the second line from our shell script.
#
# Note that you must alter the mib.txt file to be correct if you want
# the .50.* outputs above to change to reasonable text descriptions.

# Other ideas:
#
# exec .1.3.6.1.4.1.2021.51 ps /bin/ps
# exec .1.3.6.1.4.1.2021.52 top /usr/local/bin/top
# exec .1.3.6.1.4.1.2021.53 mailq /usr/bin/mailq

# -----------------------------------------------------------------------------


###############################################################################
# Pass through control.
#

# Usage:
#   pass MIBOID EXEC-COMMAND
#
# This will pass total control of the mib underneath the MIBOID
# portion of the mib to the EXEC-COMMAND.
#
# Note:  You'll have to change the path of the passtest script to your
# source directory or install it in the given location.
#
# Example:  (see the script for details)
#           (commented out here since it requires that you place the
#           script in the right location. (its not installed by default))

# pass .1.3.6.1.4.1.2021.255 /bin/sh /usr/local/local/passtest

# % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.255
# enterprises.ucdavis.255.1 = "life the universe and everything"
# enterprises.ucdavis.255.2.1 = 42
# enterprises.ucdavis.255.2.2 = OID: 42.42.42
# enterprises.ucdavis.255.3 = Timeticks: (363136200) 42 days, 0:42:42
# enterprises.ucdavis.255.4 = IpAddress: 127.0.0.1
# enterprises.ucdavis.255.5 = 42
# enterprises.ucdavis.255.6 = Gauge: 42
#
# % snmpget -v 1 localhost public .1.3.6.1.4.1.2021.255.5
# enterprises.ucdavis.255.5 = 42
#
# % snmpset -v 1 localhost public .1.3.6.1.4.1.2021.255.1 s "New string"
# enterprises.ucdavis.255.1 = "New string"
#

# For specific usage information, see the man/snmpd.conf.5 manual page
# as well as the local/passtest script used in the above example.

###############################################################################
# Further Information
#
#  See the snmpd.conf manual page, and the output of "snmpd -H".

 配置 SNMP 简单步骤如下:  

  •  1 )首选是定义一个共同体名 (community) ,这里是 public ,及可以访问这个 public 的用户名( sec name ),这里是 notConfigUser 。 Public 相当于用户 notConfigUser 的密码   
    #                   sec.name             source             community
     com2sec      notConfigUser      default            public 
     com2sec      carlos                   default            carlos88(将carlos用户的共同体设置为carlos88)
  • 2 )定义一个组名( groupName )这里是 notConfigGroup ,及组的安全级别,把 notConfigGroup 这个用户加到这个组中。   

           #                 groupName        securityModel      securityName 
             group        notConfigGroup          v1               notConfigUser   
             group        notConfigGroup          v2c             notConfigUser 
             group           admin                       v2c             carlos(将carlos用户添加到admin用户组)

  •  3 )定义一个可操作的范围 (view) 名:
    定义一个view视图,设置视图的可看范围:
             项目名分类 |视图名称|  包含/排除   | 范围

                #                  name                incl/excl         subtree         mask(optional)       
              view           systemview          included         .1.3.6.1.2.1.1         
              view                  all                  included        .1   80 (这里是 all ,范围是  .1 
  •  4 )定义 notConfigUser 这个组在 all 这个 view 范围内可做的操作,这时定义了 notConfigUser 组的成员可对.1 这个范围做只读操作。    

          定义组可以看到的视图权限:
                # 项目分类名 | 组名|描述|sec.model  |  sec.level  |  prefix    |  可读读视图  |  可写的视图  |  notif

                    access     mygroup        ""      any     noauth       exact     all      none      none

 

备注:

cacti 就是通过snmp获取相关数据信息,采用RRDTool绘图显示。

...........

posted on 2019-01-03 10:27  CARLOS_KONG  阅读(833)  评论(0编辑  收藏  举报

导航