snmp ubuntu/centos--

 


软件安装

切换到系统管理员帐户

安装snmp
确认snmp代理已安装
rpm -q net-snmp
如果未安装,安装snmp
yum install net-snmp

设置开机自动运行snmp
/sbin/chkconfig snmpd on配置snmp


 

vi /etc/snmp/snmpd 
第一步,snmp团体名默认为public,可更改为其他,如下:
# First, map the community name "public" into a "security name"
# sec.name source community
com2sec notConfigUser default public

 

第二步,将如下位置的systemview改为all,如下:
####
# Finally, grant the group read-only access to the systemview view.
# group context sec.model sec.level prefix read write notif
#access notConfigGroup "" any noauth exact systemview none none
access notConfigGroup "" any noauth exact all none none

 

第三步,将如两行下行前面的注释去掉,如下:
## incl/excl subtree mask
view all included .1 80
## -or just the mib2 tree-
view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc

 

第四步,将下面这行前的注释去掉,如下:
#access notConfigGroup "" any noauth exact roview rwview none
access notConfigGroup "" any noauth exact mib2 none none

 

第五步,启动snmpd,并设置开机自动启:
service snmpd restart
chkconfig --level 345 snmpd on

修改配置文件


 

启动snmp

/etc/init.d/snmpd start
如果已启动则重启snmp服务
/etc/init.d/snmpd restart

测试snmp

查看端口是否打开
netstat -ln | grep 161

安装snmp测试工具
yum install net-snmp-utils

本机测试snmp数据(修改monit为配置的团体名)
snmpwalk -v 2c -c public localhost system

snmpwalk -v3 -u username -l auth -a MD5 -A password localhost

创建SNMP(v3)用户

net-snmp-config --create-snmpv3-user -ro -a MD5 lyceemsnmp lyceem.com

远程测试snmp数据(修改ip为服务器ip,snmpwalk命令需要安装net-snmp)
snmpwalk -v 2c -c public ip system

故常处理

错误排除如果本地测试snmp有数据,远程测试snmp无数据则由于服务器防火墙禁止了外部访问服务器udp 161端口,则:
修改 /etc/sysconfig/iptables (或者:/etc/sysconfig/iptables-config ) ,增加如下规则:
-A RH-Firewall-1-INPUT -p udp -m state Cstate NEW -m udp Cdport 161 -j ACCEPT
重启iptables
/etc/init.d/iptables restart

-- 
刘林强
 

Ubuntu11.04下的SNMP配置:

root@Ubuntu:~#sudo apt-get install snmp snmpd /*安装snmp服务*/

root@Ubuntu:~#vi /etc/snmp/snmpd.conf /*编辑snmp配置文件*/

在这里使用默认团体名public,实际环境中建议更改。

 

1.将原有“agentAddress udp:127.0.0.1:161”改为:

agentAddress 192.168.1.9 /*192.168.1.9为本机IP,即监控服务器要监控的主机IP*/

 

2.加入一行如下:

access MyROSystem "" any noauth exact all none none

 

3.将原有“rocommunity public default -V systemonly” 的"-V systemonly" 参数去掉,变成:

rocommunity public default

 

4.将“#trap2sink localhost public”和“#informsink localhost public”前面的“#”去掉,改为:

trap2sink localhost public

informsink localhost public

 

5.重启SNMP服务:

/etc/init.d/snmpd restart

 

6.检验snmp获取数据:

snmpwalk -v 2c -c public 192.168.1.9

****************************************************************************

CentOS6.3下的SNMP配置:

安装SNMP服务:

yum install net-snmp net-snmp-devel net-snmp-libs net-snmp-utils php-snmp
编辑snmpd文件:

vi /etc/snmp/snmpd 
第一步,snmp团体名默认为public,可更改为其他,如下:
# First, map the community name "public" into a "security name"
# sec.name source community
com2sec notConfigUser default public

 

第二步,将如下位置的systemview改为all,如下:
####
# Finally, grant the group read-only access to the systemview view.
# group context sec.model sec.level prefix read write notif
#access notConfigGroup "" any noauth exact systemview none none
access notConfigGroup "" any noauth exact all none none

 

第三步,将如两行下行前面的注释去掉,如下:
## incl/excl subtree mask
view all included .1 80
## -or just the mib2 tree-
view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc

 

第四步,将下面这行前的注释去掉,如下:
#access notConfigGroup "" any noauth exact roview rwview none
access notConfigGroup "" any noauth exact mib2 none none

 

第五步,启动snmpd,并设置开机自动启:
service snmpd restart
chkconfig --level 345 snmpd on

posted on 2016-09-18 08:31  szllq2000  阅读(180)  评论(0编辑  收藏  举报