美文网首页
linux 配置NET-SNMP 服务

linux 配置NET-SNMP 服务

作者: Joncc | 来源:发表于2020-04-29 15:03 被阅读0次
    CentOS Linux release 7.3.1611
    NET-SNMP version: 5.7.2
    

    YUM 安装

    yum install -y net-snmp net-snmp-utils
    

    使用snmptranslate命令,检查snmp工具是否可以使用
    [root@test~]# snmptranslate -To | head
    .1.3
    .1.3.6
    .1.3.6.1
    .1.3.6.1.1
    .1.3.6.1.2
    .1.3.6.1.2.1
    .1.3.6.1.2.1.1
    .1.3.6.1.2.1.1.1
    .1.3.6.1.2.1.1.2
    .1.3.6.1.2.1.1.3

    使用snmpwalk命令,查看本机localhost的主机名: 主机名

    [root@test~]# snmpwalk -v 2c -c public localhost sysName.0
    SNMPv2-MIB::sysName.0 = STRING: test


    二、配置snmp服务

    以上安装完成后,使用的是snmp的默认配置,通过这些默认配置,我们只能获取主机的部分信息。但一些其他的重要信息,无法获取。如主机的CPU使用情况,内存使用情况等。

    [root@test~]# snmpwalk -v 2c -c public localhost 1.3.6.1.4.1.2021.11.11.0  
    snmpwalk -v 2c -c public localhost 1.3.6.1.4.1.2021.11.ssCpuIdle
    
    UCD-SNMP-MIB::ssCpuIdle.0 = No more variables left in this MIB View (It is past the end of the MIB tree)
    

    如上,无法获取CPU的空闲率(注:1.3.6.1.4.1.2021.11.11.0是主机CPU空闲率的oid)。

    这时候,若要获取主机的一些重要信息,则要修改snmp的默认配置。

    配置方法:修改/etc/snmp/snmpd.conf文件

    1、修改查看设备节点的权限
    在该文件中,找到如下位置:

    # 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
    

    view:定义了可以查看哪些节点设备的信息。

    snmp默认配置只能查看.1.3.6.1.2.1.1和.1.3.6.1.2.1.25.1.1节点下的设备信息,而主机CPU和内存等设备都不在这些节点下,所以无法获取这些数据。

    因此,可以修改这个配置,如下:

    # 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
    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

    表示可以查看.1节点下的所有设备信息。

    2、修改Process checks的配置
    找到如下位置:
    ###############################################################################
    # 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
    

    proc mountd

    proc ntalkd 4

    proc sendmail 10 1

    三行前的“#”号去掉,取消注释

    3、修改Executables/scripts配置
    找到如下位置:

    ###############################################################################
    # 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
    

    exec echotest /bin/echo hello world

    的“#”号去掉,取消注释。

    4、修改disk checks配置
    找到如下位置:

    ###############################################################################
    # 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 = ""
    

    disk / 10000

    一行前的“#”号去掉,取消注释。

    5、修改load average checks配置
    找到如下位置:

    ###############################################################################
    # 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
    

    将 #load 12 14 14

    一行前的“#”号去掉,取消注释。

    6、保存修改,重启snmp服务

    7、验证修改配置后的snmp服务

    如上,通过本机localhost获取到CPU的空闲率为99%。

    snmpwalk -v 2c -c public localhost 1.3.6.1.4.1.2021.11.11.0
    UCD-SNMP-MIB::ssCpuIdle.0 = INTEGER: 99

    相关文章

      网友评论

          本文标题:linux 配置NET-SNMP 服务

          本文链接:https://www.haomeiwen.com/subject/giagwhtx.html