检查系统是否安装snmp服务
# rpm -qa|grep snmp
net-snmp-5.3.2.2-17.el5
net-snmp-perl-5.3.2.2-17.el5
net-snmp-devel-5.3.2.2-17.el5
net-snmp-libs-5.3.2.2-17.el5
net-snmp-utils-5.3.2.2-17.el5
net-snmp-libs-5.3.2.2-17.el5
net-snmp-devel-5.3.2.2-17.el5
SNMP服务安装后会有以上安装包
安装SNMP服务
1.配置好本地yum服务,使用yum安装
yum install -y net-snmp*
2.配置SNMP服务开机启动
#chkconfig snmpd on
#chkconfig --list | grep snmpd 查看开机启动设置是否成功
snmpd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
验证SNMP服务
1.使用snmpwalk获取主机名
# snmpwalk -v 2c -c public localhost sysName.0
SNMPv2-MIB::sysName.0 = STRING: wh69
snmpwalk用法
snmpwalk -v 1|2c|3(代表SNMP版本) -c <community string> IP地址 OID(对象标示符)
2.使用snmptranslate命令,检查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工具可以正常使用
配置SNMP服务
1.配置SNMP连接字符串 community string
#vi /etc/snmp/snmpd.conf
修改下面字段
# sec.name source community
com2sec notConfigUser default public
修改public为自己定义的community string
2.修改查看设备节点权限
在配置文件/etc/snmp/snmpd.conf中找到如下位置
####
# 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
view:定义了可以查看哪些节点设备的信息。
snmp默认配置只能查看.1.3.6.1.2.1.1和.1.3.6.1.2.1.25.1.1节点下的设备信息,
而主机CPU和内存等设备都不在这些节点下,所以无法获取这些数据。
因此,可以修改这个配置,如下:
####
# 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
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
在此处添加了一行:
view systemview included .1
表示可以查看.1节点下的所有设备信息。
你说的对:https://www.linuxidc.com/Linux/2016-05/131749.htm
-bash: snmpwalk: command not found
默认情况下SNMP没有安装该命令所依赖的包,因而会报错,之后执行“ yum -y install net-snmp-utils”命令,利用yum源安装万事大吉。
lsof -Pni | grep snmpd
小技巧:可以使用snmpd -f -Le -Dread_config 命令来查看日志文件信息,排错。
Comments (0)