分类: Python/Ruby
2013-09-23 14:04:55
Ubuntu安装snmp
root@ubuntu:/etc/snmp# sudo apt-get install snmp snmpd
root@ubuntu:/etc/snmp# vim snmpd.conf
root@ubuntu:/etc/snmp# /etc/init.d/snmpd restart
root@ubuntu:/etc/snmp# snmpwalk -v 2c -c public localhost system
system: Unknown Object Identifier (Sub-id not found: (top) -> system)
root@ubuntu:/etc/snmp#
查看swap
root@ubuntu:/etc/snmp# snmpwalk -v 2c -c public localhost 1.3.6.1.4.1.2021.4.3.0
iso.3.6.1.4.1.2021.4.3.0 = INTEGER: 1107964
root@ubuntu:/etc/snmp#
----------------------------------------------------------------------------
centos安装snmp
[root@mail ~]# yum install -y net-snmp net-snmp-utils
其他可能需要的包有:
yum install -y net-snmp
yum install -y
net-snmp-devel
yum install -y
net-snmp-libs
yum install -y
net-snmp-perl
yum install -y
net-snmp-utils
yum install -y mrtg
可以将public修改为自己才知道的字符串,为了简便这里不修改
去掉view这行前面的#
将红方框上面的行,转换成红框内容
启用全部功能
[root@mail snmp]# /etc/init.d/snmpd restart
测试:
[root@mail snmp]# snmpwalk -v 2c -c public localhost 1.3.6.1.4.1.2021.4.3.0
UCD-SNMP-MIB::memTotalSwap.0 = INTEGER: 1015800 kB
[root@mail snmp]#
[root@mail 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
[root@mail snmp]#
-----------------------------------------------------------------------------
输入OID查看系统信息的方法比较麻烦,所以可以使用mlib
Ubuntu安装mlib
http://tech.moosaico.com/blog/2012/12/01/
安装mibs
root@ubuntu:/etc/snmp# sudo apt-get install snmp-mibs-downloader
root@ubuntu:/etc/snmp# sudo download-mibs
配置:
root@ubuntu:/etc/snmp# vim snmp.conf
将mibs注释掉,如下图
root@ubuntu:/etc/snmp# /etc/init.d/snmpd restart
检查是否安装成功:
l root@ubuntu:/etc/snmp# ls /usr/share/mibs/
iana ietf netsnmp
root@ubuntu:/etc/snmp#
root@ubuntu:/etc/snmp# snmpwalk -v 2c -c public localhost ifInOctets
IF-MIB::ifInOctets.1 = Counter32: 622063
IF-MIB::ifInOctets.2 = Counter32: 13430504
root@ubuntu:/etc/snmp# snmpwalk -v 2c -c public localhost ifInOctets|awk -F '::' '{print $2}'
ifInOctets.1 = Counter32: 622509
ifInOctets.2 = Counter32: 13463521
---------------------------------------------------------------------------