之前在网上参考一份文档很轻松的就配置好了redhat linux下的snmp服务。http://my.oschina.net/u/1167544/blog/206787
可是后来接触到了ubuntu,配置却出现了问题……好不容易才配置好,看来还得好好补充一下这方面的知识。
ubuntu下安装SNMP比较方便,不用手动下载什么安装包:
>>sudo apt-get install snmp
>>sudo apt-get install snmpd
>>sudo apt-get install snmp-mibs-downloader
之后编辑/etc/snmp/snmp.conf文件,命令
>>sudo gedit /etc/snmp/snmp.conf
可以看到
#
# As the snmp packages come without MIB files due to license reasons, loading
# of MIBs is disabled by default. If you added the MIBs you can reenable
# loaging them by commenting out the following line.
mibs :
由于证书原因snmp包安装时没有MIB文件,默认不加载MIBs。如果添加了MIBs你可以通过注释掉下面一行(mibs:)重新加载它们. 也就是将mibs注释掉即可,修改后的:
#
# As the snmp packages come without MIB files due to license reasons, loading
# of MIBs is disabled by default. If you added the MIBs you can reenable
# loaging them by commenting out the following line.
# mibs :
编辑/etc/snmp/snmpd.conf文件,该文件内容比较多,就不一一列出,可以参考linux环境配置snmp服务的方法。之后找到:
# Listen for connections from the local system only
agentAddress udp:127.0.0.1:161
将agentAddress udp:127.0.0.1:161注释掉(前面加一个#即可),否则安装好之后,无法远程访问此主机的snmp服务。该配置的功能是:只监听接收来自本机的连接
编辑/etc/default/snmpd文件:
1.找到export MIBS=
指定MIBS路径,我的机器上
export MIBS=/usr/share/mibs
不知道路径的可以通过命令
>>find / -name mibs
来查找,/表示在根目录上查找
2.找到
SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid'
如果最后边有127.0.0.1就将其删除(在网上找资料时看到的,我的安装好之后就这样),否则也就不能远程访问本机的snmp服务。
最后重启snmpd服务:
>>service snmpd restart或>>/etc/init.d/snmpd restart
测试在本机中获取snmp相关信息:
>>snmpwalk -v 2c -c public localhost
就可以查看到相应的信息,
之后通过MIB Broswer来测试远程获取该主机的snmp服务