安装 snmp 服务

今天,在centos6.3-x86上需要搭建一个snmp服务,于是进行了如下的搜索和操作:

1.首先检查所需要的依赖包:

rpm -qa| grep snmp 如果显示net-snmp-utils-5.3.2.2-5.el5,net-snmp-libs-5.3.2.2-5.el5,net-snmp-5.3.2.2-5.el5三个包,则系统已经安装成功。

rpm -qa| grep lm    lm_sensors-2.10.6-55.el5

rpm -qa| grep libsen  libsensors3.2.10.6-55.el5  这个包网上说需要装的,但是后来我查看了下系统没有装,也没有安装上就跳过了,snmp服务正常启动了。

2.启动snmp服务

service snmpd start 

3.验证snmp服务

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

[root@localhost snmp]# snmpwalk -v 2c -c public localhost sysName.0
SNMPv2-MIB::sysName.0 = STRING: localhost.localdomain
如上,获取到本机主机名为localhost.localdomain,则表示snmp服务已经可以正常使用。

(2)使用snmptranslate命令,检查snmp工具是否可以使用:
 [root@localhost snmp]# 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
如上,查出了部分oid,则表示snmp工具可以正常使用。

4、配置snmp

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

[root@localhost snmp]# snmpwalk -v 2c -c public localhost 1.3.6.1.4.1.2021.11.11.0
UCD-SNMP-MIB::ssCpuIdle.0 = INTEGER: 93 

当没有调试配置文件时,是显示不了上诉信息的。 无法获取CPU的空闲率(注:1.3.6.1.4.1.2021.11.11.0是主机CPU空闲率的oid)。
这时候,若要获取主机的一些重要信息,则要修改snmp的默认配置。

(1).vi /et/snmp/snmpd.config 、修改查看设备节点的权限

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

view:定义了可以查看哪些节点设备的信息。
snmp默认配置只能查看.1.3.6.1.2.1.1和.1.3.6.1.2.1.25.1.1节点下的设备信息,而主机CPU和内存等设备都不在这些节点下,所以无法获取这些数据。
因此,可以修改这个配置,如下:

# 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   在此处添加了一行:
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

#  A snmpwalk of the process mib tree would look something like this:

将红色的三条语句#号去掉

(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

将红色的代码#去掉

(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

将红色的代码#号去掉

(5)、修改load average checks配置

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

将红色代码#去掉;

5,配置完成后重新启动snmp服务

service snmpd restart

查看cpu使用率:

[root@localhost snmp]# snmpwalk -v 2c -c public localhost 1.3.6.1.4.1.2021.11.11.0
UCD-SNMP-MIB::ssCpuIdle.0 = INTEGER: 93

查看远端服务器的cup使用率

[root@localhost snmp]# snmpwalk -v 2c -c public IP  1.3.6.1.4.1.2021.11.11.0
UCD-SNMP-MIB::ssCpuIdle.0 = INTEGER: 93 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值