snmpd
SNMP监控一些常用OID的总结
CentOS开启snmpd
-
snmpd
# 安装 yum install -y net-snmp # 配置: /etc/snmp/snmpd.conf # v2c验证方式 # rocommunity mytestsnmpd # rocommunity : 只读访问权限 # mytestsnmpd : v2c的帐号 # 后面的IP表示授权访问的IP # v3验证方式 # 注意: # 1.密码要8个字节以上,否则会失败。 # 2.由于安全的原因,snmpd启动后,以上两行会被删除,其内容以密文的形式记录在其它文件中。 # rouser myuser auth # 设定只读帐号类型,auth指明连接时需要验证 # createUser myuser MD5 mypassword # 创建一个名为mytest的用户,密码为mypassword,并用MD5进行加密传输 cat >> /etc/snmp/snmpd.conf <<EOF rocommunity mysnmpd rouser myuser auth createUser myuser MD5 mypassword EOF # 取消默认community:public、删除rocomnunity sed -i -e 's/^com2sec /#&/g' -e 's/^rocommunity/#&/g' -e '/^# My CONFIG START/,/^# My CONFIG END/d' /etc/snmp/snmpd.conf #增加mytestsnmpd授权(com2sec中的source默认是default 可以根据需要访问的主机IP做限制) cat >> /etc/snmp/snmpd.conf <<EOF # My CONFIG START com2sec myuser default mysnmpd group myGroup v1 myuser group myGroup v2c myuser view myview included .1.3.6.1.2.1 view myview included .1.3.6.1.4.1 access myGroup "" any noauth exact myview none none # My CONFIG END EOF # 启动 service snmpd restart chkconfig snmpd on
-
安装snmpwalk
# CentOS yum install net-snmp-utils # Ubuntu apt-get install snmp
OIDs
- 磁盘卷列表
从iso.3.6.1.4.1.2021.9.1.2.1开始,最后一位+1递增,直到返回:No Such Instance currently exists at this OID
snmpwalk -v2c -c public localhost iso.3.6.1.4.1.2021.9.1.2.1 iso.3.6.1.4.1.2021.9.1.2.1 = STRING: "/" snmpwalk -v2c -c public localhost iso.3.6.1.4.1.2021.9.1.2.25 iso.3.6.1.4.1.2021.9.1.2.25 = No Such Instance currently exists at this OID
- Ubnutu启用mibs
修改/etc/snmp/snmp.conf,注释mibs:这一行。
-
Debian missing MIBs for SNMP
For error such as: Cannot find module (HOST-RESOURCES-MIB): At line 0 in (none) Cannot find module (HOST-RESOURCES-TYPES): At line 0 in (none) Cannot find module (SNMPv2-TC): At line 10 in /usr/share/mibs/netsnmp/UCD-DLMOD-MIB Cannot find module (SNMPv2-SMI): At line 34 in /usr/share/mibs/netsnmp/UCD-SNMP-MIB Cannot find module (SNMPv2-TC): At line 37 in /usr/share/mibs/netsnmp/UCD-SNMP-MIB Did not find ‘enterprises’ in module #-1 (/usr/share/mibs/netsnmp/UCD-SNMP-MIB) Did not find ‘DisplayString’ in module #-1 (/usr/share/mibs/netsnmp/UCD-SNMP-MIB) Did not find ‘TruthValue’ in module #-1 (/usr/share/mibs/netsnmp/UCD-SNMP-MIB) Unlinked OID in UCD-SNMP-MIB: ucdavis ::= { enterprises 2021 } Undefined identifier: enterprises near line 39 of /usr/share/mibs/netsnmp/UCD-SNMP-MIB Did not find ‘DisplayString’ in module #-1 (/usr/share/mibs/netsnmp/UCD-DLMOD-MIB) Did not find ‘ucdExperimental’ in module UCD-SNMP-MIB (/usr/share/mibs/netsnmp/UCD-DLMOD-MIB) Unlinked OID in UCD-DLMOD-MIB: ucdDlmodMIB ::= { ucdExperimental 14 }
apt-get install snmp-mibs-downloader Please note that the second, snmp-mibs-downloader is not free so in order to install it you need to modify your /etc/apt/sources.list to include non-free packages. Then run download-mibs snmpwalk -Os -c public -v 1 localhost system # 以下为查询同一内容:dskPath snmpwalk -v2c -c public localhost iso.3.6.1.4.1.2021.9.1.2 snmpwalk -v2c -c public localhost 1.3.6.1.4.1.2021.9.1.2 snmpwalk -v2c -c public localhost UCD-SNMP-MIB::dskPath
-
OID-MIB查询
# snmptranslate 这个命令可以用来查看映射关系 snmptranslate .1.3.6.1.2.1.1.3.0 SNMPv2-MIB::sysUpTime.0 snmptranslate -On SNMPv2-MIB::system.sysUpTime.0 .1.3.6.1.2.1.1.3.0